import { Component } from '@angular/core' ; import { Client } from '../../../../services/api' ; import { ActivatedRoute , ParamMap } from '@angular/router' ; import { EntitiesService , EntityObservable , } from '../../../../common/services/entities.service' ; import { last , first , catchError } from 'rxjs/operators' ; import { Observable , of , BehaviorSubject , Subscription } from 'rxjs' ; import { FastFadeAnimation } from '../../../../animations' ; import { DiscoveryService } from '../../discovery.service' ; import { PaywallService } from '../../../wire/v2/paywall.service' ; import { MetaService } from '../../../../common/services/meta.service' ; import { Session } from '../../../../services/session' ; import { GuestModeExperimentService } from '../../../experiments/sub-services/guest-mode-experiment.service' ; @ Component ( { selector : 'm-discovery__trend' , templateUrl : './trend.component.html' , animations : [ FastFadeAnimation ] , providers : [ PaywallService ] , } ) export class DiscoveryTrendComponent { entity$ : Observable < Object > = of ( null ) ; paramSubscription : Subscription ; entitySubscription : Subscription ; constructor ( private entitiesService , private route , private discoveryService , private paywallService , private metaService , private session , private guestModeExperiment ) { } ngOnInit ( ) { this . paramSubscription = this . route . paramMap . subscribe ( ( params ) => { this . loadEntity ( params . get ( 'guid' ) ) ; } ) ; this . entitySubscription = this . entity$ . subscribe ( ( entity ) => { if ( entity ) this . metaService . setCanonicalUrl ( `/newsfeed/${ entity . guid }` ) ; } ) ; } ngOnDestroy ( ) { this . paramSubscription . unsubscribe ( ) ; this . entitySubscription . unsubscribe ( ) ; } loadEntity ( guid ) { if ( this . discoveryService . isPlusPage$ . getValue ( ) === true ) { this . entity$ = this . paywallService . unlock ( guid ) . pipe ( catchError ( err => { return this . loadEntityFromEntitiesService ( guid ) ; } ) ) ; } else { this . entity$ = this . loadEntityFromEntitiesService ( guid ) ; } } loadEntityFromEntitiesService ( guid ) { return this . entitiesService . single ( `urn:entity:${ guid }` ) ; } returns { boolean } public shouldBeDiscoveryHomepage ( ) { return ( this . guestModeExperiment . isActive ( ) && ! this . session . getLoggedInUser ( ) ) ; } }