next-ucap-messenger/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts

318 lines
9.0 KiB
TypeScript
Raw Normal View History

import {
Component,
OnInit,
OnDestroy,
AfterViewChecked,
ViewChild,
ElementRef
} from '@angular/core';
2019-10-16 09:05:18 +00:00
import {
ucapAnimations,
SnackBarService,
ClipboardService,
DialogService
} from '@ucap-webmessenger/ui';
2019-10-08 04:31:33 +00:00
import { Store, select } from '@ngrx/store';
import { NGXLogger } from 'ngx-logger';
2019-10-08 08:57:57 +00:00
import { Observable, Subscription } from 'rxjs';
2019-10-16 07:33:19 +00:00
import {
Info,
EventType,
isRecalled,
isCopyable,
isRecallable
} from '@ucap-webmessenger/protocol-event';
2019-10-08 04:31:33 +00:00
import * as AppStore from '@app/store';
2019-10-08 05:34:37 +00:00
import * as EventStore from '@app/store/messenger/event';
2019-10-11 09:03:01 +00:00
import * as ChatStore from '@app/store/messenger/chat';
2019-10-11 06:55:27 +00:00
import * as RoomStore from '@app/store/messenger/room';
2019-10-08 04:31:33 +00:00
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
2019-10-16 09:05:18 +00:00
import {
LoginInfo,
KEY_LOGIN_INFO,
EnvironmentsInfo,
KEY_ENVIRONMENTS_INFO
} from '@app/types';
import { RoomInfo, UserInfo } from '@ucap-webmessenger/protocol-room';
2019-10-16 09:05:18 +00:00
import { tap, take } from 'rxjs/operators';
import { FileInfo } from '@ucap-webmessenger/ui-chat';
import { KEY_VER_INFO } from '@app/types/ver-info.type';
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
2019-10-16 07:33:19 +00:00
import { MatMenuTrigger } from '@angular/material';
2019-10-16 09:05:18 +00:00
import { CommonApiService } from '@ucap-webmessenger/api-common';
2019-10-17 00:18:55 +00:00
import {
DeleteMessageDialogComponent,
DeleteMessageDialogData,
DeleteMessageDialogResult
} from '@app/layouts/messenger/dialogs/message/delete-message.dialog.component';
2019-10-16 09:05:18 +00:00
import {
RelayMessageDialogComponent,
RelayMessageDialogData,
RelayMessageDialogResult
2019-10-17 00:18:55 +00:00
} from '@app/layouts/messenger/dialogs/message/relay-message.dialog.component';
import {
RecallMessageDialogComponent,
RecallMessageDialogData,
RecallMessageDialogResult
} from '@app/layouts/messenger/dialogs/message/recall-message.dialog.component';
@Component({
2019-09-26 02:11:22 +00:00
selector: 'app-layout-messenger-messages',
templateUrl: './messages.component.html',
styleUrls: ['./messages.component.scss'],
animations: ucapAnimations
})
export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked {
@ViewChild('messageBoxContainer', { static: true })
private messageBoxContainer: ElementRef;
2019-10-16 07:33:19 +00:00
@ViewChild('messageContextMenuTrigger', { static: true })
messageContextMenuTrigger: MatMenuTrigger;
messageContextMenuPosition = { x: '0px', y: '0px' };
2019-10-16 09:05:18 +00:00
environmentsInfo: EnvironmentsInfo;
2019-10-08 05:59:22 +00:00
loginRes: LoginResponse;
loginResSubscription: Subscription;
2019-10-08 04:31:33 +00:00
eventList$: Observable<Info[]>;
2019-10-08 05:34:37 +00:00
roomInfo: RoomInfo;
roomInfoSubscription: Subscription;
userInfoList$: Observable<UserInfo[]>;
2019-10-08 06:25:00 +00:00
eventListProcessing$: Observable<boolean>;
2019-10-16 09:05:18 +00:00
sessionVerInfo: VersionInfo2Response;
2019-10-08 04:31:33 +00:00
2019-10-16 07:33:19 +00:00
isRecalledMessage = isRecalled;
isCopyableMessage = isCopyable;
isRecallableMessage = isRecallable;
2019-10-08 04:31:33 +00:00
constructor(
private store: Store<any>,
private sessionStorageService: SessionStorageService,
2019-10-16 09:05:18 +00:00
private commonApiService: CommonApiService,
private clipboardService: ClipboardService,
private dialogService: DialogService,
private snackBarService: SnackBarService,
2019-10-08 04:31:33 +00:00
private logger: NGXLogger
2019-10-16 09:05:18 +00:00
) {
this.sessionVerInfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
this.environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
KEY_ENVIRONMENTS_INFO
);
}
2019-10-08 04:31:33 +00:00
ngOnInit() {
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
2019-10-08 05:59:22 +00:00
this.loginResSubscription = this.store
.pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
tap(loginRes => {
this.loginRes = loginRes;
})
)
.subscribe();
2019-10-08 05:34:37 +00:00
this.roomInfoSubscription = this.store
.pipe(
select(AppStore.MessengerSelector.RoomSelector.roomInfo),
tap(roomInfo => {
this.roomInfo = roomInfo;
})
)
.subscribe();
this.userInfoList$ = this.store.pipe(
select(AppStore.MessengerSelector.RoomSelector.userInfoList)
);
2019-10-08 06:25:00 +00:00
this.eventListProcessing$ = this.store.pipe(
select(AppStore.MessengerSelector.EventSelector.infoListProcessing)
);
2019-10-08 04:31:33 +00:00
this.eventList$ = this.store.pipe(
select(AppStore.MessengerSelector.EventSelector.selectAllInfoList)
2019-10-08 04:31:33 +00:00
);
this.scrollToBottomForMessageBoxContainer();
2019-10-08 04:31:33 +00:00
}
2019-10-08 05:34:37 +00:00
ngOnDestroy(): void {
2019-10-08 05:59:22 +00:00
if (!!this.loginResSubscription) {
this.loginResSubscription.unsubscribe();
}
2019-10-08 05:34:37 +00:00
if (!!this.roomInfoSubscription) {
this.roomInfoSubscription.unsubscribe();
}
}
ngAfterViewChecked(): void {
this.scrollToBottomForMessageBoxContainer();
}
selectContact() {}
2019-10-08 05:34:37 +00:00
onSendMessage(message: string) {
this.store.dispatch(
EventStore.send({
2019-10-08 05:59:22 +00:00
senderSeq: this.loginRes.userSeq,
2019-10-08 05:34:37 +00:00
req: {
roomSeq: this.roomInfo.roomSeq,
eventType: EventType.Character,
sentMessage: message
}
})
);
}
2019-10-11 06:55:27 +00:00
onClickReceiveAlarm() {
this.store.dispatch(RoomStore.updateOnlyAlarm({ roomInfo: this.roomInfo }));
}
private scrollToBottomForMessageBoxContainer(): void {
try {
this.messageBoxContainer.nativeElement.scrollTop = this.messageBoxContainer.nativeElement.scrollHeight;
} catch (err) {}
}
2019-10-11 09:03:01 +00:00
/** MassText Detail View */
onMassDetail(value: number) {
this.store.dispatch(
ChatStore.selectedMassDetail({
massEventSeq: value
})
);
}
onImageViewer(value: FileInfo) {
this.logger.debug('imageViewer', value);
}
/** File Save, Save As */
onSave(value: { fileInfo: FileInfo; type: string }) {
this.logger.debug('fileSave', value);
}
2019-10-16 07:33:19 +00:00
onContextMenuMessage(params: { event: MouseEvent; message: Info }) {
params.event.preventDefault();
params.event.stopPropagation();
this.messageContextMenuPosition.x = params.event.clientX + 'px';
this.messageContextMenuPosition.y = params.event.clientY + 'px';
this.messageContextMenuTrigger.menu.focusFirstItem('mouse');
this.messageContextMenuTrigger.menuData = {
message: params.message,
loginRes: this.loginRes
};
this.messageContextMenuTrigger.openMenu();
}
2019-10-16 09:05:18 +00:00
async onClickMessageContextMenu(menuType: string, message: Info) {
2019-10-16 07:33:19 +00:00
switch (menuType) {
case 'COPY':
{
2019-10-16 09:05:18 +00:00
switch (message.type) {
case EventType.Character:
{
if (
this.clipboardService.copyFromContent(message.sentMessage)
) {
this.snackBarService.open('클립보드에 복사되었습니다.', '', {
duration: 3000,
verticalPosition: 'top',
horizontalPosition: 'center'
});
}
}
break;
case EventType.MassText:
{
this.commonApiService
.massTalkDownload({
userSeq: this.loginRes.userSeq,
deviceType: this.environmentsInfo.deviceType,
token: this.loginRes.tokenString,
eventMassSeq: message.seq
})
.pipe(take(1))
.subscribe(res => {
if (this.clipboardService.copyFromContent(res.content)) {
this.snackBarService.open(
'클립보드에 복사되었습니다.',
'',
{
duration: 3000,
verticalPosition: 'top',
horizontalPosition: 'center'
}
);
}
});
}
break;
default:
break;
}
2019-10-16 07:33:19 +00:00
}
break;
case 'REPLAY':
{
2019-10-16 09:05:18 +00:00
const result = await this.dialogService.open<
RelayMessageDialogComponent,
RelayMessageDialogData,
RelayMessageDialogResult
>(RelayMessageDialogComponent, {
width: '220px',
data: {
title: 'Logout',
message: 'Logout ?'
}
});
2019-10-16 07:33:19 +00:00
}
break;
case 'REPLAY_TO_ME':
{
}
break;
case 'DELETE':
{
2019-10-17 00:18:55 +00:00
const result = await this.dialogService.open<
DeleteMessageDialogComponent,
DeleteMessageDialogData,
DeleteMessageDialogResult
>(DeleteMessageDialogComponent, {
width: '220px',
data: {
title: 'Logout',
message: 'Logout ?'
}
});
2019-10-16 07:33:19 +00:00
}
break;
case 'RECALL':
{
2019-10-17 00:18:55 +00:00
const result = await this.dialogService.open<
RecallMessageDialogComponent,
RecallMessageDialogData,
RecallMessageDialogResult
>(RecallMessageDialogComponent, {
width: '220px',
data: {
title: 'Logout',
message: 'Logout ?'
}
});
2019-10-16 07:33:19 +00:00
}
break;
default:
break;
}
}
}