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

1924 lines
57 KiB
TypeScript
Raw Normal View History

import {
Component,
OnInit,
OnDestroy,
ViewChild,
2019-11-08 04:35:39 +00:00
AfterViewInit,
Output,
EventEmitter,
Inject,
ChangeDetectorRef,
ChangeDetectionStrategy
} from '@angular/core';
2019-10-16 09:05:18 +00:00
import {
ucapAnimations,
SnackBarService,
ClipboardService,
DialogService,
ConfirmDialogComponent,
ConfirmDialogData,
ConfirmDialogResult,
AlertDialogComponent,
AlertDialogData,
2019-11-05 04:46:17 +00:00
AlertDialogResult,
2019-11-09 04:35:24 +00:00
FileUploadQueueComponent,
StringUtil,
AlertSnackbarComponent,
AlertSnackbarData
2019-10-16 09:05:18 +00:00
} from '@ucap-webmessenger/ui';
2019-10-08 04:31:33 +00:00
import { Store, select } from '@ngrx/store';
import { NGXLogger } from 'ngx-logger';
2020-01-17 01:41:22 +00:00
import {
Observable,
Subscription,
forkJoin,
combineLatest,
of,
BehaviorSubject
} from 'rxjs';
2019-10-16 07:33:19 +00:00
import {
Info,
EventType,
isRecalled,
isCopyable,
isRecallable,
isForwardable,
2019-11-06 04:48:06 +00:00
InfoResponse,
EventJson,
FileEventJson,
2019-12-23 06:23:27 +00:00
StickerEventJson,
2019-12-31 05:36:32 +00:00
MassTextEventJson,
2019-12-31 07:10:24 +00:00
TranslationEventJson,
MassTranslationEventJson
2019-10-16 07:33:19 +00:00
} 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';
import * as SyncStore from '@app/store/messenger/sync';
2019-10-08 04:31:33 +00:00
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
2019-11-25 06:48:43 +00:00
import {
SessionStorageService,
LocalStorageService
} from '@ucap-webmessenger/web-storage';
import {
EnvironmentsInfo,
KEY_ENVIRONMENTS_INFO,
UserSelectDialogType,
2019-11-25 06:48:43 +00:00
RightDrawer,
KEY_STICKER_HISTORY
} from '@app/types';
import {
RoomInfo,
UserInfo,
RoomType,
UserInfoShort
} from '@ucap-webmessenger/protocol-room';
import { tap, take, map, catchError, finalize } from 'rxjs/operators';
2020-01-17 01:41:22 +00:00
import {
FormComponent as UCapUiChatFormComponent,
MessagesComponent as UCapUiChatMessagesComponent
} from '@ucap-webmessenger/ui-chat';
2019-12-13 05:38:42 +00:00
import { KEY_VER_INFO } from '@app/types';
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
import {
MatMenuTrigger,
MatSnackBarRef,
SimpleSnackBar
} from '@angular/material';
import { FileUploadItem, FileDownloadItem } from '@ucap-webmessenger/api';
2019-11-05 04:46:17 +00:00
import {
CommonApiService,
FileTalkSaveRequest,
2019-12-31 05:36:32 +00:00
FileTalkSaveResponse,
2019-12-31 07:10:24 +00:00
TranslationSaveRequest,
TranslationSaveResponse
2019-11-05 04:46:17 +00:00
} from '@ucap-webmessenger/api-common';
2019-10-17 00:18:55 +00:00
import {
CreateChatDialogComponent,
CreateChatDialogData,
CreateChatDialogResult
} from '../dialogs/chat/create-chat.dialog.component';
2019-10-29 00:07:06 +00:00
import {
2019-11-06 04:48:06 +00:00
FileViewerDialogComponent,
FileViewerDialogData,
FileViewerDialogResult
2019-11-06 04:48:06 +00:00
} from '@app/layouts/common/dialogs/file-viewer.dialog.component';
import { FileUtil, StickerFilesInfo, MimeUtil } from '@ucap-webmessenger/core';
2020-01-17 01:41:22 +00:00
2019-11-05 04:46:17 +00:00
import { StatusCode } from '@ucap-webmessenger/api';
import {
EditChatRoomDialogComponent,
EditChatRoomDialogResult,
EditChatRoomDialogData
} from '../dialogs/chat/edit-chat-room.dialog.component';
import {
SelectGroupDialogComponent,
SelectGroupDialogResult,
SelectGroupDialogData
} from '../dialogs/group/select-group.dialog.component';
import { GroupDetailData } from '@ucap-webmessenger/protocol-sync';
import { environment } from '../../../../environments/environment';
2020-01-01 23:44:16 +00:00
import {
MassDetailComponent,
MassDetailDialogData
} from '../dialogs/chat/mass-detail.component';
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
2020-01-07 02:36:25 +00:00
import { TranslateService } from '@ngx-translate/core';
import { TranslatePipe } from 'projects/ucap-webmessenger-ui/src/lib/pipes/translate.pipe';
import { TranslateService as UiTranslateService } from '@ucap-webmessenger/ui';
import { FileProtocolService } from '@ucap-webmessenger/protocol-file';
@Component({
2019-09-26 02:11:22 +00:00
selector: 'app-layout-messenger-messages',
templateUrl: './messages.component.html',
styleUrls: ['./messages.component.scss'],
animations: ucapAnimations,
changeDetection: ChangeDetectionStrategy.OnPush
})
2019-11-01 06:06:37 +00:00
export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
2019-11-08 04:35:39 +00:00
@Output()
openProfile = new EventEmitter<{
userSeq: number;
}>();
@Output()
closeRightDrawer = new EventEmitter();
2019-11-08 04:35:39 +00:00
@ViewChild('chatForm', { static: false })
2019-11-01 06:06:37 +00:00
private chatForm: UCapUiChatFormComponent;
2019-10-16 07:33:19 +00:00
@ViewChild('messageContextMenuTrigger', { static: true })
messageContextMenuTrigger: MatMenuTrigger;
messageContextMenuPosition = { x: '0px', y: '0px' };
2019-11-05 04:46:17 +00:00
@ViewChild('fileUploadQueue', { static: true })
fileUploadQueue: FileUploadQueueComponent;
2020-01-17 01:41:22 +00:00
@ViewChild('chatMessages', { static: true })
chatMessages: UCapUiChatMessagesComponent;
2019-10-16 09:05:18 +00:00
environmentsInfo: EnvironmentsInfo;
2019-10-08 05:59:22 +00:00
loginResSubscription: Subscription;
2020-01-17 01:41:22 +00:00
loginResSubject = new BehaviorSubject<LoginResponse>(undefined);
2019-10-08 05:34:37 +00:00
roomInfoSubscription: Subscription;
2020-01-17 01:41:22 +00:00
roomInfoSubject = new BehaviorSubject<RoomInfo>(undefined);
userInfoListSubscription: Subscription;
2020-01-17 01:41:22 +00:00
userInfoListSubject = new BehaviorSubject<UserInfo[]>(undefined);
eventListSubscription: Subscription;
eventListSubject = new BehaviorSubject<Info<EventJson>[]>(undefined);
eventListNewSubject = new BehaviorSubject<Info<EventJson>[]>(undefined);
eventInfoStatusSubscription: Subscription;
2020-01-17 01:41:22 +00:00
eventInfoStatusSubject = new BehaviorSubject<InfoResponse>(undefined);
eventRemainedSubscription: Subscription;
eventRemainedSubject = new BehaviorSubject<boolean>(false); // 이전대화가 남아 있는지 여부
2019-10-16 09:05:18 +00:00
sessionVerInfo: VersionInfo2Response;
2019-10-08 04:31:33 +00:00
2020-01-17 01:41:22 +00:00
baseEventSeq = 0;
eventListProcessing$: Observable<boolean>;
searchEventListProcessing: boolean;
searchEventListProcessingSubscription: Subscription;
2019-10-16 07:33:19 +00:00
isRecalledMessage = isRecalled;
isCopyableMessage = isCopyable;
isRecallableMessage = isRecallable;
isForwardableMessage = isForwardable;
2019-10-16 07:33:19 +00:00
/** Timer 대화방의 대화 삭제를 위한 interval */
interval: any;
2019-12-23 06:23:27 +00:00
/** About Searching */
2020-01-07 04:45:34 +00:00
isShowSearchArea = false;
2019-12-23 06:23:27 +00:00
moreSearchProcessing = false;
searchText = '';
2020-01-17 01:41:22 +00:00
searchedListSubject = new BehaviorSubject<Info<EventJson>[]>(undefined);
2019-12-23 06:23:27 +00:00
searchedFocusEvent: Info<EventJson>;
searchTotalCount = 0;
searchCurrentIndex = 0;
/** About Sticker */
2019-11-20 09:04:24 +00:00
isShowStickerSelector = false;
selectedSticker: StickerFilesInfo;
2019-11-20 09:04:24 +00:00
2019-12-31 05:36:32 +00:00
/** About Translation */
isTranslationProcess = false;
2019-12-31 05:36:32 +00:00
isShowTranslation = false;
translationSimpleview = false;
translationPreview = false;
destLocale = 'en'; // default English :: en
2019-12-31 07:10:24 +00:00
translationPreviewInfo: {
previewInfo: TranslationSaveResponse | null;
translationType: EventType.Translation | EventType.MassTranslation;
};
2019-12-31 05:36:32 +00:00
2019-12-19 05:23:11 +00:00
/** About ReadHere */
2020-01-17 01:41:22 +00:00
firstCheckReadHere = true;
2019-12-19 05:23:11 +00:00
clearReadHere = false;
initRoomLastEventSeq: number;
2019-12-19 05:23:11 +00:00
snackBarPreviewEvent: MatSnackBarRef<SimpleSnackBar>;
2019-12-17 07:13:38 +00:00
RoomType = RoomType;
environment = environment;
2019-12-17 07:13:38 +00:00
2019-10-08 04:31:33 +00:00
constructor(
private store: Store<any>,
private sessionStorageService: SessionStorageService,
2019-11-25 06:48:43 +00:00
private localStorageService: LocalStorageService,
2019-10-16 09:05:18 +00:00
private commonApiService: CommonApiService,
private fileProtocolService: FileProtocolService,
2019-10-16 09:05:18 +00:00
private clipboardService: ClipboardService,
private uiTranslateService: UiTranslateService,
2020-01-07 02:36:25 +00:00
private translateService: TranslateService,
private changeDetectorRef: ChangeDetectorRef,
2019-10-16 09:05:18 +00:00
private dialogService: DialogService,
private snackBarService: SnackBarService,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
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() {
2019-10-08 05:59:22 +00:00
this.loginResSubscription = this.store
2020-01-17 01:41:22 +00:00
.pipe(select(AppStore.AccountSelector.AuthenticationSelector.loginRes))
.subscribe(loginRes => {
this.loginResSubject.next(loginRes);
});
2019-10-08 05:34:37 +00:00
this.roomInfoSubscription = this.store
2020-01-17 01:41:22 +00:00
.pipe(select(AppStore.MessengerSelector.RoomSelector.roomInfo))
.subscribe(roomInfo => {
this.clearView();
this.roomInfoSubject.next(roomInfo);
});
2019-10-08 05:34:37 +00:00
this.userInfoListSubscription = this.store
2020-01-17 01:41:22 +00:00
.pipe(select(AppStore.MessengerSelector.RoomSelector.selectUserinfolist))
.subscribe(userInfoList => {
this.userInfoListSubject.next(userInfoList);
});
2019-10-08 06:25:00 +00:00
this.eventListProcessing$ = this.store.pipe(
select(AppStore.MessengerSelector.EventSelector.infoListProcessing)
);
2020-01-07 04:45:34 +00:00
this.searchEventListProcessingSubscription = this.store
.pipe(
select(
AppStore.MessengerSelector.EventSelector.infoSearchListProcessing
2020-01-17 01:41:22 +00:00
)
2020-01-07 04:45:34 +00:00
)
2020-01-17 01:41:22 +00:00
.subscribe(process => {
this.searchEventListProcessing = process;
if (!process && this.isShowSearchArea) {
this.doSearchTextInEvent(this.searchText);
this.snackBarService.open(
this.translateService.instant('chat.searchEventByTextEnd'),
this.translateService.instant('common.messages.confirm'),
{
duration: 3000,
verticalPosition: 'top',
horizontalPosition: 'center'
}
);
}
});
2020-01-07 04:45:34 +00:00
2020-01-17 01:41:22 +00:00
this.eventRemainedSubscription = this.store
.pipe(select(AppStore.MessengerSelector.EventSelector.remainInfo))
.subscribe(remained => {
this.eventRemainedSubject.next(remained);
});
2019-12-19 05:23:11 +00:00
// [Daesang]
this.eventListSubscription = combineLatest([
this.store.pipe(
select(AppStore.MessengerSelector.EventSelector.selectAllInfoList)
),
this.store.pipe(select(AppStore.MessengerSelector.RoomSelector.roomInfo))
2020-01-17 01:41:22 +00:00
]).subscribe(([infoList, roomInfo]) => {
if (
!!this.eventListSubject.value &&
this.eventListSubject.value.length > 0
) {
this.eventListNewSubject.next(
infoList.filter(info => {
2019-12-19 05:23:11 +00:00
if (
2020-01-17 01:41:22 +00:00
info.seq <=
this.eventListSubject.value[
this.eventListSubject.value.length - 1
].seq
2019-12-19 05:23:11 +00:00
) {
2020-01-17 01:41:22 +00:00
return false;
2019-12-19 05:23:11 +00:00
}
2020-01-17 01:41:22 +00:00
return true;
})
);
2019-12-19 05:23:11 +00:00
2020-01-17 01:41:22 +00:00
if (
!!infoList &&
infoList.length > 0 &&
!!roomInfo &&
!!roomInfo.lastReadEventSeq &&
this.baseEventSeq <= roomInfo.lastReadEventSeq
) {
// 조회된 내용중에 read here 가 있을 경우.
this.firstCheckReadHere = false;
}
}
2020-01-17 01:41:22 +00:00
this.eventListSubject.next(infoList);
if (this.moreSearchProcessing) {
const baseseq = this.baseEventSeq;
// setTimeout(() => {
// this.doSearchTextInEvent(this.searchText, baseseq);
// }, 800);
this.baseEventSeq = infoList[0].seq;
} else {
if (!!infoList && infoList.length > 0) {
this.baseEventSeq = infoList[0].seq;
this.readyToReply();
}
}
});
2019-12-19 05:23:11 +00:00
// // [GROUP]
// this.eventListSubscription = this.store
// .pipe(
// select(AppStore.MessengerSelector.EventSelector.selectAllInfoList),
// tap(infoList => {
// if (!!this.eventList && this.eventList.length > 0) {
// this.eventListNew = infoList.filter(info => {
// if (info.seq <= this.eventList[this.eventList.length - 1].seq) {
// return false;
// }
// return true;
// });
// }
// this.eventList = infoList;
// if (!!infoList && infoList.length > 0) {
// this.baseEventSeq = infoList[0].seq;
// this.readyToReply();
// }
// })
// )
// .subscribe();
this.eventInfoStatusSubscription = this.store
2020-01-17 01:41:22 +00:00
.pipe(select(AppStore.MessengerSelector.EventSelector.infoStatus))
.subscribe(res => {
this.eventInfoStatusSubject.next(res);
if (!!res) {
const elist = this.eventListSubject.value;
if (res.baseSeq === 0 && elist.length > 0) {
this.initRoomLastEventSeq = elist[elist.length - 1].seq;
}
2020-01-17 01:41:22 +00:00
}
});
if (
!!this.roomInfoSubject.value &&
!!this.roomInfoSubject.value.isTimeRoom
) {
this.interval = setInterval(() => {
this.store.dispatch(EventStore.infoIntervalClear({}));
}, 1000);
}
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();
}
if (!!this.userInfoListSubscription) {
this.userInfoListSubscription.unsubscribe();
}
if (!!this.eventListSubscription) {
this.eventListSubscription.unsubscribe();
}
if (!!this.eventInfoStatusSubscription) {
this.eventInfoStatusSubscription.unsubscribe();
}
2020-01-17 01:41:22 +00:00
if (!!this.eventRemainedSubscription) {
this.eventRemainedSubscription.unsubscribe();
}
2020-01-07 04:45:34 +00:00
if (!!this.searchEventListProcessingSubscription) {
this.searchEventListProcessingSubscription.unsubscribe();
}
if (!!this.interval) {
clearInterval(this.interval);
}
2019-10-08 05:34:37 +00:00
}
2019-11-01 06:06:37 +00:00
ngAfterViewInit(): void {
// this.readyToReply();
}
/**
* .
*/
clearView() {
// Right Drawer closed..
this.closeRightDrawer.emit();
// Sticker Selector Clear..
this.isShowStickerSelector = false;
this.selectedSticker = undefined;
2019-12-19 05:23:11 +00:00
2019-12-23 06:23:27 +00:00
// Chat Search Clear..
this.onCloseSearchArea();
2019-12-31 05:36:32 +00:00
// Translate Clear..
this.isTranslationProcess = false;
2019-12-31 05:36:32 +00:00
this.isShowTranslation = false;
this.translationSimpleview = false;
this.translationPreview = false;
// this.destLocale = 'en'; // default English :: en
this.translationPreviewInfo = null;
// Read here Clear..
2020-01-17 01:41:22 +00:00
this.firstCheckReadHere = true;
2019-12-23 06:23:15 +00:00
2019-12-31 05:36:32 +00:00
// Chat Formfield Clear..
2019-12-23 06:23:15 +00:00
if (!!this.chatForm) {
this.chatForm.replyForm.reset();
}
}
2019-12-17 07:13:38 +00:00
get _roomUserInfos() {
2020-01-17 01:41:22 +00:00
return this.userInfoListSubject.value
2019-12-17 07:13:38 +00:00
.filter(roomUserInfo => {
return (
2020-01-17 01:41:22 +00:00
this.loginResSubject.value.userSeq !== roomUserInfo.seq &&
roomUserInfo.isJoinRoom
2019-12-17 07:13:38 +00:00
);
})
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
}
getRoomNameByRoomUser(roomUserInfos: (UserInfo | UserInfoShort)[]) {
let roomName = new TranslatePipe(
this.uiTranslateService,
this.changeDetectorRef
).transform(roomUserInfos, 'name', ',');
if (!roomName || roomName.trim().length === 0) {
roomName = this.translateService.instant('chat.noRoomUser');
}
return roomName;
}
/** 대화전송 가능한 방인지 판단 */
getEnableSend() {
2020-01-17 01:41:22 +00:00
if (!this.roomInfoSubject.value) {
return false;
}
if (
2020-01-17 01:41:22 +00:00
[
RoomType.Bot,
RoomType.Allim,
RoomType.Link,
RoomType.Allim_Elephant,
RoomType.Allim_TMS
].some(v => v === this.roomInfoSubject.value.roomType)
) {
return false;
}
return true;
}
2019-10-31 06:05:59 +00:00
getConvertTimer(timerInterval: number, unit: number = 1) {
if (timerInterval >= 0 && timerInterval < 60 * unit) {
return Math.floor((timerInterval / 1) * unit) + ' 초';
} else if (timerInterval >= 60 * unit && timerInterval < 3600 * unit) {
return Math.floor(((timerInterval / 1) * unit) / 60) + ' 분';
} else if (timerInterval >= 3600 * unit && timerInterval <= 86400 * unit) {
return Math.floor(((timerInterval / 1) * unit) / 60 / 60) + ' 시간';
} else {
return '';
}
}
getShowContextMenu(menuType: string) {
if (
2020-01-17 01:41:22 +00:00
['OPEN_ROOM_USER', 'ADD_MEMBER', 'ADD_GROUP', 'EDIT_ROOM'].some(
v => v === menuType
)
) {
if (
2020-01-17 01:41:22 +00:00
!this.roomInfoSubject.value ||
!this.roomInfoSubject.value.roomType ||
[
RoomType.Mytalk,
RoomType.Allim,
RoomType.Bot,
RoomType.Link,
RoomType.Allim_Elephant,
RoomType.Allim_TMS
].some(v => v === this.roomInfoSubject.value.roomType)
) {
return false;
}
}
return true;
}
getShowUnreadCount(): boolean {
2020-01-17 01:41:22 +00:00
if (
!this.roomInfoSubject.value ||
this.roomInfoSubject.value === undefined
) {
return true;
}
if (
2020-01-17 01:41:22 +00:00
[
RoomType.Mytalk,
RoomType.Allim,
RoomType.Bot,
RoomType.Link,
RoomType.Allim_Elephant,
RoomType.Allim_TMS
].some(v => v === this.roomInfoSubject.value.roomType)
) {
return false;
}
return true;
}
2019-11-01 06:06:37 +00:00
readyToReply(): void {
setTimeout(() => {
this.focusReplyInput();
});
}
focusReplyInput(): void {
setTimeout(() => {
if (!!this.chatForm) {
this.chatForm.focus();
}
2019-11-01 06:06:37 +00:00
});
}
2020-01-17 01:41:22 +00:00
onScrollupMessages(event: any) {}
onYReachStartMessages(event: any) {
2019-12-19 05:23:11 +00:00
// 자동 스크롤이 아닌 버튼 방식으로 변경.
// this.onMoreEvent(this.baseEventSeq);
}
2020-01-17 01:41:22 +00:00
onYReachEndMessages(event: any) {
this.chatMessages.initEventMore();
if (!!this.snackBarPreviewEvent) {
this.snackBarPreviewEvent.dismiss();
}
2019-12-19 05:23:11 +00:00
// // clear readHere object.. 정책상 클리어 하지 않도록 함.
2020-01-17 01:41:22 +00:00
// if (!this.firstCheckReadHere) {
// this.clearReadHere = true;
// }
}
/** More Event */
onMoreEvent(seq: number) {
2020-01-17 01:41:22 +00:00
this.store.dispatch(
EventStore.info({
roomSeq: this.roomInfoSubject.value.roomSeq,
baseSeq: seq,
requestCount:
environment.productConfig.CommonSetting.eventRequestDefaultCount
})
);
}
2019-11-01 06:06:37 +00:00
2019-12-31 05:36:32 +00:00
/** Send Event */
2020-01-08 03:30:39 +00:00
async onSendMessage(message: string) {
2020-01-17 01:41:22 +00:00
this.chatMessages.initEventMore();
if (!this.selectedSticker) {
if (!message || message.trim().length === 0) {
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
title: this.translateService.instant('chat.errors.label'),
message: this.translateService.instant(
'chat.errors.inputChatMessage'
)
}
});
return;
}
}
2019-12-31 05:36:32 +00:00
if (!!this.isShowTranslation && this.destLocale.trim().length > 0) {
/** CASE : Translation */
const destLocale = this.destLocale;
const original = message;
2020-01-17 01:41:22 +00:00
const roomSeq = this.roomInfoSubject.value.roomSeq;
if (!!this.isTranslationProcess) {
return;
}
this.isTranslationProcess = true;
2019-12-31 05:36:32 +00:00
this.commonApiService
.translationSave({
2020-01-17 01:41:22 +00:00
userSeq: this.loginResSubject.value.userSeq,
2019-12-31 05:36:32 +00:00
deviceType: this.environmentsInfo.deviceType,
2020-01-17 01:41:22 +00:00
token: this.loginResSubject.value.tokenString,
2019-12-31 05:36:32 +00:00
roomSeq,
original,
srcLocale: '',
destLocale
} as TranslationSaveRequest)
.pipe(
take(1),
map(res => {
if (res.statusCode === StatusCode.Success) {
2019-12-31 07:10:24 +00:00
let sentMessage = '';
let eventType = EventType.Translation;
let previewObject:
| TranslationEventJson
| MassTranslationEventJson;
2019-12-31 05:36:32 +00:00
if (res.translationSeq > 0) {
// Mass Text Translation
2019-12-31 07:10:24 +00:00
previewObject = res;
sentMessage = res.returnJson;
eventType = EventType.MassTranslation;
2019-12-31 05:36:32 +00:00
} else {
// Normal Text Translation
2019-12-31 07:10:24 +00:00
previewObject = {
2019-12-31 05:36:32 +00:00
locale: destLocale,
original,
translation: res.translation,
stickername: '',
stickerfile: !!this.selectedSticker
? this.selectedSticker.index
: ''
};
2019-12-31 07:10:24 +00:00
sentMessage = JSON.stringify(previewObject);
eventType = EventType.Translation;
}
if (!!this.translationPreview) {
// preview
this.translationPreviewInfo = {
previewInfo: res,
translationType: eventType
};
} else {
// direct send
this.store.dispatch(
EventStore.send({
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
2019-12-31 07:10:24 +00:00
req: {
roomSeq,
eventType,
sentMessage
}
})
);
2019-12-31 05:36:32 +00:00
2019-12-31 07:10:24 +00:00
if (!!this.translationPreviewInfo) {
this.translationPreviewInfo = null;
2019-12-31 05:36:32 +00:00
}
}
2019-12-31 07:10:24 +00:00
if (!!this.selectedSticker) {
this.isShowStickerSelector = false;
this.setStickerHistory(this.selectedSticker);
this.selectedSticker = null;
2019-12-31 07:10:24 +00:00
}
2019-12-31 05:36:32 +00:00
} else {
this.logger.error(res);
}
}),
catchError(error => of(this.logger.error(error)))
)
.subscribe(() => {
this.isTranslationProcess = false;
});
2019-12-31 05:36:32 +00:00
} else if (!!this.selectedSticker) {
/** CASE : Sticker */
if (
!!message &&
message.trim().length >
environment.productConfig.CommonSetting.masstextLength
) {
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
title: this.translateService.instant('chat.errors.label'),
message: this.translateService.instant(
'chat.errors.maxLengthOfMassText',
{
maxLength:
environment.productConfig.CommonSetting.masstextLength
2020-01-07 02:36:25 +00:00
}
2020-01-08 03:30:39 +00:00
)
}
});
return;
}
const stickerJson: StickerEventJson = {
name: '스티커',
file: this.selectedSticker.index,
chat: !!message ? message.trim() : ''
};
this.store.dispatch(
EventStore.send({
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
req: {
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
eventType: EventType.Sticker,
sentMessage: JSON.stringify(stickerJson)
}
})
);
this.isShowStickerSelector = false;
2019-11-25 06:48:43 +00:00
this.setStickerHistory(this.selectedSticker);
this.selectedSticker = null;
} else if (
message.trim().length >
environment.productConfig.CommonSetting.masstextLength
) {
2019-12-31 05:36:32 +00:00
/** CASE : MASS TEXT */
2019-10-28 09:03:27 +00:00
this.store.dispatch(
EventStore.sendMass({
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
2019-10-28 09:03:27 +00:00
req: {
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
2019-10-28 09:03:27 +00:00
eventType: EventType.MassText,
// sentMessage: message.replace(/\n/gi, '\r\n')
sentMessage: message
}
2019-10-28 09:03:27 +00:00
})
);
} else {
2019-12-31 05:36:32 +00:00
/** CASE : Normal Text */
2019-10-28 09:03:27 +00:00
this.store.dispatch(
EventStore.send({
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
2019-10-28 09:03:27 +00:00
req: {
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
2019-10-28 09:03:27 +00:00
eventType: EventType.Character,
sentMessage: message
}
2019-10-28 09:03:27 +00:00
})
);
}
2019-10-08 05:34:37 +00:00
}
2019-10-11 06:55:27 +00:00
onClickReceiveAlarm() {
2020-01-17 01:41:22 +00:00
this.store.dispatch(
RoomStore.updateOnlyAlarm({ roomInfo: this.roomInfoSubject.value })
);
2019-10-11 06:55:27 +00:00
}
2019-10-11 09:03:01 +00:00
/** MassText Detail View */
onMassDetail(value: number) {
this.store.dispatch(
ChatStore.selectedMassDetail({
massEventSeq: value
2019-10-11 09:03:01 +00:00
})
);
}
onMassTranslationDetail(params: {
message: Info<MassTranslationEventJson>;
2020-01-01 23:44:16 +00:00
contentsType: string;
}) {
this.commonApiService
.transMassTalkDownload({
2020-01-17 01:41:22 +00:00
userSeq: this.loginResSubject.value.userSeq,
deviceType: this.environmentsInfo.deviceType,
2020-01-17 01:41:22 +00:00
token: this.loginResSubject.value.tokenString,
eventTransSeq: params.message.sentMessageJson.translationSeq.toString()
})
.pipe(take(1))
.subscribe(res => {
let contents = '';
if (res.statusCode === StatusCode.Success) {
contents =
params.contentsType === 'T' ? res.translation : res.original;
} else {
contents =
params.contentsType === 'T'
? params.message.sentMessageJson.translation
: params.message.sentMessageJson.original;
2020-01-01 23:44:16 +00:00
}
this.dialogService.open<MassDetailComponent, MassDetailDialogData>(
MassDetailComponent,
{
disableClose: false,
width: '550px',
data: {
title: this.translateService.instant('chat.detailView'),
contents
}
}
);
});
2020-01-01 23:44:16 +00:00
}
2019-11-07 06:46:02 +00:00
async onFileViewer(fileInfo: FileEventJson) {
2019-10-29 00:07:06 +00:00
const result = await this.dialogService.open<
2019-11-06 04:48:06 +00:00
FileViewerDialogComponent,
FileViewerDialogData,
FileViewerDialogResult
>(FileViewerDialogComponent, {
2019-10-29 00:07:06 +00:00
position: {
2019-11-22 08:35:00 +00:00
top: '50px'
2019-10-29 00:07:06 +00:00
},
maxWidth: '100vw',
maxHeight: '100vh',
2019-11-22 08:35:00 +00:00
height: 'calc(100% - 50px)',
2019-10-29 00:07:06 +00:00
width: '100%',
hasBackdrop: false,
2019-11-06 04:48:06 +00:00
panelClass: 'app-dialog-full',
data: {
fileInfo,
downloadUrl: this.sessionVerInfo.downloadUrl,
deviceType: this.environmentsInfo.deviceType,
2020-01-17 01:41:22 +00:00
token: this.loginResSubject.value.tokenString,
userSeq: this.loginResSubject.value.userSeq
}
2019-10-29 00:07:06 +00:00
});
}
/** File Save, Save As */
onSave(value: {
fileInfo: FileEventJson;
fileDownloadItem: FileDownloadItem;
type: string;
}) {
this.logger.debug('fileSave', value);
if (value.type === 'saveAs') {
2020-01-08 03:30:39 +00:00
this.nativeService
.selectSaveFilePath(value.fileInfo.fileName)
.then(result => {
if (!!result && result.length > 0) {
this.saveFile(value, result);
} else {
this.snackBarService.open(
this.translateService.instant(
'common.file.errors.failToSpecifyPath'
),
this.translateService.instant('common.file.errors.label')
);
}
})
.catch(reason => {
this.snackBarService.open(
this.translateService.instant(
'common.file.errors.failToSpecifyPath'
),
this.translateService.instant('common.file.errors.label')
);
});
} else {
this.saveFile(value);
}
}
2019-10-16 07:33:19 +00:00
2019-10-31 08:09:38 +00:00
onFileDragEnter(items: DataTransferItemList) {
this.clearView();
2019-10-31 08:09:38 +00:00
this.logger.debug('onFileDragEnter', items);
2019-10-21 04:36:58 +00:00
}
onFileDragOver() {
this.logger.debug('onFileDragOver');
}
onFileDragLeave() {
this.logger.debug('onFileDragLeave');
}
2020-01-17 01:41:22 +00:00
onExistNewMessage(info: Info<EventJson>) {
let message = '';
const senderUser = this.userInfoListSubject.value.filter(
user => user.seq === info.senderSeq
);
if (!!senderUser && senderUser.length > 0) {
message += `${senderUser[0].name} : `;
}
message += StringUtil.convertFinalEventMessage(
info.type,
info.sentMessageJson || info.sentMessage
);
this.snackBarPreviewEvent = this.snackBarService.open(
message,
this.translateService.instant('common.messages.confirm'),
{
// duration: 3000,
verticalPosition: 'bottom',
horizontalPosition: 'center',
panelClass: ['chat-snackbar-class']
}
);
this.snackBarPreviewEvent.onAction().subscribe(() => {
this.chatMessages.initEventMore();
this.chatMessages.scrollToBottom();
this.snackBarPreviewEvent.dismiss();
});
}
saveFile(
value: {
fileInfo: FileEventJson;
fileDownloadItem: FileDownloadItem;
type: string;
},
savePath?: string
) {
this.commonApiService
.fileTalkDownload({
2020-01-17 01:41:22 +00:00
userSeq: this.loginResSubject.value.userSeq,
deviceType: this.environmentsInfo.deviceType,
2020-01-17 01:41:22 +00:00
token: this.loginResSubject.value.tokenString,
attachmentsSeq: value.fileInfo.attachmentSeq,
fileDownloadItem: value.fileDownloadItem
})
.pipe(
take(1),
map(async rawBlob => {
const mimeType = MimeUtil.getMimeFromExtension(
FileUtil.getExtension(value.fileInfo.fileName)
);
const blob = rawBlob.slice(0, rawBlob.size, mimeType);
FileUtil.fromBlobToBuffer(blob)
.then(buffer => {
/** download check */
this.fileProtocolService
.downCheck({
seq: value.fileInfo.attachmentSeq
})
.pipe(take(1))
.subscribe();
this.nativeService
.saveFile(buffer, value.fileInfo.fileName, mimeType, savePath)
.then(result => {
if (!!result) {
2020-01-08 03:30:39 +00:00
this.snackBarService.open(
this.translateService.instant(
'common.file.results.savedToPath',
{
path: result
}
),
'',
{
duration: 3000,
verticalPosition: 'bottom'
}
);
} else {
this.snackBarService.openFromComponent<
AlertSnackbarComponent,
AlertSnackbarData
>(AlertSnackbarComponent, {
data: {
html: this.translateService.instant(
'common.file.errors.failToSave'
),
buttonText: this.translateService.instant(
'common.file.errors.label'
)
}
});
}
})
.catch(reason => {
this.snackBarService.openFromComponent<
AlertSnackbarComponent,
AlertSnackbarData
>(AlertSnackbarComponent, {
data: {
html: this.translateService.instant(
'common.file.errors.failToSave'
),
buttonText: this.translateService.instant(
'common.file.errors.label'
)
}
});
});
})
.catch(reason => {
this.logger.error('download', reason);
});
}),
finalize(() => {
setTimeout(() => {
value.fileDownloadItem.downloadingProgress$ = undefined;
}, 1000);
})
)
.subscribe();
}
2019-11-07 09:08:00 +00:00
async onFileSelected(fileUploadItems: FileUploadItem[]) {
2019-11-05 04:46:17 +00:00
this.logger.debug('onFileSelected', fileUploadItems);
this.clearView();
2019-11-05 04:46:17 +00:00
2019-11-05 05:55:17 +00:00
const info = {
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
roomSeq: this.roomInfoSubject.value.roomSeq
2019-11-05 05:55:17 +00:00
};
2019-11-05 04:46:17 +00:00
const allObservables: Observable<FileTalkSaveResponse>[] = [];
const fileAllowSize =
!!this.sessionVerInfo && this.sessionVerInfo.fileAllowSize
? this.sessionVerInfo.fileAllowSize
: environment.productConfig.CommonSetting.defaultFileAllowSize;
if (fileAllowSize > 0) {
if (
fileUploadItems.filter(
fui => fui.file.size > fileAllowSize * 1024 * 1024
).length
) {
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
title: '',
message: this.translateService.instant(
'common.file.errors.oversize',
{
maxSize: fileAllowSize
}
)
}
});
if (!!this.fileUploadQueue) {
this.fileUploadQueue.onUploadComplete();
}
return;
}
}
const checkExt = this.commonApiService.acceptableExtensionForFileTalk(
fileUploadItems.map(fui => FileUtil.getExtension(fui.file.name))
);
if (!checkExt.accept) {
if (!!this.fileUploadQueue) {
this.fileUploadQueue.onUploadComplete();
}
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
data: {
title: 'Alert',
html: `${this.translateService.instant(
'common.file.errors.notSupporedType'
)} ${
checkExt.reject.length > 0
? '<br/>(' + checkExt.reject.join(',') + ')'
: ''
}`
}
});
return;
}
2019-11-05 04:46:17 +00:00
for (const fileUploadItem of fileUploadItems) {
2019-11-07 09:08:00 +00:00
let thumbnail: File;
if (
-1 !==
[
'3gp',
'avi',
'm4v',
'mkv',
'mov',
'mp4',
'mpeg',
'mpg',
'rv',
'ts',
'webm',
'wmv'
2019-11-07 09:08:00 +00:00
].indexOf(FileUtil.getExtension(fileUploadItem.file.name))
) {
thumbnail = await FileUtil.thumbnail(fileUploadItem.file);
this.logger.debug('thumbnail', thumbnail);
}
2019-11-05 04:46:17 +00:00
const req: FileTalkSaveRequest = {
2020-01-17 01:41:22 +00:00
userSeq: this.loginResSubject.value.userSeq,
2019-11-05 04:46:17 +00:00
deviceType: this.environmentsInfo.deviceType,
2020-01-17 01:41:22 +00:00
token: this.loginResSubject.value.tokenString,
roomSeq: this.roomInfoSubject.value.roomSeq,
2019-11-05 04:46:17 +00:00
file: fileUploadItem.file,
fileName: fileUploadItem.file.name,
2019-11-07 09:08:00 +00:00
thumb: thumbnail,
fileUploadItem
2019-11-05 04:46:17 +00:00
};
allObservables.push(
this.commonApiService
.fileTalkSave(req, this.sessionVerInfo.uploadUrl)
.pipe(
map(res => {
if (!res) {
return;
}
if (StatusCode.Success === res.statusCode) {
return res;
} else {
throw res;
}
})
)
);
2019-10-21 04:36:58 +00:00
}
2019-11-05 04:46:17 +00:00
forkJoin(allObservables)
.pipe(take(1))
.subscribe(
resList => {
for (const res of resList) {
this.store.dispatch(
EventStore.send({
2019-11-05 05:55:17 +00:00
senderSeq: info.senderSeq,
2019-11-05 04:46:17 +00:00
req: {
2019-11-05 05:55:17 +00:00
roomSeq: info.roomSeq,
2019-11-05 04:46:17 +00:00
eventType: EventType.File,
sentMessage: res.returnJson
}
2019-11-05 04:46:17 +00:00
})
);
}
},
2019-11-05 05:55:17 +00:00
error => {
this.logger.debug('onFileSelected error', error);
2020-01-08 03:30:39 +00:00
this.snackBarService.open(
this.translateService.instant('common.file.errors.failToUpload'),
this.translateService.instant('common.file.errors.label')
);
if (!!this.fileUploadQueue) {
this.fileUploadQueue.onUploadComplete();
}
2019-11-05 05:55:17 +00:00
},
2019-11-05 04:46:17 +00:00
() => {
this.fileUploadQueue.onUploadComplete();
}
);
2019-10-21 04:36:58 +00:00
}
2019-11-06 04:48:06 +00:00
onContextMenuMessage(params: {
event: MouseEvent;
message: Info<EventJson>;
type?: string;
2019-11-06 04:48:06 +00:00
}) {
2019-10-16 07:33:19 +00:00
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,
2020-01-17 01:41:22 +00:00
loginRes: this.loginResSubject.value,
clicktype: params.type
2019-10-16 07:33:19 +00:00
};
this.messageContextMenuTrigger.openMenu();
}
async onClickMessageContextMenu(
menuType: string,
message: Info<EventJson>,
clicktype?: string
) {
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 (
2019-11-06 04:48:06 +00:00
this.clipboardService.copyFromContent(
(message as Info<string>).sentMessage
)
2019-10-16 09:05:18 +00:00
) {
this.snackBarService.open(
this.translateService.instant(
'common.clipboard.results.copied'
),
'확인'
);
2020-01-08 03:30:39 +00:00
this.snackBarService.open(
this.translateService.instant(
'common.clipboard.results.copied'
),
'',
{
duration: 3000,
verticalPosition: 'top',
horizontalPosition: 'center'
}
);
2019-10-16 09:05:18 +00:00
}
}
break;
case EventType.MassText:
{
this.commonApiService
.massTalkDownload({
2020-01-17 01:41:22 +00:00
userSeq: this.loginResSubject.value.userSeq,
2019-10-16 09:05:18 +00:00
deviceType: this.environmentsInfo.deviceType,
2020-01-17 01:41:22 +00:00
token: this.loginResSubject.value.tokenString,
eventMassSeq: message.seq
2019-10-16 09:05:18 +00:00
})
.pipe(take(1))
.subscribe(res => {
if (this.clipboardService.copyFromContent(res.content)) {
2020-01-08 03:30:39 +00:00
this.snackBarService.open(
this.translateService.instant(
'common.clipboard.results.copied'
),
'',
{
duration: 3000,
verticalPosition: 'top',
horizontalPosition: 'center'
}
);
2019-10-16 09:05:18 +00:00
}
});
}
break;
case EventType.Translation:
2020-01-14 09:26:09 +00:00
{
let trgtStr = '';
if (clicktype === 'translation') {
// translation
trgtStr = (message.sentMessageJson as TranslationEventJson)
.translation;
} else {
// original
trgtStr = (message.sentMessageJson as TranslationEventJson)
.original;
}
if (this.clipboardService.copyFromContent(trgtStr)) {
this.snackBarService.open(
this.translateService.instant(
'common.clipboard.results.copied'
),
'',
{
duration: 3000,
verticalPosition: 'top',
horizontalPosition: 'center'
}
);
}
}
break;
case EventType.MassTranslation:
{
const sentMessageJson: MassTranslationEventJson = message.sentMessageJson as MassTranslationEventJson;
this.commonApiService
.transMassTalkDownload({
2020-01-17 01:41:22 +00:00
userSeq: this.loginResSubject.value.userSeq,
deviceType: this.environmentsInfo.deviceType,
2020-01-17 01:41:22 +00:00
token: this.loginResSubject.value.tokenString,
eventTransSeq: sentMessageJson.translationSeq.toString()
})
.pipe(take(1))
.subscribe(res => {
let contents = '';
if (res.statusCode === StatusCode.Success) {
contents =
clicktype === 'translation'
? res.translation
: res.original;
} else {
contents =
clicktype === 'translation'
? sentMessageJson.translation
: sentMessageJson.original;
}
2019-10-16 09:05:18 +00:00
if (this.clipboardService.copyFromContent(contents)) {
this.snackBarService.open(
this.translateService.instant(
'common.clipboard.results.copied'
),
'',
{
duration: 3000,
verticalPosition: 'top',
horizontalPosition: 'center'
}
);
}
});
}
break;
2019-10-16 09:05:18 +00:00
default:
break;
}
2019-10-16 07:33:19 +00:00
}
break;
case 'REPLAY':
{
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
CreateChatDialogComponent,
CreateChatDialogData,
CreateChatDialogResult
>(CreateChatDialogComponent, {
width: '600px',
data: {
type: UserSelectDialogType.MessageForward,
title: this.translateService.instant('chat.forwardEventTo'),
2020-01-17 01:41:22 +00:00
ignoreRoom: [this.roomInfoSubject.value]
2020-01-08 03:30:39 +00:00
}
});
2020-01-08 03:30:39 +00:00
if (!!result && !!result.choice && result.choice) {
const userSeqs: number[] = [];
let roomSeq = '';
if (
!!result.selectedUserList &&
result.selectedUserList.length > 0
) {
result.selectedUserList.map(user => userSeqs.push(user.seq));
}
2020-01-08 03:30:39 +00:00
if (!!result.selectedRoom) {
roomSeq = result.selectedRoom.roomSeq;
}
2020-01-08 03:30:39 +00:00
if (userSeqs.length > 0 || roomSeq.trim().length > 0) {
this.store.dispatch(
EventStore.forward({
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
2020-01-08 03:30:39 +00:00
req: {
roomSeq: '-999',
eventType: message.type,
sentMessage: message.sentMessage
},
trgtUserSeqs: userSeqs,
trgtRoomSeq: roomSeq
})
);
}
}
2019-10-16 07:33:19 +00:00
}
break;
case 'REPLAY_TO_ME':
{
2020-01-17 01:41:22 +00:00
if (this.loginResSubject.value.talkWithMeBotSeq > -1) {
this.store.dispatch(
EventStore.forward({
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
req: {
roomSeq: '-999',
eventType: message.type,
sentMessage: message.sentMessage
},
2020-01-17 01:41:22 +00:00
trgtUserSeqs: [this.loginResSubject.value.talkWithMeBotSeq]
})
);
}
2019-10-16 07:33:19 +00:00
}
break;
case 'DELETE':
{
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
ConfirmDialogComponent,
ConfirmDialogData,
ConfirmDialogResult
>(ConfirmDialogComponent, {
width: '400px',
data: {
title: this.translateService.instant('chat.removeEvent'),
html: this.translateService.instant('chat.confirmRemoveEvent')
}
});
2020-01-08 03:30:39 +00:00
if (!!result && !!result.choice && result.choice) {
this.store.dispatch(
EventStore.del({
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
2020-01-08 03:30:39 +00:00
eventSeq: message.seq
})
);
}
2019-10-16 07:33:19 +00:00
}
break;
case 'RECALL':
{
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
ConfirmDialogComponent,
ConfirmDialogData,
ConfirmDialogResult
>(ConfirmDialogComponent, {
width: '400px',
data: {
title: this.translateService.instant('chat.recallEvent'),
html: this.translateService.instant('chat.confirmRecallEvent')
}
});
2020-01-08 03:30:39 +00:00
if (!!result && !!result.choice && result.choice) {
this.store.dispatch(
EventStore.cancel({
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
2020-01-08 03:30:39 +00:00
eventSeq: message.seq,
deviceType: this.environmentsInfo.deviceType
})
);
}
2019-10-16 07:33:19 +00:00
}
break;
default:
break;
}
}
2020-01-08 03:30:39 +00:00
async onClickContextMenu(menuType: string) {
switch (menuType) {
case 'OPEN_ALBUM_LIST':
{
this.store.dispatch(
ChatStore.selectedRightDrawer({
req: RightDrawer.AlbumBox
})
);
}
break;
case 'OPEN_FILE_LIST':
{
this.store.dispatch(
ChatStore.selectedRightDrawer({
req: RightDrawer.FileBox
})
);
}
break;
2019-12-23 06:23:27 +00:00
case 'CHAT_SEARCH':
{
this.onShowToggleSearchArea();
}
break;
case 'OPEN_ROOM_USER':
{
this.store.dispatch(
ChatStore.selectedRightDrawer({
req: RightDrawer.RoomUser
})
);
}
break;
2019-11-01 06:53:54 +00:00
case 'ADD_MEMBER':
{
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
CreateChatDialogComponent,
CreateChatDialogData,
CreateChatDialogResult
>(CreateChatDialogComponent, {
width: '600px',
data: {
type: UserSelectDialogType.EditChatMember,
title: this.translateService.instant('chat.modifyRoomMember'),
2020-01-17 01:41:22 +00:00
curRoomUser: this.userInfoListSubject.value.filter(
user =>
user.seq !== this.loginResSubject.value.userSeq &&
user.isJoinRoom
2020-01-08 03:30:39 +00:00
)
}
});
2019-11-01 06:53:54 +00:00
2020-01-08 03:30:39 +00:00
if (!!result && !!result.choice && result.choice) {
2020-01-16 06:41:18 +00:00
// include me here..
const userSeqs: number[] = this.userInfoListSubject.value
2020-01-16 06:41:18 +00:00
.filter(userInfo => userInfo.isJoinRoom)
.map(userInfo => userInfo.seq);
2020-01-08 03:30:39 +00:00
if (
!!result.selectedUserList &&
result.selectedUserList.length > 0
) {
result.selectedUserList.forEach(user => {
if (userSeqs.indexOf(user.seq) < 0) {
userSeqs.push(user.seq);
2020-01-07 02:36:25 +00:00
}
2020-01-08 03:30:39 +00:00
});
}
2020-01-07 02:36:25 +00:00
2020-01-08 03:30:39 +00:00
if (userSeqs.length > 0) {
// include me
2020-01-17 01:41:22 +00:00
userSeqs.push(this.loginResSubject.value.userSeq);
2020-01-07 02:36:25 +00:00
2020-01-08 03:30:39 +00:00
this.store.dispatch(
RoomStore.inviteOrOpen({
req: {
divCd: 'Invite',
userSeqs
}
})
);
}
}
2019-11-01 06:53:54 +00:00
}
break;
case 'ADD_GROUP':
{
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
SelectGroupDialogComponent,
SelectGroupDialogData,
SelectGroupDialogResult
>(SelectGroupDialogComponent, {
width: '600px',
data: {
title: this.translateService.instant('chat.addMemberToGroup')
}
});
2020-01-08 03:30:39 +00:00
if (!!result && !!result.choice && result.choice) {
if (!!result.group) {
const oldGroup: GroupDetailData = result.group;
const trgtUserSeq: number[] = [];
result.group.userSeqs.map(seq => trgtUserSeq.push(seq));
2020-01-17 01:41:22 +00:00
this.userInfoListSubject.value
2020-01-08 03:30:39 +00:00
.filter(v => result.group.userSeqs.indexOf(v.seq) < 0)
.forEach(user => {
trgtUserSeq.push(user.seq);
});
this.store.dispatch(
SyncStore.updateGroupMember({
oldGroup,
trgtUserSeq
})
);
}
}
}
break;
case 'EDIT_ROOM':
{
2020-01-08 03:30:39 +00:00
const result = await this.dialogService.open<
EditChatRoomDialogComponent,
EditChatRoomDialogData,
EditChatRoomDialogResult
>(EditChatRoomDialogComponent, {
width: '600px',
data: {
title: this.translateService.instant('chat.settingsOfRoom'),
2020-01-17 01:41:22 +00:00
roomInfo: this.roomInfoSubject.value
2020-01-08 03:30:39 +00:00
}
});
2020-01-08 03:30:39 +00:00
if (!!result && !!result.choice && result.choice) {
const roomName: string = result.roomName;
const roomNameChangeTarget: string = result.roomNameChangeTarget;
const timeRoomInterval: number = result.timeRoomInterval;
const roomInfo: RoomInfo = result.roomInfo;
2020-01-08 03:30:39 +00:00
// 방제목 업데이트.
this.store.dispatch(
RoomStore.update({
req: {
roomSeq: roomInfo.roomSeq,
roomName,
receiveAlarm: roomInfo.receiveAlarm,
syncAll:
roomNameChangeTarget.toUpperCase() === 'ALL' ? true : false
2020-01-07 02:36:25 +00:00
}
2020-01-08 03:30:39 +00:00
})
);
if (
roomInfo.isTimeRoom &&
timeRoomInterval > 0 &&
roomInfo.timeRoomInterval !== timeRoomInterval
) {
this.store.dispatch(
RoomStore.updateTimeRoomInterval({
roomSeq: roomInfo.roomSeq,
timerInterval: timeRoomInterval
})
);
}
}
}
break;
case 'CLOSE_ROOM':
{
this.store.dispatch(ChatStore.clearSelectedRoom());
}
break;
default:
break;
}
}
2019-11-08 04:35:39 +00:00
onClickOpenProfile(userSeq: number) {
2019-11-08 04:35:39 +00:00
if (
2020-01-17 01:41:22 +00:00
[
RoomType.Allim,
RoomType.Bot,
RoomType.Link,
RoomType.Allim_Elephant,
RoomType.Allim_TMS
].some(v => v === this.roomInfoSubject.value.roomType)
2019-11-08 04:35:39 +00:00
) {
this.openProfile.emit({ userSeq });
2019-11-08 04:35:39 +00:00
}
}
/** About Sticker */
onShowToggleStickerSelector() {
this.isShowStickerSelector = !this.isShowStickerSelector;
if (!this.isShowStickerSelector) {
this.selectedSticker = null;
}
}
onSelectedSticker(stickerInfo: StickerFilesInfo) {
this.selectedSticker = stickerInfo;
}
2019-11-25 06:48:43 +00:00
setStickerHistory(sticker: StickerFilesInfo) {
const history = this.localStorageService.get<string[]>(KEY_STICKER_HISTORY);
if (!!history && history.length > 0) {
const stickers: string[] = [];
[sticker.index, ...history.filter(hist => hist !== sticker.index)].map(
(s, i) => {
if (i < 10) {
stickers.push(s);
}
}
);
this.localStorageService.set<string[]>(KEY_STICKER_HISTORY, stickers);
} else {
this.localStorageService.set<string[]>(KEY_STICKER_HISTORY, [
sticker.index
]);
}
}
2019-12-15 23:58:33 +00:00
getStickerHistory(): string[] {
return this.localStorageService.get<string[]>(KEY_STICKER_HISTORY);
}
2019-12-23 06:23:27 +00:00
/** About Chat Search */
onShowToggleSearchArea() {
this.isShowSearchArea = !this.isShowSearchArea;
if (!this.isShowSearchArea) {
2020-01-17 01:41:22 +00:00
this.searchedListSubject.next([]);
2019-12-23 06:23:27 +00:00
this.searchedFocusEvent = null;
this.searchText = '';
}
}
onCloseSearchArea() {
this.isShowSearchArea = false;
2020-01-17 01:41:22 +00:00
this.searchedListSubject.next([]);
2019-12-23 06:23:27 +00:00
this.searchedFocusEvent = null;
this.searchText = '';
this.moreSearchProcessing = false;
this.searchTotalCount = 0;
this.searchCurrentIndex = 0;
this.store.dispatch(EventStore.infoForSearchEnd({}));
}
onSearchChat(searchText: string, baseSeq?: number) {
this.searchText = searchText;
2020-01-07 04:45:34 +00:00
// CASE :: searching text after retrieve All event Infos.
this.store.dispatch(
EventStore.infoAll({
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
baseSeq: this.eventListSubject.value[0].seq,
2020-01-07 04:45:34 +00:00
requestCount:
environment.productConfig.CommonSetting.eventRequestDefaultCount * 2
})
);
// this.doSearchTextInEvent(searchText);
}
doSearchTextInEvent(searchText: string, baseSeq?: number): void {
2020-01-17 01:41:22 +00:00
this.searchedListSubject.next(
this.eventListSubject.value.filter(event => {
let contents = '';
if (event.type === EventType.Character) {
contents = event.sentMessage;
} else if (
event.type === EventType.Sticker &&
!!event.sentMessageJson
) {
contents = (event.sentMessageJson as StickerEventJson).chat;
} else if (event.type === EventType.File && !!event.sentMessageJson) {
contents = (event.sentMessageJson as FileEventJson).fileName;
} else if (
event.type === EventType.MassText &&
!!event.sentMessageJson
) {
contents = (event.sentMessageJson as MassTextEventJson).content;
} else if (
(event.type === EventType.Translation ||
event.type === EventType.MassTranslation) &&
!!event.sentMessageJson
) {
contents = (event.sentMessageJson as TranslationEventJson).original;
contents += (event.sentMessageJson as TranslationEventJson)
.translation;
}
2019-12-23 06:23:27 +00:00
2020-01-17 01:41:22 +00:00
return contents.indexOf(searchText) > -1;
})
);
2019-12-23 06:23:27 +00:00
2020-01-17 01:41:22 +00:00
if (
!!this.searchedListSubject.value &&
this.searchedListSubject.value.length > 0
) {
this.searchTotalCount = this.searchedListSubject.value.length;
2019-12-23 06:23:27 +00:00
if (!!baseSeq && baseSeq > 0) {
2020-01-17 01:41:22 +00:00
this.searchedListSubject.value.forEach((searched, index) => {
2019-12-23 06:23:27 +00:00
if (searched.seq <= baseSeq) {
this.searchCurrentIndex = index + 1;
this.searchedFocusEvent = searched;
}
});
} else {
2020-01-17 01:41:22 +00:00
this.searchCurrentIndex = this.searchedListSubject.value.length;
this.searchedFocusEvent = this.searchedListSubject.value[
this.searchedListSubject.value.length - 1
2019-12-23 06:23:27 +00:00
];
}
this.store.dispatch(EventStore.infoForSearchEnd({}));
2020-01-17 01:41:22 +00:00
this.chatMessages.gotoPosition(this.searchedFocusEvent.seq);
2019-12-23 06:23:27 +00:00
} else {
this.searchTotalCount = 0;
this.searchCurrentIndex = 0;
this.searchedFocusEvent = null;
}
}
onPrevSearch() {
2020-01-17 01:41:22 +00:00
this.searchedListSubject.value.forEach((event, index) => {
2019-12-23 06:23:27 +00:00
if (event.seq === this.searchedFocusEvent.seq && index > 0) {
this.searchCurrentIndex = this.searchCurrentIndex - 1;
2020-01-17 01:41:22 +00:00
this.searchedFocusEvent = this.searchedListSubject.value[index - 1];
this.chatMessages.gotoPosition(this.searchedFocusEvent.seq);
2019-12-23 06:23:27 +00:00
}
});
}
onNextSearch() {
// let exist = false;
// this.searchedList.forEach((event, index) => {
// if (
// event.seq === this.searchedFocusEvent.seq &&
// index < this.searchedList.length - 2 &&
// !exist
// ) {
// exist = true;
// this.searchCurrentIndex = this.searchCurrentIndex + 1;
// this.searchedFocusEvent = this.searchedList[index + 1];
// this.goSearchPosition(this.searchedFocusEvent.seq);
// }
// });
2020-01-17 01:41:22 +00:00
if (this.searchCurrentIndex < this.searchedListSubject.value.length) {
this.searchedFocusEvent = this.searchedListSubject.value[
this.searchCurrentIndex
];
this.searchCurrentIndex = this.searchCurrentIndex + 1;
2020-01-17 01:41:22 +00:00
this.chatMessages.gotoPosition(this.searchedFocusEvent.seq);
}
2019-12-23 06:23:27 +00:00
}
onSearchAndPrev() {
if (
!!this.searchText &&
this.searchText.trim().length > 0 &&
2020-01-17 01:41:22 +00:00
this.eventRemainedSubject.value
2019-12-23 06:23:27 +00:00
) {
this.moreSearchProcessing = true;
this.chatMessages.storeScrollPosition();
2019-12-23 06:23:27 +00:00
2020-01-07 04:45:34 +00:00
// Case :: retrieve event infos step by step until include searchtext in event..
2019-12-23 06:23:27 +00:00
this.store.dispatch(
EventStore.infoForSearch({
req: {
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
baseSeq: this.eventListSubject.value[0].seq,
2019-12-23 06:23:27 +00:00
requestCount:
environment.productConfig.CommonSetting.eventRequestDefaultCount
},
searchText: this.searchText
})
);
}
}
2019-12-31 05:36:32 +00:00
/** About Translation */
onShowToggleTranslation() {
this.isShowTranslation = !this.isShowTranslation;
if (!this.isShowTranslation) {
}
}
onChangeTranslationSimpleView(value: boolean) {
this.translationSimpleview = value;
}
onChangeTranslationPreView(value: boolean) {
this.translationPreview = value;
}
onChangeDestLocale(destLocale: string) {
this.destLocale = destLocale;
}
onCancelTranslation() {
this.isTranslationProcess = false;
2019-12-31 05:36:32 +00:00
this.translationPreviewInfo = null;
}
2019-12-31 07:10:24 +00:00
onSendTranslationMessage(params: {
previewInfo: TranslationSaveResponse | null;
translationType: EventType.Translation | EventType.MassTranslation;
}) {
let sentMessage = '';
if (params.translationType === EventType.MassTranslation) {
// Mass Text Translation
sentMessage = params.previewInfo.returnJson;
} else {
// Normal Text Translation
sentMessage = JSON.stringify({
locale: params.previewInfo.destLocale,
original: params.previewInfo.original,
translation: params.previewInfo.translation,
stickername: '',
stickerfile: !!this.selectedSticker ? this.selectedSticker.index : ''
});
}
2019-12-31 05:36:32 +00:00
this.store.dispatch(
EventStore.send({
2020-01-17 01:41:22 +00:00
senderSeq: this.loginResSubject.value.userSeq,
2019-12-31 05:36:32 +00:00
req: {
2020-01-17 01:41:22 +00:00
roomSeq: this.roomInfoSubject.value.roomSeq,
2019-12-31 07:10:24 +00:00
eventType: params.translationType,
sentMessage
2019-12-31 05:36:32 +00:00
}
})
);
this.isTranslationProcess = false;
2019-12-31 05:36:32 +00:00
this.translationPreviewInfo = null;
}
}