import { EventEmitter , Inject , Injectable , PLATFORM_ID } from '@angular/core' ; import { Client } from '../../../services/api/client' ; import { Session } from '../../../services/session' ; import { NSFWSelectorConsumerService } from '../../../common/components/nsfw-selector/nsfw-selector.service' ; import { MindsVideoPlayerComponent } from '../../media/components/video-player/player.component' ; import { AnalyticsService } from '../../../services/analytics' ; import * as snowplow from '@snowplow/browser-tracker' ; import { isPlatformBrowser } from '@angular/common' ; @ Injectable ( ) export class NewsfeedService { allHashtags : boolean = false ; onReloadFeed : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ; constructor ( private client , private session , private nsfwSelectorService , private analyticsService , @ Inject ( PLATFORM_ID ) private platformId ) { } get nsfw ( ) : Array < number > { return this . nsfwSelectorService . build ( ) . reasons . filter ( reason => reason . selected ) . map ( reason => reason . value ) ; } public async recordView ( entity , visible = true , channel = null , clientMeta = { } ) { if ( isPlatformBrowser ( this . platformId ) ) { snowplow . trackSelfDescribingEvent ( { event : { schema : 'iglu:com.minds/view/jsonschema/1-0-0' , data : { entity_guid : entity . guid , entity_owner_guid : entity . owner_guid , ... clientMeta , } , } , context : this . analyticsService . getContexts ( ) , } ) ; } if ( entity . boosted_guid ) { let url = `api/v2/analytics/views/boost/${ entity . boosted_guid }` ; if ( channel ) url += `/${ channel . guid }` ; if ( ! visible ) url += `/stop` ; return await this . client . post ( url , { client_meta : clientMeta , } ) ; } return await this . client . post ( `api/v2/analytics/views/activity/${ entity . guid }` , { client_meta : clientMeta , } ) ; } public reloadFeed ( allHashtags = false ) { this . allHashtags = allHashtags ; this . onReloadFeed . emit ( allHashtags ) ; } setNSFW ( reasons ) { this . onReloadFeed . emit ( this . allHashtags ) ; } }