import { ChangeDetectionStrategy , ChangeDetectorRef , Component , ElementRef , EventEmitter , Input , Output , OnInit , OnDestroy , ViewChild , } from '@angular/core' ; import { ActivatedRoute , ActivatedRouteSnapshot , Router , } from '@angular/router' ; import { Subscription } from 'rxjs' ; import { Client } from '../../../services/api/client' ; import { Session } from '../../../services/session' ; import { AttachmentService } from '../../../services/attachment' ; import { SocketsService } from '../../../services/sockets' ; import { CommentsService } from '../comments.service' ; import { ActivityService as ActivityServiceCommentsLegacySupport } from '../../../common/services/activity.service' ; import { ActivityService } from '../../newsfeed/activity/activity.service' ; @ Component ( { selector : 'm-comments__entityOutlet' , templateUrl : 'entity-outlet.component.html' , styleUrls : [ 'entity-outlet.component.ng.scss' ] , providers : [ AttachmentService , { provide : CommentsService , useFactory : ( _route , _client ) => { return new CommentsService ( _route , _client ) ; } , deps : [ ActivatedRoute , Client ] , } , ] , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class CommentsEntityOutletComponent implements OnInit , OnDestroy { entity ; guid : string = '' ; parent : any ; @ Input ( ) limit : number = 12 ; @ Input ( ) canEdit : boolean = false ; @ Input ( ) canDelete : boolean = false ; @ Input ( ) fixedHeight = false ; @ Input ( ) showOnlyPoster = true ; @ Input ( ) compact = false ; optimisticList : Array < any > = [ ] ; constructor ( public session , public client , public attachment , public sockets , private router , private cd , public legacyActivityService , public activityService ) { } ngOnInit ( ) { if ( ! this . activityService . displayOptions . isFeed ) { this . openFullComments ( ) ; } } ngOnDestroy ( ) { } @ Input ( 'entity' ) set _entity ( value ) { this . entity = value ; this . guid = this . entity . guid ; if ( this . entity . entity_guid ) this . guid = this . entity . entity_guid ; this . parent = this . entity ; if ( ! this . canDelete ) { this . canDelete = this . entity . owner_guid == this . session . getLoggedInUser ( ) . guid ; } } get count ( ) : number { return this . entity [ 'comments:count' ] || 0 ; } onPosted ( { comment , index } ) { if ( this . fixedHeight ) { this . redirectToSinglePage ( ) ; } this . optimisticList [ index ] = comment ; this . detectChanges ( ) ; } onOptimisticPost ( comment ) { if ( this . fixedHeight ) return ; this . optimisticList . push ( comment ) ; } toggleComments ( ) { if ( this . count > 0 ) { if ( this . showOnlyPoster ) { this . openFullComments ( ) ; } else { this . closeFullComments ( ) ; } } } openFullComments ( ) { if ( this . fixedHeight ) { this . redirectToSinglePage ( ) ; } this . showOnlyPoster = false ; this . activityService . displayOptions . showOnlyCommentsInput = false ; this . detectChanges ( ) ; } closeFullComments ( ) { this . showOnlyPoster = true ; this . activityService . displayOptions . showOnlyCommentsInput = true ; this . detectChanges ( ) ; } redirectToSinglePage ( ) { this . router . navigate ( [ `/newsfeed/${ this . entity . guid }` ] , { queryParams : { fixedHeight : 0 , } , } ) ; } detectChanges ( ) { this . cd . markForCheck ( ) ; this . cd . detectChanges ( ) ; } ngOnChanges ( changes ) { } }