import { Component , OnDestroy , OnInit , ViewEncapsulation } from '@angular/core' ; import { MediaObserver } from '@angular/flex-layout' ; import { Subject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; import { fuseAnimations } from '@fuse/animations' ; import { FuseMatSidenavHelperService } from '@fuse/directives/fuse-mat-sidenav/fuse-mat-sidenav.service' ; import { MessagesService } from '../../../messages.service' ; import { ChainTime } from '@signumjs/util' ; @ Component ( { selector : 'message-sidenav' , templateUrl : './message.component.html' , styleUrls : [ './message.component.scss' ] , encapsulation : ViewEncapsulation . None , animations : fuseAnimations } ) export class MessageSidenavComponent implements OnInit , OnDestroy { messages : any [ ] ; messageSearch : any ; contacts : any [ ] ; searchText : string ; user : any ; isNewMessage = false ; private _unsubscribeAll : Subject < any > ; param { MessagesService } _messageService param { FuseMatSidenavHelperService } _fuseMatSidenavHelperService param { ObservableMedia } _observableMedia constructor ( private _messageService , private _fuseMatSidenavHelperService , public _observableMedia ) { this . messageSearch = { name : '' } ; this . searchText = '' ; this . _unsubscribeAll = new Subject ( ) ; } /**
     * On init
     */ ngOnInit ( ) { this . user = this . _messageService . user ; this . messages = this . _messageService . messages ; this . contacts = this . _messageService . contacts ; this . _messageService . onMessagesUpdated . pipe ( takeUntil ( this . _unsubscribeAll ) ) . subscribe ( ( messages ) => { this . messages = messages ; } ) ; } /**
     * On destroy
     */ ngOnDestroy ( ) { this . _unsubscribeAll . next ( ) ; this . _unsubscribeAll . complete ( ) ; } param contact getMessage ( contact ) { this . _messageService . getMessage ( contact ) ; if ( ! this . _observableMedia . isActive ( 'gt-md' ) ) { this . _fuseMatSidenavHelperService . getSidenav ( 'message-left-sidenav' ) . toggle ( ) ; } } startMessage ( ) { this . _messageService . sendNewMessage ( this . searchText ) ; if ( ! this . _observableMedia . isActive ( 'gt-md' ) ) { this . _fuseMatSidenavHelperService . getSidenav ( 'message-left-sidenav' ) . toggle ( ) ; } } param view changeLeftSidenavView ( view ) { this . _messageService . onLeftSidenavViewChanged . next ( view ) ; } convertTimestampToDate ( timestamp ) { return ChainTime . fromChainTimestamp ( timestamp ) . getDate ( ) ; } }