leejinho dbf62d321b 1. 알림 버그 수정 :: 알림, 소리, 알림+소리 변경시 소리 안나는 버그 수정.
2. 소리로 설정시 알림 안뜨고 소리만 날 수 있도록 수정.
3. 쪽지 수신시 자동 팝업 오픈 기능 추가.
2020-01-02 10:29:21 +09:00

360 lines
10 KiB
TypeScript

import { map, tap, take, catchError } from 'rxjs/operators';
import {
Component,
OnInit,
Inject,
OnDestroy,
ViewChild,
NgZone
} from '@angular/core';
import { Store, select } from '@ngrx/store';
import * as AppStore from '@app/store';
import * as ChatStore from '@app/store/messenger/chat';
import * as MessageStore from '@app/store/messenger/message';
import { Observable, Subscription, of } from 'rxjs';
import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native';
import { UserInfo } from '@ucap-webmessenger/protocol-sync';
import {
UserInfoSS,
UserInfoF,
UserInfoDN
} 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';
import {
ProfileDialogComponent,
ProfileDialogData,
ProfileDialogResult
} from '@app/layouts/messenger/dialogs/profile/profile.dialog.component';
import { MatDrawer } from '@angular/material';
import { NGXLogger } from 'ngx-logger';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
import { OpenProfileOptions } from '@ucap-webmessenger/protocol-buddy';
import { DaesangProtocolService, SmsUtils } from '@ucap-webmessenger/daesang';
import { CallService } from '@ucap-webmessenger/api-prompt';
import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types';
import {
SessionStorageService,
LocalStorageService
} from '@ucap-webmessenger/web-storage';
import { MessageType } from '@ucap-webmessenger/api-message';
import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type';
import { environment } from '../../../../environments/environment';
@Component({
selector: 'app-page-messenger-main',
templateUrl: './main.page.component.html',
styleUrls: ['./main.page.component.scss']
})
export class MainPageComponent implements OnInit, OnDestroy {
selectedChat$: Observable<string | null>;
selectedRightDrawer$: Observable<string | null>;
idleStateChangedSubscription: Subscription;
chatOpenRoomSubscription: Subscription;
msgOpenMessageSubscription: Subscription;
defaultLeftSideComponentWidth = 380;
leftSideComponentWidth = this.defaultLeftSideComponentWidth;
loginRes: LoginResponse;
loginResSubscription: Subscription;
environmentsInfo: EnvironmentsInfo;
@ViewChild('rightDrawer', { static: true }) rightDrawer: MatDrawer;
constructor(
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private store: Store<any>,
private ngZone: NgZone,
private statusProtocolService: StatusProtocolService,
private daesangProtocolService: DaesangProtocolService,
private callService: CallService,
private localStorageService: LocalStorageService,
private sessionStorageService: SessionStorageService,
private dialogService: DialogService,
private logger: NGXLogger
) {
this.environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
KEY_ENVIRONMENTS_INFO
);
}
ngOnInit(): void {
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();
}
})
);
this.idleStateChangedSubscription = this.nativeService
.idleStateChanged()
.subscribe(action => {
this.logger.debug(action);
let statusType: StatusCode;
if (action === 'IDLE') {
// away
statusType = StatusCode.Away;
} else {
// online
statusType = StatusCode.OnLine;
}
this.statusProtocolService.status({
statusDivisionType: StatusType.Messenger,
statusType,
statusMessage: ''
});
});
this.chatOpenRoomSubscription = this.nativeService
.chatOpenRoom()
.subscribe(roomSeq => {
this.store.dispatch(ChatStore.selectedRoom({ roomSeq }));
});
this.msgOpenMessageSubscription = this.nativeService
.msgOpenMessage()
.subscribe(messageSeq => {
const appUserInfo = this.localStorageService.encGet<AppUserInfo>(
KEY_APP_USER_INFO,
environment.customConfig.appKey
);
// direct open detail
if (!appUserInfo.settings.notification.receiveForMessage) {
// unreadCount refresh..
this.store.dispatch(MessageStore.retrieveUnreadCount({}));
this.ngZone.run(() => {
/**
* 쪽지 상세보기.
* state 를 구독하여 Message.component.ts 에서 팝업 띄움.
*/
this.store.dispatch(
MessageStore.detailMessage({
messageType: MessageType.Receive,
msgId: Number(messageSeq)
})
);
});
}
});
this.loginResSubscription = this.store
.pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
tap(loginRes => {
this.loginRes = loginRes;
})
)
.subscribe();
}
ngOnDestroy(): void {
if (!!this.idleStateChangedSubscription) {
this.idleStateChangedSubscription.unsubscribe();
}
if (!!this.chatOpenRoomSubscription) {
this.chatOpenRoomSubscription.unsubscribe();
}
if (!!this.loginResSubscription) {
this.loginResSubscription.unsubscribe();
}
this.logger.debug('-----------------------MainPageComponent ngOnDestroy');
}
onOpenedChange(event: boolean) {
if (!event) {
this.store.dispatch(
ChatStore.selectedRightDrawer({
req: null
})
);
}
}
onGutterDragEnd(e: { gutterNum: number; sizes: Array<number> }) {
this.leftSideComponentWidth = e.sizes[0];
}
onGutterDblClick(e: { gutterNum: number; sizes: Array<number> }) {
this.leftSideComponentWidth = this.defaultLeftSideComponentWidth;
}
onClickOpenProfile(params: {
userInfo: UserInfo | UserInfoSS | UserInfoF | UserInfoDN;
openProfileOptions?: OpenProfileOptions;
}) {
// [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: params.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,
openProfileOptions: params.openProfileOptions
}
});
}
})
)
.subscribe();
}
async sendClickToCall(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);
}),
catchError(error => of(this.logger.debug(error)))
)
.subscribe();
}
} else {
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
data: {
title: '',
html: `상대방 번호가 없어 전화를 걸 수 없습니다.`
}
});
}
}
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]);
}
onCloseRightDrawer() {
this.rightDrawer.close();
}
}