349 lines
10 KiB
TypeScript
Raw Normal View History

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,
ChangeDetectorRef
} 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
import * as AppStore from '@app/store';
2019-11-13 10:45:06 +09:00
import * as ChatStore from '@app/store/messenger/chat';
2019-12-17 11:44:59 +09:00
import { Observable, Subscription, of } from 'rxjs';
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,
UserInfoDN,
QueryProtocolService
2019-11-13 10:45:06 +09:00
} from '@ucap-webmessenger/protocol-query';
import { StatusProtocolService } from '@ucap-webmessenger/protocol-status';
import { StatusType, StatusCode } from '@ucap-webmessenger/core';
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';
import { MatDrawer } from '@angular/material';
2019-11-21 10:29:19 +09:00
import { NGXLogger } from 'ngx-logger';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
import { DaesangProtocolService } from '@ucap-webmessenger/daesang';
import { CallService } from '@ucap-webmessenger/api-prompt';
import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
2019-12-17 16:39:02 +09:00
import {
MessageApiService,
MessageType,
DetailRequest
} 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>;
selectedRightDrawer$: Observable<string | null>;
idleStateChangedSubscription: Subscription;
chatOpenRoomSubscription: Subscription;
2019-12-17 16:39:02 +09:00
msgOpenMessageSubscription: Subscription;
2019-11-13 10:45:06 +09:00
defaultLeftSideComponentWidth = 380;
leftSideComponentWidth = this.defaultLeftSideComponentWidth;
loginRes: LoginResponse;
loginResSubscription: Subscription;
environmentsInfo: EnvironmentsInfo;
2019-11-13 10:45:06 +09:00
@ViewChild('rightDrawer', { static: true }) rightDrawer: MatDrawer;
constructor(
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private store: Store<any>,
2019-11-08 13:35:39 +09:00
private statusProtocolService: StatusProtocolService,
2019-12-17 16:39:02 +09:00
private messageApiService: MessageApiService,
private daesangProtocolService: DaesangProtocolService,
private callService: CallService,
private sessionStorageService: SessionStorageService,
2019-11-21 10:29:19 +09:00
private dialogService: DialogService,
2019-12-17 16:39:02 +09:00
private logger: NGXLogger,
private changeDetectorRef: ChangeDetectorRef
) {
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(
select(AppStore.MessengerSelector.ChatSelector.selectedRoom),
tap(selectedRoom => {
if (!selectedRoom) {
this.rightDrawer.close();
}
return selectedRoom;
})
);
this.selectedRightDrawer$ = this.store.pipe(
select(AppStore.MessengerSelector.ChatSelector.selectedRightDrawer),
tap(selectedRightDrawer => {
if (!!selectedRightDrawer) {
this.rightDrawer.open();
} else {
this.rightDrawer.close();
}
})
2019-09-27 12:53:21 +09:00
);
this.idleStateChangedSubscription = this.nativeService
.idleStateChanged()
.subscribe(action => {
2019-11-26 17:54:37 +09:00
this.logger.debug(action);
let statusType: StatusCode;
2019-11-13 10:45:06 +09:00
if (action === 'IDLE') {
// 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: ''
});
});
this.chatOpenRoomSubscription = this.nativeService
.chatOpenRoom()
.subscribe(roomSeq => {
this.store.dispatch(ChatStore.selectedRoom({ roomSeq }));
});
2019-12-17 16:39:02 +09:00
this.msgOpenMessageSubscription = this.nativeService
.msgOpenMessage()
.subscribe(messageSeq => {
console.log(messageSeq);
// this.messageApiService
// .detailMessage({
// userSeq: this.loginRes.userSeq,
// deviceType: this.environmentsInfo.deviceType,
// tokenKey: this.loginRes.tokenString,
// type: MessageType.Receive,
// msgId: Number(messageSeq)
// } as DetailRequest)
// .pipe(
// take(1),
// map(res => {
// if (res.responseCode === MessageStatusCode.Success) {
// // detail view..
// this.dialogService.open<
// MessageDetailDialogComponent,
// MessageDetailDialogData,
// MessageDetailDialogResult
// >(MessageDetailDialogComponent, {
// width: '600px',
// data: {
// detail: res,
// loginRes: this.loginRes,
// environmentsInfo: this.environmentsInfo
// }
// });
// // this.changeDetectorRef.detectChanges();
// } else {
// }
// }),
// catchError(error => of(this.logger.error(error)))
// )
// .subscribe();
});
this.loginResSubscription = this.store
.pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
tap(loginRes => {
this.loginRes = loginRes;
})
)
.subscribe();
}
2019-11-21 10:29:19 +09:00
ngOnDestroy(): void {
if (!!this.idleStateChangedSubscription) {
this.idleStateChangedSubscription.unsubscribe();
}
if (!!this.chatOpenRoomSubscription) {
this.chatOpenRoomSubscription.unsubscribe();
}
2019-11-21 10:29:19 +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
onOpenedChange(event: boolean) {
if (!event) {
this.store.dispatch(
ChatStore.selectedRightDrawer({
2019-11-21 10:29:19 +09:00
req: null
})
);
}
}
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-11-08 13:35:39 +09:00
onClickOpenProfile(userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN) {
// [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',
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();
2019-11-08 13:35:39 +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 => {
console.log(res);
2019-12-17 11:44:59 +09:00
}),
catchError(error => of(this.logger.debug(error)))
)
.subscribe();
}
} else {
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
data: {
title: '',
html: `상대방 번호가 없어 전화를 걸 수 없습니다.`
}
});
}
}
onCloseRightDrawer() {
this.rightDrawer.close();
}
2019-09-18 15:02:21 +09:00
}