2019-12-17 11:44:59 +09:00
|
|
|
import { map, tap, take, catchError } from 'rxjs/operators';
|
2019-12-17 16:39:02 +09:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
Inject,
|
|
|
|
OnDestroy,
|
|
|
|
ViewChild,
|
2019-12-23 14:47:35 +09:00
|
|
|
ChangeDetectorRef,
|
|
|
|
NgZone
|
2019-12-17 16:39:02 +09:00
|
|
|
} from '@angular/core';
|
2019-09-27 12:53:21 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2019-09-27 12:53:21 +09:00
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
import * as AppStore from '@app/store';
|
2019-11-13 10:45:06 +09:00
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
2019-12-27 15:26:03 +09:00
|
|
|
import * as MessageStore from '@app/store/messenger/message';
|
2019-12-17 11:44:59 +09:00
|
|
|
import { Observable, Subscription, of } from 'rxjs';
|
2019-12-15 21:36:12 +09:00
|
|
|
import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native';
|
2019-11-08 13:35:39 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
import { UserInfo } from '@ucap-webmessenger/protocol-sync';
|
2019-11-08 13:35:39 +09:00
|
|
|
import {
|
|
|
|
UserInfoSS,
|
|
|
|
UserInfoF,
|
2019-12-15 21:36:12 +09:00
|
|
|
UserInfoDN,
|
|
|
|
QueryProtocolService
|
2019-11-13 10:45:06 +09:00
|
|
|
} from '@ucap-webmessenger/protocol-query';
|
|
|
|
import { StatusProtocolService } from '@ucap-webmessenger/protocol-status';
|
2019-12-23 16:47:20 +09:00
|
|
|
import { StatusType, StatusCode, DeviceType } from '@ucap-webmessenger/core';
|
2019-12-16 17:42:49 +09:00
|
|
|
import {
|
|
|
|
DialogService,
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogResult,
|
|
|
|
AlertDialogComponent,
|
|
|
|
AlertDialogResult,
|
|
|
|
AlertDialogData,
|
|
|
|
ConfirmDialogData
|
|
|
|
} from '@ucap-webmessenger/ui';
|
2019-11-08 13:35:39 +09:00
|
|
|
import {
|
|
|
|
ProfileDialogComponent,
|
|
|
|
ProfileDialogData,
|
2019-11-21 10:29:19 +09:00
|
|
|
ProfileDialogResult
|
2019-11-13 10:45:06 +09:00
|
|
|
} from '@app/layouts/messenger/dialogs/profile/profile.dialog.component';
|
2019-12-15 21:36:12 +09:00
|
|
|
import { MatDrawer } from '@angular/material';
|
2019-11-21 10:29:19 +09:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-12-15 21:36:12 +09:00
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
2019-12-26 17:34:52 +09:00
|
|
|
import { OpenProfileOptions } from '@ucap-webmessenger/protocol-buddy';
|
2019-12-18 09:56:00 +09:00
|
|
|
import { DaesangProtocolService, SmsUtils } from '@ucap-webmessenger/daesang';
|
2019-12-16 17:42:49 +09:00
|
|
|
import { CallService } from '@ucap-webmessenger/api-prompt';
|
2019-12-26 17:34:52 +09:00
|
|
|
import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types';
|
2019-12-16 17:42:49 +09:00
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
2019-12-17 16:39:02 +09:00
|
|
|
import {
|
|
|
|
MessageApiService,
|
|
|
|
MessageType,
|
2019-12-23 16:47:20 +09:00
|
|
|
DetailRequest,
|
|
|
|
MessageDetailInfo,
|
|
|
|
DelRequest
|
2019-12-17 16:39:02 +09:00
|
|
|
} from '@ucap-webmessenger/api-message';
|
|
|
|
import { MessageStatusCode } from '@ucap-webmessenger/api';
|
|
|
|
import {
|
|
|
|
MessageDetailDialogComponent,
|
|
|
|
MessageDetailDialogResult,
|
|
|
|
MessageDetailDialogData
|
|
|
|
} from '@app/layouts/messenger/dialogs/message/message-detail.dialog.component';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
@Component({
|
2019-11-13 10:45:06 +09:00
|
|
|
selector: 'app-page-messenger-main',
|
|
|
|
templateUrl: './main.page.component.html',
|
2019-11-21 10:29:19 +09:00
|
|
|
styleUrls: ['./main.page.component.scss']
|
2019-09-18 15:02:21 +09:00
|
|
|
})
|
2019-11-21 10:29:19 +09:00
|
|
|
export class MainPageComponent implements OnInit, OnDestroy {
|
2019-10-08 11:19:47 +09:00
|
|
|
selectedChat$: Observable<string | null>;
|
2019-11-11 14:31:26 +09:00
|
|
|
selectedRightDrawer$: Observable<string | null>;
|
2019-11-07 16:56:14 +09:00
|
|
|
idleStateChangedSubscription: Subscription;
|
2019-11-12 10:38:51 +09:00
|
|
|
chatOpenRoomSubscription: Subscription;
|
2019-12-17 16:39:02 +09:00
|
|
|
msgOpenMessageSubscription: Subscription;
|
2019-09-23 14:23:24 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
defaultLeftSideComponentWidth = 380;
|
|
|
|
leftSideComponentWidth = this.defaultLeftSideComponentWidth;
|
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
loginRes: LoginResponse;
|
|
|
|
loginResSubscription: Subscription;
|
2019-12-16 17:42:49 +09:00
|
|
|
environmentsInfo: EnvironmentsInfo;
|
2019-12-15 21:36:12 +09:00
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
@ViewChild('rightDrawer', { static: true }) rightDrawer: MatDrawer;
|
2019-11-11 14:31:26 +09:00
|
|
|
|
2019-11-07 16:56:14 +09:00
|
|
|
constructor(
|
|
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
|
|
|
private store: Store<any>,
|
2019-12-23 14:47:35 +09:00
|
|
|
private ngZone: NgZone,
|
2019-11-08 13:35:39 +09:00
|
|
|
private statusProtocolService: StatusProtocolService,
|
2019-12-17 16:39:02 +09:00
|
|
|
private messageApiService: MessageApiService,
|
2019-12-15 21:36:12 +09:00
|
|
|
private daesangProtocolService: DaesangProtocolService,
|
2019-12-16 17:42:49 +09:00
|
|
|
private callService: CallService,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
2019-11-21 10:29:19 +09:00
|
|
|
private dialogService: DialogService,
|
2019-12-26 17:34:52 +09:00
|
|
|
private logger: NGXLogger
|
2019-12-16 17:42:49 +09:00
|
|
|
) {
|
|
|
|
this.environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
|
|
|
|
KEY_ENVIRONMENTS_INFO
|
|
|
|
);
|
|
|
|
}
|
2019-09-19 14:15:43 +09:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2019-09-27 12:53:21 +09:00
|
|
|
this.selectedChat$ = this.store.pipe(
|
2019-12-15 21:36:12 +09:00
|
|
|
select(AppStore.MessengerSelector.ChatSelector.selectedRoom),
|
2019-11-11 14:31:26 +09:00
|
|
|
tap(selectedRoom => {
|
|
|
|
if (!selectedRoom) {
|
|
|
|
this.rightDrawer.close();
|
|
|
|
}
|
|
|
|
return selectedRoom;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
this.selectedRightDrawer$ = this.store.pipe(
|
2019-12-15 21:36:12 +09:00
|
|
|
select(AppStore.MessengerSelector.ChatSelector.selectedRightDrawer),
|
2019-11-11 14:31:26 +09:00
|
|
|
tap(selectedRightDrawer => {
|
|
|
|
if (!!selectedRightDrawer) {
|
|
|
|
this.rightDrawer.open();
|
|
|
|
} else {
|
|
|
|
this.rightDrawer.close();
|
|
|
|
}
|
|
|
|
})
|
2019-09-27 12:53:21 +09:00
|
|
|
);
|
2019-11-07 16:56:14 +09:00
|
|
|
|
|
|
|
this.idleStateChangedSubscription = this.nativeService
|
|
|
|
.idleStateChanged()
|
|
|
|
.subscribe(action => {
|
2019-11-26 17:54:37 +09:00
|
|
|
this.logger.debug(action);
|
2019-11-07 16:56:14 +09:00
|
|
|
let statusType: StatusCode;
|
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
if (action === 'IDLE') {
|
2019-11-07 16:56:14 +09:00
|
|
|
// away
|
|
|
|
statusType = StatusCode.Away;
|
|
|
|
} else {
|
|
|
|
// online
|
|
|
|
statusType = StatusCode.OnLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statusProtocolService.status({
|
|
|
|
statusDivisionType: StatusType.Messenger,
|
|
|
|
statusType,
|
2019-11-21 10:29:19 +09:00
|
|
|
statusMessage: ''
|
2019-11-07 16:56:14 +09:00
|
|
|
});
|
|
|
|
});
|
2019-11-12 10:38:51 +09:00
|
|
|
|
|
|
|
this.chatOpenRoomSubscription = this.nativeService
|
|
|
|
.chatOpenRoom()
|
|
|
|
.subscribe(roomSeq => {
|
|
|
|
this.store.dispatch(ChatStore.selectedRoom({ roomSeq }));
|
|
|
|
});
|
2019-12-15 21:36:12 +09:00
|
|
|
|
2019-12-17 16:39:02 +09:00
|
|
|
this.msgOpenMessageSubscription = this.nativeService
|
|
|
|
.msgOpenMessage()
|
|
|
|
.subscribe(messageSeq => {
|
2019-12-27 15:26:03 +09:00
|
|
|
// unreadCount refresh..
|
|
|
|
this.store.dispatch(MessageStore.retrieveUnreadCount({}));
|
2019-12-17 16:39:02 +09:00
|
|
|
|
2019-12-23 14:47:35 +09:00
|
|
|
this.ngZone.run(() => {
|
2019-12-27 15:26:03 +09:00
|
|
|
/**
|
|
|
|
* 쪽지 상세보기.
|
|
|
|
* state 를 구독하여 Message.component.ts 에서 팝업 띄움.
|
|
|
|
*/
|
|
|
|
this.store.dispatch(
|
|
|
|
MessageStore.detailMessage({
|
|
|
|
messageType: MessageType.Receive,
|
2019-12-23 14:47:35 +09:00
|
|
|
msgId: Number(messageSeq)
|
2019-12-27 15:26:03 +09:00
|
|
|
})
|
|
|
|
);
|
2019-12-23 14:47:35 +09:00
|
|
|
});
|
2019-12-17 16:39:02 +09:00
|
|
|
});
|
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
this.loginResSubscription = this.store
|
|
|
|
.pipe(
|
|
|
|
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
|
|
|
|
tap(loginRes => {
|
|
|
|
this.loginRes = loginRes;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-11-07 16:56:14 +09:00
|
|
|
}
|
|
|
|
|
2019-11-21 10:29:19 +09:00
|
|
|
ngOnDestroy(): void {
|
2019-11-07 16:56:14 +09:00
|
|
|
if (!!this.idleStateChangedSubscription) {
|
|
|
|
this.idleStateChangedSubscription.unsubscribe();
|
|
|
|
}
|
2019-11-12 10:38:51 +09:00
|
|
|
|
|
|
|
if (!!this.chatOpenRoomSubscription) {
|
|
|
|
this.chatOpenRoomSubscription.unsubscribe();
|
|
|
|
}
|
2019-11-21 10:29:19 +09:00
|
|
|
|
2019-12-15 21:36:12 +09:00
|
|
|
if (!!this.loginResSubscription) {
|
|
|
|
this.loginResSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-11-21 10:29:19 +09:00
|
|
|
this.logger.debug('-----------------------MainPageComponent ngOnDestroy');
|
2019-09-19 14:15:43 +09:00
|
|
|
}
|
2019-11-08 13:35:39 +09:00
|
|
|
|
2019-11-11 14:31:26 +09:00
|
|
|
onOpenedChange(event: boolean) {
|
|
|
|
if (!event) {
|
|
|
|
this.store.dispatch(
|
|
|
|
ChatStore.selectedRightDrawer({
|
2019-11-21 10:29:19 +09:00
|
|
|
req: null
|
2019-11-11 14:31:26 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 10:45:06 +09:00
|
|
|
onGutterDragEnd(e: { gutterNum: number; sizes: Array<number> }) {
|
|
|
|
this.leftSideComponentWidth = e.sizes[0];
|
|
|
|
}
|
|
|
|
onGutterDblClick(e: { gutterNum: number; sizes: Array<number> }) {
|
|
|
|
this.leftSideComponentWidth = this.defaultLeftSideComponentWidth;
|
|
|
|
}
|
|
|
|
|
2019-12-26 17:34:52 +09:00
|
|
|
onClickOpenProfile(params: {
|
|
|
|
userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN;
|
|
|
|
openProfileOptions?: OpenProfileOptions;
|
|
|
|
}) {
|
2019-12-15 21:36:12 +09:00
|
|
|
// [GROUP]
|
|
|
|
// this.queryProtocolService
|
|
|
|
// .dataUser({
|
|
|
|
// divCd: 'OPENPROF',
|
|
|
|
// seq: userInfo.seq,
|
|
|
|
// senderCompanyCode: this.loginRes.userInfo.companyCode,
|
|
|
|
// senderEmployeeType: this.loginRes.userInfo.employeeType
|
|
|
|
// })
|
|
|
|
// .pipe(
|
|
|
|
// take(1),
|
|
|
|
// map(res => {
|
|
|
|
// if (!!res && !!res.userInfo) {
|
|
|
|
// this.dialogService.open<
|
|
|
|
// ProfileDialogComponent,
|
|
|
|
// ProfileDialogData,
|
|
|
|
// ProfileDialogResult
|
|
|
|
// >(ProfileDialogComponent, {
|
|
|
|
// data: {
|
|
|
|
// userInfo: res.userInfo
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// )
|
|
|
|
// .subscribe();
|
|
|
|
|
|
|
|
// [Daesang]
|
|
|
|
this.daesangProtocolService
|
|
|
|
.dataUserDaesang({
|
|
|
|
divCd: 'OPENPROF',
|
2019-12-26 17:34:52 +09:00
|
|
|
seq: params.userInfo.seq,
|
2019-12-15 21:36:12 +09:00
|
|
|
senderCompanyCode: this.loginRes.userInfo.companyCode,
|
|
|
|
senderEmployeeType: this.loginRes.userInfo.employeeType
|
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => {
|
|
|
|
if (!!res && !!res.userInfo) {
|
|
|
|
this.dialogService.open<
|
|
|
|
ProfileDialogComponent,
|
|
|
|
ProfileDialogData,
|
|
|
|
ProfileDialogResult
|
|
|
|
>(ProfileDialogComponent, {
|
|
|
|
data: {
|
2019-12-26 17:34:52 +09:00
|
|
|
userInfo: res.userInfo,
|
|
|
|
openProfileOptions: params.openProfileOptions
|
2019-12-15 21:36:12 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-11-08 13:35:39 +09:00
|
|
|
}
|
2019-11-13 11:06:13 +09:00
|
|
|
|
2019-12-18 09:56:00 +09:00
|
|
|
async sendClickToCall(calleeNumber: string) {
|
2019-12-16 17:42:49 +09:00
|
|
|
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 => {
|
|
|
|
console.log(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
|
|
|
openSms(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, '');
|
|
|
|
smsUtil.openSendSms(this.loginRes.tokenString, [calleeNumber]);
|
|
|
|
}
|
|
|
|
|
2019-11-13 11:06:13 +09:00
|
|
|
onCloseRightDrawer() {
|
|
|
|
this.rightDrawer.close();
|
|
|
|
}
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|