2019-12-03 18:59:11 +09:00
|
|
|
import { Component, OnInit, Inject, ViewChild } from '@angular/core';
|
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
|
|
|
|
|
|
|
import { DialogService, SnackBarService } from '@ucap-webmessenger/ui';
|
|
|
|
|
|
|
|
import {
|
|
|
|
DetailResponse,
|
|
|
|
DetailContent,
|
2019-12-11 08:18:32 +09:00
|
|
|
MessageApiService,
|
2019-12-12 15:11:49 +09:00
|
|
|
MessageType
|
2019-12-03 18:59:11 +09:00
|
|
|
} from '@ucap-webmessenger/api-message';
|
|
|
|
|
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-12-04 17:58:59 +09:00
|
|
|
import {
|
|
|
|
WriteComponent as UCapMessageWriteComponent,
|
2019-12-12 15:11:49 +09:00
|
|
|
Message,
|
|
|
|
MessageModify
|
2019-12-04 17:58:59 +09:00
|
|
|
} from '@ucap-webmessenger/ui-message';
|
|
|
|
import { UserInfo } from '@ucap-webmessenger/protocol-sync';
|
|
|
|
import {
|
|
|
|
CreateChatDialogComponent,
|
|
|
|
CreateChatDialogData,
|
|
|
|
CreateChatDialogResult
|
|
|
|
} from '../chat/create-chat.dialog.component';
|
2020-01-09 18:14:00 +09:00
|
|
|
import {
|
|
|
|
UserSelectDialogType,
|
|
|
|
EnvironmentsInfo,
|
|
|
|
KEY_VER_INFO
|
|
|
|
} from '@app/types';
|
2019-12-04 17:58:59 +09:00
|
|
|
import { take } from 'rxjs/operators';
|
2019-12-15 21:36:12 +09:00
|
|
|
import { UserInfoSS } from '@ucap-webmessenger/protocol-query';
|
2020-01-08 12:30:39 +09:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2020-01-09 18:14:00 +09:00
|
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { environment } from '../../../../../environments/environment';
|
2019-12-03 18:59:11 +09:00
|
|
|
|
|
|
|
export interface MessageWriteDialogData {
|
|
|
|
loginRes: LoginResponse;
|
2019-12-04 17:58:59 +09:00
|
|
|
environmentsInfo: EnvironmentsInfo;
|
2019-12-03 18:59:11 +09:00
|
|
|
detail?: DetailResponse;
|
2019-12-12 15:11:49 +09:00
|
|
|
detailContents?: string;
|
2019-12-15 21:36:12 +09:00
|
|
|
receiverList?: (UserInfo | UserInfoSS)[];
|
2019-12-03 18:59:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line: no-empty-interface
|
2019-12-12 15:11:49 +09:00
|
|
|
export interface MessageWriteDialogResult {
|
|
|
|
sendFlag: boolean;
|
|
|
|
sendType?: MessageType;
|
|
|
|
}
|
2019-12-03 18:59:11 +09:00
|
|
|
|
|
|
|
export interface DownloadQueueForMessage extends DetailContent {
|
|
|
|
downloadType: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-layout-messenger-message-write',
|
|
|
|
templateUrl: './message-write.dialog.component.html',
|
|
|
|
styleUrls: ['./message-write.dialog.component.scss']
|
|
|
|
})
|
|
|
|
export class MessageWriteDialogComponent implements OnInit {
|
|
|
|
@ViewChild('messageWrite', { static: true })
|
|
|
|
messageWrite: UCapMessageWriteComponent;
|
|
|
|
|
2020-01-09 18:14:00 +09:00
|
|
|
sessionVerInfo: VersionInfo2Response;
|
|
|
|
|
|
|
|
fileAllowSize: number;
|
|
|
|
|
2019-12-12 15:11:49 +09:00
|
|
|
isModify = false;
|
|
|
|
|
2019-12-03 18:59:11 +09:00
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<
|
|
|
|
MessageWriteDialogData,
|
|
|
|
MessageWriteDialogResult
|
|
|
|
>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: MessageWriteDialogData,
|
|
|
|
private messageApiService: MessageApiService,
|
|
|
|
private snackBarService: SnackBarService,
|
2020-01-08 12:30:39 +09:00
|
|
|
private translateService: TranslateService,
|
2020-01-09 18:14:00 +09:00
|
|
|
private sessionStorageService: SessionStorageService,
|
2019-12-03 18:59:11 +09:00
|
|
|
private logger: NGXLogger,
|
|
|
|
private dialogService: DialogService
|
|
|
|
) {}
|
|
|
|
|
2019-12-12 15:11:49 +09:00
|
|
|
ngOnInit(): void {
|
2020-01-09 18:14:00 +09:00
|
|
|
this.sessionVerInfo = this.sessionStorageService.get<VersionInfo2Response>(
|
|
|
|
KEY_VER_INFO
|
|
|
|
);
|
|
|
|
|
|
|
|
this.fileAllowSize =
|
|
|
|
!!this.sessionVerInfo && this.sessionVerInfo.fileAllowSize
|
|
|
|
? this.sessionVerInfo.fileAllowSize
|
|
|
|
: environment.productConfig.CommonSetting.defaultFileAllowSize;
|
|
|
|
|
2019-12-12 15:11:49 +09:00
|
|
|
if (!!this.data.detail && !!this.data.detail.msgInfo) {
|
|
|
|
this.isModify = true;
|
|
|
|
}
|
|
|
|
}
|
2019-12-03 18:59:11 +09:00
|
|
|
|
2019-12-04 17:58:59 +09:00
|
|
|
async onSelectReceiver(receiverList: UserInfo[]) {
|
|
|
|
const result = await this.dialogService.open<
|
|
|
|
CreateChatDialogComponent,
|
|
|
|
CreateChatDialogData,
|
|
|
|
CreateChatDialogResult
|
|
|
|
>(CreateChatDialogComponent, {
|
|
|
|
width: '600px',
|
|
|
|
data: {
|
|
|
|
type: UserSelectDialogType.EditChatMember,
|
2020-01-08 12:30:39 +09:00
|
|
|
title: this.translateService.instant('message.selectRecipient'),
|
2019-12-04 17:58:59 +09:00
|
|
|
curRoomUser: receiverList
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!!result && !!result.choice && result.choice) {
|
|
|
|
while (receiverList.length) {
|
|
|
|
receiverList.pop();
|
|
|
|
}
|
|
|
|
result.selectedUserList.forEach(v => {
|
|
|
|
receiverList.push(v as UserInfo);
|
|
|
|
});
|
|
|
|
}
|
2019-12-03 18:59:11 +09:00
|
|
|
}
|
|
|
|
|
2019-12-12 15:11:49 +09:00
|
|
|
onSend(message: Message | MessageModify) {
|
|
|
|
if (this.isModify) {
|
|
|
|
this.onModifySend(message as MessageModify);
|
|
|
|
} else {
|
|
|
|
this.onNewSend(message as Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onNewSend(message: Message) {
|
2019-12-04 17:58:59 +09:00
|
|
|
this.messageApiService
|
|
|
|
.sendMessage({
|
|
|
|
...message,
|
|
|
|
userSeq: this.data.loginRes.userInfo.seq,
|
|
|
|
userName: this.data.loginRes.userInfo.name,
|
|
|
|
deviceType: this.data.environmentsInfo.deviceType,
|
|
|
|
tokenKey: this.data.loginRes.tokenString,
|
|
|
|
titleYn: '' !== message.title ? true : false
|
|
|
|
})
|
|
|
|
.pipe(take(1))
|
|
|
|
.subscribe(
|
|
|
|
res => {
|
2019-12-06 17:53:19 +09:00
|
|
|
let msg = '';
|
|
|
|
if (!!message.reservationTime) {
|
2020-01-08 12:30:39 +09:00
|
|
|
msg = this.translateService.instant(
|
|
|
|
'message.results.successForReservation'
|
|
|
|
);
|
2019-12-06 17:53:19 +09:00
|
|
|
} else {
|
2020-01-08 12:30:39 +09:00
|
|
|
msg = this.translateService.instant(
|
|
|
|
'message.results.successForSending'
|
|
|
|
);
|
2019-12-06 17:53:19 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this.snackBarService.open(msg, '', {
|
|
|
|
duration: 3000,
|
|
|
|
verticalPosition: 'bottom'
|
|
|
|
});
|
|
|
|
|
2019-12-12 15:11:49 +09:00
|
|
|
this.dialogRef.close({ sendFlag: true, sendType: message.type });
|
2019-12-04 17:58:59 +09:00
|
|
|
},
|
|
|
|
error => {
|
2020-01-08 12:30:39 +09:00
|
|
|
this.snackBarService.open(
|
|
|
|
this.translateService.instant('message.errors.failToSending'),
|
|
|
|
'',
|
|
|
|
{
|
|
|
|
duration: 3000,
|
|
|
|
verticalPosition: 'bottom'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-11 08:18:32 +09:00
|
|
|
// this.dialogRef.close({});
|
2019-12-04 17:58:59 +09:00
|
|
|
}
|
|
|
|
);
|
2019-12-03 18:59:11 +09:00
|
|
|
}
|
2019-12-12 15:11:49 +09:00
|
|
|
onModifySend(message: MessageModify) {
|
|
|
|
this.messageApiService
|
|
|
|
.editReservationMessageEx({
|
|
|
|
...message,
|
|
|
|
userSeq: this.data.loginRes.userInfo.seq,
|
|
|
|
deviceType: this.data.environmentsInfo.deviceType,
|
|
|
|
tokenKey: this.data.loginRes.tokenString,
|
|
|
|
titleYn: '' !== message.title ? true : false
|
|
|
|
})
|
|
|
|
.pipe(take(1))
|
|
|
|
.subscribe(
|
|
|
|
res => {
|
2020-01-08 12:30:39 +09:00
|
|
|
this.snackBarService.open(
|
|
|
|
this.translateService.instant(
|
|
|
|
'message.results.successForModifying'
|
|
|
|
),
|
|
|
|
'',
|
|
|
|
{
|
|
|
|
duration: 3000,
|
|
|
|
verticalPosition: 'bottom'
|
|
|
|
}
|
|
|
|
);
|
2019-12-12 15:11:49 +09:00
|
|
|
|
|
|
|
this.dialogRef.close({ sendFlag: true, sendType: message.type });
|
|
|
|
},
|
|
|
|
error => {
|
2020-01-08 12:30:39 +09:00
|
|
|
this.snackBarService.open(
|
|
|
|
this.translateService.instant('message.errors.failToModify'),
|
|
|
|
'',
|
|
|
|
{
|
|
|
|
duration: 3000,
|
|
|
|
verticalPosition: 'bottom'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-12 15:11:49 +09:00
|
|
|
// this.dialogRef.close({});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-12-03 18:59:11 +09:00
|
|
|
|
2019-12-06 17:53:19 +09:00
|
|
|
onCancel() {
|
2019-12-12 15:11:49 +09:00
|
|
|
this.dialogRef.close({ sendFlag: false });
|
2019-12-06 17:53:19 +09:00
|
|
|
}
|
|
|
|
|
2019-12-04 17:58:59 +09:00
|
|
|
getBtnValid() {
|
|
|
|
return true;
|
2019-12-03 18:59:11 +09:00
|
|
|
}
|
|
|
|
}
|