import { Component, OnInit, Output, Input, EventEmitter } from '@angular/core'; import { Info, FileEventJson } from '@ucap-webmessenger/protocol-event'; import { StatusCode, FileDownloadItem } from '@ucap-webmessenger/api'; import { FileType } from '@ucap-webmessenger/protocol-file'; import { NGXLogger } from 'ngx-logger'; import { RoomInfo } from '@ucap-webmessenger/protocol-room'; import { SelectFileInfo } from '@ucap-webmessenger/ui'; @Component({ selector: 'ucap-chat-message-box-file', templateUrl: './file.component.html', styleUrls: ['./file.component.scss'] }) export class FileComponent implements OnInit { @Input() message: Info; @Input() roomInfo: RoomInfo; @Output() save = new EventEmitter<{ fileInfo: FileEventJson; fileDownloadItem: FileDownloadItem; type: string; }>(); @Output() fileViewer = new EventEmitter(); fileInfo?: FileEventJson; fileDownloadItem: FileDownloadItem; errorMessage?: string; FileType = FileType; constructor(private logger: NGXLogger) {} ngOnInit() { if (StatusCode.Success === this.message.sentMessageJson.statusCode) { this.fileInfo = this.message.sentMessageJson; } else { this.errorMessage = this.message.sentMessageJson.errorMessage || '[Error] System Error!!'; } this.fileDownloadItem = new FileDownloadItem(); } getExpiredFile() { if ( !!this.roomInfo && this.roomInfo.expiredFileStdSeq <= this.message.seq ) { return false; } else { return true; } } onClickFileViewer(fileInfo: FileEventJson) { if (!this.getExpiredFile()) { this.fileViewer.emit({ attachmentSeq: this.fileInfo.attachmentSeq }); } } onSave(value: string) { if (!this.getExpiredFile()) { this.save.emit({ fileInfo: this.fileInfo, fileDownloadItem: this.fileDownloadItem, type: value }); } } }