2019-10-31 18:12:38 +09:00
|
|
|
import { CONST } from '@ucap-webmessenger/core';
|
2019-10-15 15:02:00 +09:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
Input,
|
|
|
|
EventEmitter,
|
|
|
|
Output,
|
2019-10-17 18:11:38 +09:00
|
|
|
ViewEncapsulation
|
2019-10-15 15:02:00 +09:00
|
|
|
} from '@angular/core';
|
2019-09-23 14:23:24 +09:00
|
|
|
|
2019-10-29 18:11:31 +09:00
|
|
|
import {
|
|
|
|
Info,
|
|
|
|
EventType,
|
2019-11-06 13:48:06 +09:00
|
|
|
InfoResponse,
|
|
|
|
EventJson
|
2019-10-29 18:11:31 +09:00
|
|
|
} from '@ucap-webmessenger/protocol-event';
|
2019-10-30 16:22:49 +09:00
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { UserInfo } from '@ucap-webmessenger/protocol-room';
|
2019-10-08 15:13:01 +09:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-10-15 14:58:11 +09:00
|
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
2019-10-14 13:53:22 +09:00
|
|
|
import { FileInfo } from '../models/file-info.json';
|
2019-10-14 17:19:13 +09:00
|
|
|
import { DatePipe } from '@angular/common';
|
2019-10-08 13:31:33 +09:00
|
|
|
|
2019-09-23 14:23:24 +09:00
|
|
|
@Component({
|
|
|
|
selector: 'ucap-chat-messages',
|
|
|
|
templateUrl: './messages.component.html',
|
2019-10-25 09:46:14 +09:00
|
|
|
styleUrls: ['./messages.component.scss']
|
2019-09-23 14:23:24 +09:00
|
|
|
})
|
|
|
|
export class MessagesComponent implements OnInit {
|
|
|
|
@Input()
|
2019-10-08 13:31:33 +09:00
|
|
|
loginRes: LoginResponse;
|
|
|
|
@Input()
|
2019-11-06 13:48:06 +09:00
|
|
|
messages: Info<EventJson>[];
|
2019-10-11 11:40:35 +09:00
|
|
|
@Input()
|
2019-10-29 18:11:31 +09:00
|
|
|
eventInfoStatus?: InfoResponse;
|
|
|
|
@Input()
|
2019-10-31 18:12:38 +09:00
|
|
|
eventRemain: boolean;
|
|
|
|
@Input()
|
2019-10-11 11:40:35 +09:00
|
|
|
userInfos?: UserInfo[];
|
2019-10-15 14:58:11 +09:00
|
|
|
@Input()
|
|
|
|
sessionVerInfo: VersionInfo2Response;
|
2019-09-23 14:23:24 +09:00
|
|
|
|
2019-10-31 18:12:38 +09:00
|
|
|
@Output()
|
|
|
|
moreEvent = new EventEmitter<number>();
|
2019-10-11 18:03:01 +09:00
|
|
|
@Output()
|
|
|
|
massDetail = new EventEmitter<number>();
|
2019-10-14 13:53:22 +09:00
|
|
|
@Output()
|
|
|
|
imageViewer = new EventEmitter<FileInfo>();
|
|
|
|
@Output()
|
|
|
|
save = new EventEmitter<{ fileInfo: FileInfo; type: string }>();
|
2019-10-16 16:33:19 +09:00
|
|
|
@Output()
|
|
|
|
contextMenu = new EventEmitter<{
|
|
|
|
event: MouseEvent;
|
2019-11-06 13:48:06 +09:00
|
|
|
message: Info<EventJson>;
|
2019-10-16 16:33:19 +09:00
|
|
|
}>();
|
2019-10-15 15:02:00 +09:00
|
|
|
|
2019-10-08 16:41:23 +09:00
|
|
|
EventType = EventType;
|
2019-10-31 18:12:38 +09:00
|
|
|
CONST = CONST;
|
2019-10-11 11:40:35 +09:00
|
|
|
profileImageRoot: string;
|
2019-10-08 16:41:23 +09:00
|
|
|
|
2019-10-28 11:15:38 +09:00
|
|
|
constructor(private logger: NGXLogger, private datePipe: DatePipe) {}
|
2019-09-23 14:23:24 +09:00
|
|
|
|
2019-10-08 15:13:01 +09:00
|
|
|
ngOnInit() {
|
2019-10-15 14:58:11 +09:00
|
|
|
this.profileImageRoot =
|
|
|
|
this.profileImageRoot || this.sessionVerInfo.profileRoot;
|
2019-10-11 11:40:35 +09:00
|
|
|
}
|
|
|
|
|
2019-10-30 16:22:49 +09:00
|
|
|
/**
|
|
|
|
* UserInfo getter
|
|
|
|
*/
|
2019-10-11 11:40:35 +09:00
|
|
|
getUserName(seq: number): string {
|
2019-10-11 15:55:27 +09:00
|
|
|
if (!this.userInfos) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-10-11 11:40:35 +09:00
|
|
|
const userInfo: UserInfo[] = this.userInfos.filter(
|
|
|
|
user => user.seq === seq
|
|
|
|
);
|
|
|
|
if (!!userInfo && userInfo.length > 0) {
|
|
|
|
return userInfo[0].name;
|
|
|
|
}
|
|
|
|
return '(알수없는 사용자)';
|
|
|
|
}
|
|
|
|
getUserProfile(seq: number): string {
|
2019-10-11 15:55:27 +09:00
|
|
|
if (!this.userInfos) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-10-11 11:40:35 +09:00
|
|
|
const userInfo: UserInfo[] = this.userInfos.filter(
|
|
|
|
user => user.seq === seq
|
|
|
|
);
|
|
|
|
if (!!userInfo && userInfo.length > 0) {
|
2019-10-17 16:57:37 +09:00
|
|
|
return userInfo[0].profileImageFile;
|
2019-10-11 11:40:35 +09:00
|
|
|
}
|
|
|
|
return '';
|
2019-10-08 15:13:01 +09:00
|
|
|
}
|
2019-10-11 18:03:01 +09:00
|
|
|
|
2019-11-06 13:48:06 +09:00
|
|
|
getUnreadCount(message: Info<EventJson>): string | number {
|
2019-10-30 16:22:49 +09:00
|
|
|
const unreadCnt = this.userInfos.filter(user => {
|
|
|
|
if (message.senderSeq === user.seq) {
|
|
|
|
// 본인 글은 unreadCount 에 포함하지 않는다.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return user.lastReadEventSeq < message.seq;
|
|
|
|
}).length;
|
|
|
|
return unreadCnt === 0 ? '' : unreadCnt;
|
|
|
|
}
|
|
|
|
|
2019-10-15 11:50:23 +09:00
|
|
|
/**
|
|
|
|
* 정보성 Event 인지 판단.
|
|
|
|
* @description 정보성 event 일 경우 프로필, 일시 를 표현하지 않는다.
|
2019-10-29 10:46:55 +09:00
|
|
|
* Edit with reducers.ts / sync / updateRoomForNewEventMessage
|
2019-10-15 11:50:23 +09:00
|
|
|
*/
|
2019-11-06 13:48:06 +09:00
|
|
|
getIsInformation(info: Info<EventJson>) {
|
2019-10-15 11:50:23 +09:00
|
|
|
if (
|
|
|
|
info.type === EventType.Join ||
|
|
|
|
info.type === EventType.Exit ||
|
|
|
|
info.type === EventType.RenameRoom ||
|
|
|
|
info.type === EventType.NotificationForTimerRoom ||
|
|
|
|
info.type === EventType.GuideForRoomTimerChanged
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-30 16:22:49 +09:00
|
|
|
/** Date Splitter show check */
|
2019-10-14 17:19:13 +09:00
|
|
|
getDateSplitter(curIndex: number): boolean {
|
|
|
|
if (curIndex === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (curIndex > 0) {
|
|
|
|
return (
|
|
|
|
this.datePipe.transform(
|
|
|
|
this.messages[curIndex].sendDate,
|
|
|
|
'yyyyMMdd'
|
|
|
|
) !==
|
|
|
|
this.datePipe.transform(
|
|
|
|
this.messages[curIndex - 1].sendDate,
|
|
|
|
'yyyyMMdd'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-31 18:12:38 +09:00
|
|
|
onClickMore(event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
this.moreEvent.emit(this.messages[0].seq);
|
|
|
|
}
|
|
|
|
|
2019-10-14 17:19:13 +09:00
|
|
|
/** [Event] MassTalk Detail View */
|
2019-10-11 18:03:01 +09:00
|
|
|
onMassDetail(value: number) {
|
|
|
|
this.massDetail.emit(value);
|
|
|
|
}
|
2019-10-14 13:53:22 +09:00
|
|
|
|
2019-10-14 17:19:13 +09:00
|
|
|
/** [Event] Image Viewer */
|
2019-10-14 13:53:22 +09:00
|
|
|
onImageViewer(value: FileInfo) {
|
|
|
|
this.imageViewer.emit(value);
|
|
|
|
}
|
|
|
|
|
2019-10-14 17:19:13 +09:00
|
|
|
/** [Event] Attach File Save & Save As */
|
2019-10-14 13:53:22 +09:00
|
|
|
onSave(value: { fileInfo: FileInfo; type: string }) {
|
|
|
|
this.save.emit(value);
|
|
|
|
}
|
2019-10-15 15:02:00 +09:00
|
|
|
|
2019-10-30 16:22:49 +09:00
|
|
|
/** [Event] Context Menu */
|
2019-11-06 13:48:06 +09:00
|
|
|
onContextMenuMessage(event: MouseEvent, message: Info<EventJson>) {
|
2019-10-16 16:33:19 +09:00
|
|
|
this.contextMenu.emit({ event, message });
|
2019-10-15 15:02:00 +09:00
|
|
|
}
|
2019-09-23 14:23:24 +09:00
|
|
|
}
|