import { Component , Input } from '@angular/core' ; import { interval , Subscription } from 'rxjs' ; import { Session } from '../../../services/session' ; import { UpdateMarkersService } from '../../../common/services/update-markers.service' ; import { map , startWith , throttle } from 'rxjs/operators' ; import { ConfigsService } from '../../../common/services/configs.service' ; @ Component ( { selector : 'm-groups--tile' , templateUrl : 'tile.component.html' , styleUrls : [ 'tile.component.ng.scss' ] , } ) export class GroupsTileComponent { cdnUrl : string ; @ Input ( ) entity ; $updateMarker ; hasMarker : boolean = false ; constructor ( public session , private updateMarkers , configs ) { this . cdnUrl = configs . get ( 'cdn_url' ) ; } ngOnInit ( ) { this . $updateMarker = this . updateMarkers . markers . subscribe ( markers => { if ( ! markers ) return ; this . entity . hasGathering$ = interval ( 1000 ) . pipe ( throttle ( ( ) => interval ( 2000 ) ) , startWith ( 0 ) , map ( ( ) => markers . filter ( marker => marker . entity_guid == this . entity . guid && marker . marker == 'gathering-heartbeat' && marker . updated_timestamp > Date . now ( ) / 1000 - 60 ) . length > 0 ) ) ; this . hasMarker = markers . filter ( marker => marker . read_timestamp < marker . updated_timestamp && marker . entity_guid == this . entity . guid ) . length ; } ) ; } ngOnDestroy ( ) { this . $updateMarker . unsubscribe ( ) ; } }