From 23ae97caab8ab887c42fcc4b691540d59b53c641 Mon Sep 17 00:00:00 2001 From: leejinho Date: Mon, 23 Mar 2020 16:34:27 +0900 Subject: [PATCH] =?UTF-8?q?noti=20popup=20=EC=97=90=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=ED=91=9C=EC=8B=9C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/services/notification.service.ts | 382 +++++++++++------- .../src/assets/i18n/en.json | 2 + .../src/assets/i18n/ko.json | 2 + .../src/lib/protocols/user-seq.ts | 4 +- 4 files changed, 252 insertions(+), 138 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts index a802dfe1..335b1586 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -1,7 +1,6 @@ -import { delGroupSuccess, buddy2 } from './../store/messenger/sync/actions'; import { Injectable, Inject } from '@angular/core'; -import { tap, withLatestFrom, take } from 'rxjs/operators'; +import { tap, withLatestFrom } from 'rxjs/operators'; import { Store, select } from '@ngrx/store'; @@ -95,7 +94,11 @@ import { NotificationType, WindowState } from '@ucap-webmessenger/native'; -import { StringUtil, DialogService } from '@ucap-webmessenger/ui'; +import { + StringUtil, + DialogService, + TranslateService as UcapTranslateService +} from '@ucap-webmessenger/ui'; import { UmgProtocolService, SSVC_TYPE_UMG_NOTI, @@ -110,10 +113,10 @@ import { import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type'; import { environment } from '../../environments/environment'; -import { NotificationMethod } from '@ucap-webmessenger/core'; +import { NotificationMethod, LocaleCode } from '@ucap-webmessenger/core'; import { Dictionary } from '@ngrx/entity'; import { MessageType } from '@ucap-webmessenger/api-message'; -import { LogoutInfo, KEY_LOGOUT_INFO } from '@app/types'; +import { LogoutInfo, KEY_LOGOUT_INFO, KEY_VER_INFO } from '@app/types'; import { TranslateService } from '@ngx-translate/core'; import { deleteMessageSuccess } from '@app/store/messenger/message'; import { ServerErrorCode } from '@ucap-webmessenger/protocol'; @@ -131,6 +134,10 @@ import { } from '@ucap-webmessenger/ui-settings'; import clone from 'clone'; import { ElectronBrowserWindowChannel } from '@ucap-webmessenger/electron-core'; +import { UserInfo, RoomUserData } from '@ucap-webmessenger/protocol-sync'; +import { VersionInfo2Response } from '@ucap-webmessenger/api-public'; +import { QueryProtocolService } from '@ucap-webmessenger/protocol-query'; +import { UserInfoListState } from '@app/store/messenger/room'; @Injectable() export class AppNotificationService { @@ -141,8 +148,10 @@ export class AppNotificationService { private roomProtocolService: RoomProtocolService, private groupProtocolService: GroupProtocolService, private buddyProtocolService: BuddyProtocolService, + private queryProtocolService: QueryProtocolService, private statusProtocolService: StatusProtocolService, private translateService: TranslateService, + private ucapTranslateService: UcapTranslateService, private optionProtocolService: OptionProtocolService, private umgProtocolService: UmgProtocolService, private localStorageService: LocalStorageService, @@ -205,161 +214,262 @@ export class AppNotificationService { this.store.pipe( select((state: any) => state.messenger.room.roomInfo as RoomInfo) ), + this.store.pipe( + select( + (state: any) => + state.messenger.room.userInfoList.entities as Dictionary< + UserInfoListState + > + ) + ), this.store.pipe( select( (state: any) => state.messenger.sync.room.entities as Dictionary ) + ), + this.store.pipe( + select( + (state: any) => + state.messenger.sync.buddy2.entities as Dictionary + ) + ), + this.store.pipe( + select( + (state: any) => + state.messenger.sync.roomUserShort.entities as Dictionary< + RoomUserData + > + ) ) ), - tap(([notiOrRes, curRoomInfo, roomList]) => { - switch (notiOrRes.SSVC_TYPE) { - case SSVC_TYPE_EVENT_SEND_RES: - case SSVC_TYPE_EVENT_SEND_NOTI: - { - const noti = notiOrRes as SendNotification; - this.logger.debug( - 'Notification::eventProtocolService::SendNotification', - noti - ); - - this.store.dispatch( - EventStore.sendNotification({ + tap( + ([ + notiOrRes, + curRoomInfo, + curRoomUserInfo, + roomList, + buddyList, + roomUserShorts + ]) => { + switch (notiOrRes.SSVC_TYPE) { + case SSVC_TYPE_EVENT_SEND_RES: + case SSVC_TYPE_EVENT_SEND_NOTI: + { + const noti = notiOrRes as SendNotification; + this.logger.debug( + 'Notification::eventProtocolService::SendNotification', noti - }) - ); + ); - // notification.. - if (notiOrRes.SSVC_TYPE === SSVC_TYPE_EVENT_SEND_NOTI) { - let doNoti = true; + this.store.dispatch( + EventStore.sendNotification({ + noti + }) + ); - const windowState = this.nativeService.getWindowState(); + // notification.. + if (notiOrRes.SSVC_TYPE === SSVC_TYPE_EVENT_SEND_NOTI) { + let doNoti = true; - // 현재 열려 있는 방일경우 노티 안함. - if ( - !!curRoomInfo && - !!curRoomInfo.roomSeq && - curRoomInfo.roomSeq === noti.roomSeq && - !!windowState && - windowState.windowState !== WindowState.Minimized && - windowState.windowState !== WindowState.Hidden - ) { - doNoti = false; - } + const windowState = this.nativeService.getWindowState(); - // // 포커스 아웃일때 무조건 노티. - // // Case 1 : 단순 포커스 아웃. - // // Case 2 : hidden 시 포커스 인 상태이지만 위에서 필터링 됨. - // console.log(windowState); - // if ( - // windowState.windowFocusState !== - // ElectronBrowserWindowChannel.Focus - // ) { - // doNoti = true; - // } + // 현재 열려 있는 방일경우 노티 안함. + if ( + !!curRoomInfo && + !!curRoomInfo.roomSeq && + curRoomInfo.roomSeq === noti.roomSeq && + !!windowState && + windowState.windowState !== WindowState.Minimized && + windowState.windowState !== WindowState.Hidden + ) { + doNoti = false; + } - // 방별 알림이 꺼져 있으면 노티 안함. > 우선순위 최상위. - if ( - !!roomList[noti.roomSeq] && - !roomList[noti.roomSeq].receiveAlarm - ) { - doNoti = false; - } + // // 포커스 아웃일때 무조건 노티. + // // Case 1 : 단순 포커스 아웃. + // // Case 2 : hidden 시 포커스 인 상태이지만 위에서 필터링 됨. + // console.log(windowState); + // if ( + // windowState.windowFocusState !== + // ElectronBrowserWindowChannel.Focus + // ) { + // doNoti = true; + // } - if (doNoti) { - const appUserInfo = this.localStorageService.encGet< - AppUserInfo - >(KEY_APP_USER_INFO, environment.customConfig.appKey); + // 방별 알림이 꺼져 있으면 노티 안함. > 우선순위 최상위. + if ( + !!roomList[noti.roomSeq] && + !roomList[noti.roomSeq].receiveAlarm + ) { + doNoti = false; + } - if (appUserInfo.settings.notification.use) { - if ( - appUserInfo.settings.notification.method === - NotificationMethod.Sound - ) { - const audio = new Audio( - 'assets/sounds/messageAlarm.mp3' - ); - audio.play(); - } else { - const contents = StringUtil.convertFinalEventMessage( - noti.eventType, - noti.info.sentMessageJson - ); + if (doNoti) { + const appUserInfo = this.localStorageService.encGet< + AppUserInfo + >(KEY_APP_USER_INFO, environment.customConfig.appKey); - if (!!contents) { - const notiReq: NotificationRequest = { - type: NotificationType.Event, - seq: noti.roomSeq, - title: this.translateService.instant( - 'notification.titleChatEventArrived' - ), - contents, - image: '', - useSound: [ - NotificationMethod.Sound, - NotificationMethod.SoundAndAlert - ].some( - n => - n === appUserInfo.settings.notification.method - ) - ? true - : false, - displayTime: - appUserInfo.settings.notification - .alertExposureTime * 1000 - }; - this.nativeService.notify(notiReq); + if (appUserInfo.settings.notification.use) { + if ( + appUserInfo.settings.notification.method === + NotificationMethod.Sound + ) { + const audio = new Audio( + 'assets/sounds/messageAlarm.mp3' + ); + audio.play(); + } else { + const contents = StringUtil.convertFinalEventMessage( + noti.eventType, + noti.info.sentMessageJson + ); + + if (!!contents) { + const notiReq: NotificationRequest = { + type: NotificationType.Event, + seq: noti.roomSeq, + title: this.translateService.instant( + 'notification.titleChatEventArrived' + ), + contents, + image: '', + useSound: [ + NotificationMethod.Sound, + NotificationMethod.SoundAndAlert + ].some( + n => + n === appUserInfo.settings.notification.method + ) + ? true + : false, + displayTime: + appUserInfo.settings.notification + .alertExposureTime * 1000 + }; + + // Sender Info setting + // STEP 1 >> In buddy group. + let senderInfo: any = buddyList[noti.SENDER_SEQ]; + + // STEP 2 >> In Current Room Users. + if (!senderInfo) { + senderInfo = curRoomUserInfo[noti.SENDER_SEQ]; + } + + // STEP 3 >> In All Room Users. + if (!senderInfo) { + for (const key in roomUserShorts) { + if (key === undefined) { + continue; + } + + if (roomUserShorts.hasOwnProperty(key)) { + const element = roomUserShorts[key]; + const filteredUserInfos = element.userInfos.filter( + info => info.seq === noti.SENDER_SEQ + ); + + if ( + !!filteredUserInfos && + filteredUserInfos.length > 0 + ) { + senderInfo = filteredUserInfos[0]; + break; + } + } + } + } + + // Sender Info setting. + if (!!senderInfo) { + // name set + let name = senderInfo.name; + let grade = senderInfo.grade; + + switch ( + this.ucapTranslateService.currentLang.toUpperCase() + ) { + case LocaleCode.English: + name = senderInfo.nameEn; + grade = senderInfo.gradeEn; + break; + case LocaleCode.Chinese: + name = senderInfo.nameCn; + grade = senderInfo.gradeCn; + break; + } + + notiReq.title = this.translateService.instant( + 'notification.titleChatEventArrivedByUser', + { + userInfo: !!grade ? `${name} ${grade}` : name + } + ); + + // Image set. + if (!!senderInfo.profileImageFile) { + const sessionVerinfo = this.sessionStorageService.get< + VersionInfo2Response + >(KEY_VER_INFO); + notiReq.image = `${sessionVerinfo.profileRoot}${senderInfo.profileImageFile}`; + } + } + + // express noti popup + this.nativeService.notify(notiReq); + } } } } } } - } - break; - case SSVC_TYPE_EVENT_READ_RES: - case SSVC_TYPE_EVENT_READ_NOTI: - { - // 대화방 unread count 처리. - const noti = notiOrRes as ReadNotification; - this.logger.debug( - 'Notification::eventProtocolService::ReadNotification', - noti - ); - this.store.dispatch(EventStore.readNotification(noti)); - } - break; - case SSVC_TYPE_EVENT_CANCEL_NOTI: - { - const noti = notiOrRes as CancelNotification; - this.logger.debug( - 'Notification::eventProtocolService::CancelNotification', - noti - ); - this.store.dispatch( - EventStore.cancelNotification({ + break; + case SSVC_TYPE_EVENT_READ_RES: + case SSVC_TYPE_EVENT_READ_NOTI: + { + // 대화방 unread count 처리. + const noti = notiOrRes as ReadNotification; + this.logger.debug( + 'Notification::eventProtocolService::ReadNotification', noti - }) - ); - } - break; - case SSVC_TYPE_EVENT_DEL_RES: - { - const noti = notiOrRes as DelNotification; - this.logger.debug( - 'Notification::eventProtocolService::DelNotification', - noti - ); - this.store.dispatch( - EventStore.delNotification({ + ); + this.store.dispatch(EventStore.readNotification(noti)); + } + break; + case SSVC_TYPE_EVENT_CANCEL_NOTI: + { + const noti = notiOrRes as CancelNotification; + this.logger.debug( + 'Notification::eventProtocolService::CancelNotification', noti - }) - ); - } - break; - default: - break; + ); + this.store.dispatch( + EventStore.cancelNotification({ + noti + }) + ); + } + break; + case SSVC_TYPE_EVENT_DEL_RES: + { + const noti = notiOrRes as DelNotification; + this.logger.debug( + 'Notification::eventProtocolService::DelNotification', + noti + ); + this.store.dispatch( + EventStore.delNotification({ + noti + }) + ); + } + break; + default: + break; + } } - }) + ) ) .subscribe(); this.infoProtocolService.notification$ diff --git a/projects/ucap-webmessenger-app/src/assets/i18n/en.json b/projects/ucap-webmessenger-app/src/assets/i18n/en.json index 02839e06..aa11888d 100644 --- a/projects/ucap-webmessenger-app/src/assets/i18n/en.json +++ b/projects/ucap-webmessenger-app/src/assets/i18n/en.json @@ -383,7 +383,9 @@ "label": "Update" }, "notification": { + "titleChatEventArrivedByUser": "A Message of chat from {{userInfo}}.", "titleChatEventArrived": "A message of chat has arrived.", + "titleMessageArrivedByUser": "A Message from {{userInfo}}.", "titleMessageArrived": "A message has arrived." }, "common": { diff --git a/projects/ucap-webmessenger-app/src/assets/i18n/ko.json b/projects/ucap-webmessenger-app/src/assets/i18n/ko.json index 230d59ec..e0093ff7 100644 --- a/projects/ucap-webmessenger-app/src/assets/i18n/ko.json +++ b/projects/ucap-webmessenger-app/src/assets/i18n/ko.json @@ -383,7 +383,9 @@ "label": "업데이트" }, "notification": { + "titleChatEventArrivedByUser": "{{userInfo}} 님의 메세지.", "titleChatEventArrived": "메세지가 도착했습니다.", + "titleMessageArrivedByUser": "{{userInfo}} 님의 쪽지.", "titleMessageArrived": "쪽지가 도착했습니다." }, "common": { diff --git a/projects/ucap-webmessenger-protocol-query/src/lib/protocols/user-seq.ts b/projects/ucap-webmessenger-protocol-query/src/lib/protocols/user-seq.ts index 9a8ae379..43ea1644 100644 --- a/projects/ucap-webmessenger-protocol-query/src/lib/protocols/user-seq.ts +++ b/projects/ucap-webmessenger-protocol-query/src/lib/protocols/user-seq.ts @@ -22,7 +22,7 @@ export interface UserSeqRequest extends ProtocolRequest { // 기관코드(s) companyCode: string; // 상세정보여부(s) - isDetail: boolean; + detailType: string; // 발신자회사코드(s) senderCompanyCode: string; // 발신자임직원유형(s) @@ -51,7 +51,7 @@ export const encodeUserSeq: ProtocolEncoder = ( { type: PacketBodyValue.String, value: req.divCd }, { type: PacketBodyValue.String, value: req.loginIds.join(',') }, { type: PacketBodyValue.String, value: req.companyCode }, - { type: PacketBodyValue.String, value: req.isDetail ? 'Y' : 'N' }, + { type: PacketBodyValue.String, value: req.detailType }, { type: PacketBodyValue.String, value: req.senderCompanyCode }, { type: PacketBodyValue.String, value: req.senderEmployeeType } );