2019-11-20 14:57:54 +09:00
|
|
|
import { Component, OnInit, Inject, ViewChild, OnDestroy } from '@angular/core';
|
2019-11-08 13:35:39 +09:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
2019-12-13 14:38:42 +09:00
|
|
|
import { KEY_LOGIN_RES_INFO, KEY_VER_INFO } from '@app/types';
|
2019-11-08 13:35:39 +09:00
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import * as AppStore from '@app/store';
|
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
2019-11-20 14:57:54 +09:00
|
|
|
import * as SyncStore from '@app/store/messenger/sync';
|
2019-11-29 18:24:51 +09:00
|
|
|
import * as AuthenticationStore from '@app/store/account/authentication';
|
2019-11-08 13:35:39 +09:00
|
|
|
|
2019-11-20 14:57:54 +09:00
|
|
|
import { UserInfo, GroupDetailData } from '@ucap-webmessenger/protocol-sync';
|
2019-11-08 13:35:39 +09:00
|
|
|
import {
|
|
|
|
UserInfoSS,
|
|
|
|
UserInfoF,
|
|
|
|
UserInfoDN
|
|
|
|
} from '@ucap-webmessenger/protocol-query';
|
2019-11-29 18:24:51 +09:00
|
|
|
import {
|
|
|
|
DialogService,
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogData,
|
|
|
|
ConfirmDialogResult,
|
2019-12-16 17:42:49 +09:00
|
|
|
SnackBarService,
|
|
|
|
AlertDialogComponent,
|
|
|
|
AlertDialogResult,
|
|
|
|
AlertDialogData
|
2019-11-29 18:24:51 +09:00
|
|
|
} from '@ucap-webmessenger/ui';
|
2019-11-08 13:35:39 +09:00
|
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
2019-12-17 11:44:59 +09:00
|
|
|
import { map, take, finalize, catchError } from 'rxjs/operators';
|
|
|
|
import { Subscription, of } from 'rxjs';
|
2019-11-29 18:24:51 +09:00
|
|
|
import {
|
|
|
|
SelectGroupDialogComponent,
|
|
|
|
SelectGroupDialogData,
|
|
|
|
SelectGroupDialogResult
|
|
|
|
} from '../group/select-group.dialog.component';
|
2019-12-03 18:59:11 +09:00
|
|
|
import { FileUploadItem } from '@ucap-webmessenger/api';
|
|
|
|
import { CommonApiService } from '@ucap-webmessenger/api-common';
|
2019-12-26 17:34:52 +09:00
|
|
|
import { OpenProfileOptions } from '@ucap-webmessenger/protocol-buddy';
|
2019-11-29 18:24:51 +09:00
|
|
|
import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types';
|
|
|
|
import { StatusCode } from '@ucap-webmessenger/api';
|
2019-12-11 08:18:32 +09:00
|
|
|
import {
|
|
|
|
MessageWriteDialogComponent,
|
|
|
|
MessageWriteDialogResult,
|
|
|
|
MessageWriteDialogData
|
|
|
|
} from '../message/message-write.dialog.component';
|
2019-12-16 17:42:49 +09:00
|
|
|
import {
|
|
|
|
CallService,
|
|
|
|
PromptMessageStatusCode
|
|
|
|
} from '@ucap-webmessenger/api-prompt';
|
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-12-18 09:56:00 +09:00
|
|
|
import { SmsUtils } from '@ucap-webmessenger/daesang';
|
|
|
|
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
|
2019-12-18 10:46:42 +09:00
|
|
|
import { environment } from '../../../../../environments/environment';
|
2019-11-08 13:35:39 +09:00
|
|
|
|
|
|
|
export interface ProfileDialogData {
|
|
|
|
userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN;
|
2019-12-26 17:34:52 +09:00
|
|
|
openProfileOptions?: OpenProfileOptions;
|
2019-11-08 13:35:39 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ProfileDialogResult {}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-profile.dialog',
|
|
|
|
templateUrl: './profile.dialog.component.html',
|
|
|
|
styleUrls: ['./profile.dialog.component.scss']
|
|
|
|
})
|
2019-11-20 14:57:54 +09:00
|
|
|
export class ProfileDialogComponent implements OnInit, OnDestroy {
|
2019-11-29 18:24:51 +09:00
|
|
|
userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN;
|
2019-11-08 13:35:39 +09:00
|
|
|
loginRes: LoginResponse;
|
|
|
|
sessionVerinfo: VersionInfo2Response;
|
2019-11-29 18:24:51 +09:00
|
|
|
environmentsInfo: EnvironmentsInfo;
|
|
|
|
|
2019-11-08 13:35:39 +09:00
|
|
|
isMe: boolean;
|
|
|
|
isBuddy: boolean;
|
|
|
|
isFavorit: boolean;
|
2019-12-18 10:46:42 +09:00
|
|
|
editableProfileImage: boolean;
|
2019-11-08 13:35:39 +09:00
|
|
|
|
2019-11-20 14:57:54 +09:00
|
|
|
selectAllBuddy2Subscription: Subscription;
|
|
|
|
|
2019-11-08 13:35:39 +09:00
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<ProfileDialogData, ProfileDialogResult>,
|
2019-12-18 09:56:00 +09:00
|
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
2019-11-08 13:35:39 +09:00
|
|
|
@Inject(MAT_DIALOG_DATA) public data: ProfileDialogData,
|
|
|
|
private dialogService: DialogService,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
2019-11-29 18:24:51 +09:00
|
|
|
private commonApiService: CommonApiService,
|
2019-12-16 17:42:49 +09:00
|
|
|
private callService: CallService,
|
2019-11-29 18:24:51 +09:00
|
|
|
private snackBarService: SnackBarService,
|
2019-12-16 17:42:49 +09:00
|
|
|
private store: Store<any>,
|
|
|
|
private logger: NGXLogger
|
2019-11-08 13:35:39 +09:00
|
|
|
) {
|
|
|
|
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
|
|
|
|
KEY_VER_INFO
|
|
|
|
);
|
|
|
|
this.loginRes = this.sessionStorageService.get<LoginResponse>(
|
|
|
|
KEY_LOGIN_RES_INFO
|
|
|
|
);
|
2019-11-29 18:24:51 +09:00
|
|
|
this.environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
|
|
|
|
KEY_ENVIRONMENTS_INFO
|
|
|
|
);
|
|
|
|
|
|
|
|
this.userInfo = data.userInfo;
|
2019-12-18 10:46:42 +09:00
|
|
|
|
|
|
|
this.editableProfileImage =
|
|
|
|
environment.productConfig.CommonSetting.editableProfileImage;
|
2019-11-08 13:35:39 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.isMe = this.loginRes.userSeq === this.data.userInfo.seq;
|
|
|
|
|
2019-11-20 14:57:54 +09:00
|
|
|
this.selectAllBuddy2Subscription = this.store
|
|
|
|
.pipe(
|
|
|
|
select(AppStore.MessengerSelector.SyncSelector.selectAllBuddy2),
|
|
|
|
map(buddyList => {
|
|
|
|
const users = buddyList.filter(
|
|
|
|
buddy => buddy.seq === this.data.userInfo.seq
|
|
|
|
);
|
|
|
|
this.isBuddy = users.length > 0;
|
|
|
|
if (this.isBuddy) {
|
|
|
|
this.isFavorit = users[0].isFavorit;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (!!this.selectAllBuddy2Subscription) {
|
|
|
|
this.selectAllBuddy2Subscription.unsubscribe();
|
|
|
|
}
|
2019-11-08 13:35:39 +09:00
|
|
|
}
|
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
onClickChat(userInfo: UserInfoSS) {
|
2019-11-08 13:35:39 +09:00
|
|
|
if (userInfo.seq === this.loginRes.userSeq) {
|
|
|
|
this.store.dispatch(
|
|
|
|
ChatStore.openRoom({ userSeqList: [this.loginRes.talkWithMeBotSeq] })
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.store.dispatch(ChatStore.openRoom({ userSeqList: [userInfo.seq] }));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
2019-11-20 14:57:54 +09:00
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
onClickSendMessage(userInfo: UserInfoSS) {
|
2019-12-11 08:18:32 +09:00
|
|
|
if (userInfo.seq !== this.loginRes.userSeq) {
|
|
|
|
this.dialogRef.close();
|
|
|
|
|
|
|
|
this.dialogService.open<
|
|
|
|
MessageWriteDialogComponent,
|
|
|
|
MessageWriteDialogData,
|
|
|
|
MessageWriteDialogResult
|
|
|
|
>(MessageWriteDialogComponent, {
|
|
|
|
width: '600px',
|
|
|
|
height: '600px',
|
|
|
|
disableClose: true,
|
|
|
|
hasBackdrop: false,
|
|
|
|
data: {
|
|
|
|
loginRes: this.loginRes,
|
|
|
|
environmentsInfo: this.environmentsInfo,
|
|
|
|
receiverList: [userInfo]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 17:42:49 +09:00
|
|
|
async onClickSendClickToCall(calleeNumber: string) {
|
|
|
|
const madn = this.loginRes.madn;
|
|
|
|
if (!madn || madn.trim().length === 0) {
|
|
|
|
this.dialogService.open<
|
|
|
|
AlertDialogComponent,
|
|
|
|
AlertDialogData,
|
|
|
|
AlertDialogResult
|
|
|
|
>(AlertDialogComponent, {
|
|
|
|
data: {
|
|
|
|
title: '',
|
|
|
|
html: `전화를 걸 수 없는 사용자 입니다.`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
calleeNumber = calleeNumber.replace(/\D/g, '');
|
|
|
|
|
|
|
|
if (!!calleeNumber && calleeNumber.length > 0) {
|
|
|
|
const result = await this.dialogService.open<
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogData,
|
|
|
|
ConfirmDialogResult
|
|
|
|
>(ConfirmDialogComponent, {
|
|
|
|
width: '360px',
|
|
|
|
data: {
|
|
|
|
title: '전화 걸기',
|
|
|
|
html: `${calleeNumber}로 전화를 거시겠습니까?`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!!result && !!result.choice && result.choice) {
|
|
|
|
this.callService
|
|
|
|
.sendCall({
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: this.environmentsInfo.deviceType,
|
|
|
|
tokenKey: this.loginRes.tokenString,
|
|
|
|
calleeNumber
|
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => {
|
|
|
|
if (res.responseCode === PromptMessageStatusCode.Success) {
|
|
|
|
this.logger.debug('SUCCESS');
|
|
|
|
this.logger.debug(res);
|
|
|
|
} else {
|
|
|
|
this.logger.error(res);
|
|
|
|
}
|
2019-12-17 11:44:59 +09:00
|
|
|
}),
|
|
|
|
catchError(error => of(this.logger.debug(error)))
|
2019-12-16 17:42:49 +09:00
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.dialogService.open<
|
|
|
|
AlertDialogComponent,
|
|
|
|
AlertDialogData,
|
|
|
|
AlertDialogResult
|
|
|
|
>(AlertDialogComponent, {
|
|
|
|
data: {
|
|
|
|
title: '',
|
|
|
|
html: `상대방 번호가 없어 전화를 걸 수 없습니다.`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 09:56:00 +09:00
|
|
|
onClickSendSms(calleeNumber: string) {
|
|
|
|
const smsUtil = new SmsUtils(
|
|
|
|
this.sessionStorageService,
|
|
|
|
this.nativeService
|
|
|
|
);
|
|
|
|
if (!smsUtil.getAuthSms()) {
|
|
|
|
this.dialogService.open<
|
|
|
|
AlertDialogComponent,
|
|
|
|
AlertDialogData,
|
|
|
|
AlertDialogResult
|
|
|
|
>(AlertDialogComponent, {
|
|
|
|
data: {
|
|
|
|
title: '',
|
|
|
|
html: `SMS 사용 권한이 없습니다.`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
calleeNumber = calleeNumber.replace(/\D/g, '');
|
|
|
|
if (!!calleeNumber && calleeNumber.length > 0) {
|
|
|
|
smsUtil.openSendSms(this.loginRes.tokenString, [calleeNumber]);
|
|
|
|
} else {
|
|
|
|
// this.dialogService.open<
|
|
|
|
// AlertDialogComponent,
|
|
|
|
// AlertDialogData,
|
|
|
|
// AlertDialogResult
|
|
|
|
// >(AlertDialogComponent, {
|
|
|
|
// data: {
|
|
|
|
// title: '',
|
|
|
|
// html: `상대방 번호가 없어 전화를 걸 수 없습니다.`
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
onClickToggleFavorit(param: { userInfo: UserInfoSS; isFavorit: boolean }) {
|
2019-11-20 14:57:54 +09:00
|
|
|
this.store.dispatch(
|
|
|
|
SyncStore.updateBuddy({
|
|
|
|
seq: param.userInfo.seq,
|
|
|
|
isFavorit: param.isFavorit
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
async onClickToggleBuddy(param: { userInfo: UserInfoSS; isBuddy: boolean }) {
|
2019-11-20 14:57:54 +09:00
|
|
|
if (param.isBuddy) {
|
|
|
|
// 동료추가.
|
|
|
|
const result = await this.dialogService.open<
|
|
|
|
SelectGroupDialogComponent,
|
|
|
|
SelectGroupDialogData,
|
|
|
|
SelectGroupDialogResult
|
|
|
|
>(SelectGroupDialogComponent, {
|
|
|
|
width: '600px',
|
|
|
|
data: {
|
|
|
|
title: 'Group Select'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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));
|
|
|
|
trgtUserSeq.push(param.userInfo.seq);
|
|
|
|
|
|
|
|
this.store.dispatch(
|
|
|
|
SyncStore.updateGroupMember({
|
|
|
|
oldGroup,
|
|
|
|
trgtUserSeq
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 동료삭제.
|
|
|
|
const result = await this.dialogService.open<
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogData,
|
|
|
|
ConfirmDialogResult
|
|
|
|
>(ConfirmDialogComponent, {
|
|
|
|
width: '360px',
|
|
|
|
data: {
|
|
|
|
title: 'Delete Buddy',
|
|
|
|
html: `[${param.userInfo.name} ${param.userInfo.grade}]를 그룹에서 삭제하시겠습니까?<br/>프로필에서 삭제하면 모든 그룹에서 삭제됩니다.`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!!result && !!result.choice && result.choice) {
|
|
|
|
this.store.dispatch(
|
|
|
|
SyncStore.delBuddyAndClear({ seq: param.userInfo.seq })
|
|
|
|
);
|
2019-11-29 18:24:51 +09:00
|
|
|
this.isBuddy = false;
|
2019-11-20 14:57:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 18:24:51 +09:00
|
|
|
|
|
|
|
onUploadProfileImage(profileImageFileUploadItem: FileUploadItem) {
|
|
|
|
this.commonApiService
|
|
|
|
.fileProfileSave(
|
|
|
|
{
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: this.environmentsInfo.deviceType,
|
|
|
|
token: this.loginRes.tokenString,
|
|
|
|
file: profileImageFileUploadItem.file,
|
|
|
|
fileUploadItem: profileImageFileUploadItem
|
|
|
|
},
|
|
|
|
this.sessionVerinfo.profileUploadUrl
|
|
|
|
)
|
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => {
|
|
|
|
if (!res) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (StatusCode.Success === res.statusCode) {
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
throw res;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
finalize(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
profileImageFileUploadItem.uploadingProgress$ = undefined;
|
|
|
|
}, 1000);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe(
|
|
|
|
res => {
|
|
|
|
const userInfo = {
|
|
|
|
...this.loginRes.userInfo,
|
|
|
|
profileImageFile: res.profileSubDir
|
|
|
|
};
|
|
|
|
|
|
|
|
this.store.dispatch(
|
|
|
|
AuthenticationStore.updateLoginRes({
|
|
|
|
loginRes: {
|
|
|
|
...this.loginRes,
|
|
|
|
userInfo
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
this.userInfo = userInfo as any;
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.snackBarService.open(
|
|
|
|
`프로필 이미지 변경중에 문제가 발생하였습니다.`,
|
|
|
|
'',
|
|
|
|
{
|
|
|
|
duration: 3000,
|
|
|
|
verticalPosition: 'bottom'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-11-08 13:35:39 +09:00
|
|
|
}
|