From a725d91326bc7869d724b37a258c7541e066c77c Mon Sep 17 00:00:00 2001 From: leejinho Date: Mon, 30 Mar 2020 15:44:53 +0900 Subject: [PATCH] =?UTF-8?q?=EB=85=B8=ED=8B=B0=20=ED=8C=9D=EC=97=85?= =?UTF-8?q?=EC=97=90=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95.=201.=20searching=20in=20buddy=202.=20searching=20in?= =?UTF-8?q?=20current=20opened=20room=203.=20searching=20for=20protocols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/services/notification.service.ts | 124 ++++++++++++------ 1 file changed, 81 insertions(+), 43 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 68db247f..5e14844c 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -1,6 +1,13 @@ import { Injectable, Inject } from '@angular/core'; -import { tap, withLatestFrom } from 'rxjs/operators'; +import { + tap, + withLatestFrom, + take, + map, + catchError, + finalize +} from 'rxjs/operators'; import { Store, select } from '@ngrx/store'; @@ -116,7 +123,12 @@ import { environment } from '../../environments/environment'; import { NotificationMethod, LocaleCode } from '@ucap-webmessenger/core'; import { Dictionary } from '@ngrx/entity'; import { MessageType } from '@ucap-webmessenger/api-message'; -import { LogoutInfo, KEY_LOGOUT_INFO, KEY_VER_INFO } from '@app/types'; +import { + LogoutInfo, + KEY_LOGOUT_INFO, + KEY_VER_INFO, + KEY_LOGIN_RES_INFO +} from '@app/types'; import { TranslateService } from '@ngx-translate/core'; import { deleteMessageSuccess } from '@app/store/messenger/message'; import { ServerErrorCode } from '@ucap-webmessenger/protocol'; @@ -138,6 +150,8 @@ 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'; +import { DaesangProtocolService } from '@ucap-webmessenger/daesang'; +import { of } from 'rxjs'; @Injectable() export class AppNotificationService { @@ -149,6 +163,7 @@ export class AppNotificationService { private groupProtocolService: GroupProtocolService, private buddyProtocolService: BuddyProtocolService, private queryProtocolService: QueryProtocolService, + private daesangProtocolService: DaesangProtocolService, private statusProtocolService: StatusProtocolService, private translateService: TranslateService, private ucapTranslateService: UcapTranslateService, @@ -233,25 +248,10 @@ export class AppNotificationService { (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, - curRoomUserInfo, - roomList, - buddyList, - roomUserShorts - ]) => { + ([notiOrRes, curRoomInfo, curRoomUserInfo, roomList, buddyList]) => { switch (notiOrRes.SSVC_TYPE) { case SSVC_TYPE_EVENT_SEND_RES: case SSVC_TYPE_EVENT_SEND_NOTI: @@ -356,32 +356,70 @@ export class AppNotificationService { senderInfo = curRoomUserInfo[noti.SENDER_SEQ]; } - // STEP 3 >> In All Room Users. + // STEP 3 >> user protocol if (!senderInfo) { - for (const key in roomUserShorts) { - if (key === undefined) { - continue; - } + const loginRes = this.sessionStorageService.get< + LoginResponse + >(KEY_LOGIN_RES_INFO); - if (roomUserShorts.hasOwnProperty(key)) { - const element = roomUserShorts[key]; - const filteredUserInfos = element.userInfos.filter( - info => info.seq === noti.SENDER_SEQ - ); + this.daesangProtocolService + .dataUserDaesang({ + divCd: 'OPENNOTI', + seq: noti.SENDER_SEQ, + senderCompanyCode: + loginRes.userInfo.companyCode, + senderEmployeeType: + loginRes.userInfo.employeeType + }) + .pipe( + take(1), + map(res => { + if (!!res && !!res.userInfo) { + senderInfo = res.userInfo; + let name = senderInfo.name; + let grade = senderInfo.grade; - if ( - !!filteredUserInfos && - filteredUserInfos.length > 0 - ) { - senderInfo = filteredUserInfos[0]; - break; - } - } - } - } + 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; + } - // Sender Info setting. - if (!!senderInfo) { + 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}`; + } + } + }), + catchError(error => { + return of(); + }), + finalize(() => { + this.nativeService.notify(notiReq); + }) + ) + .subscribe(); + } else { + // Sender Info setting. // name set let name = senderInfo.name; let grade = senderInfo.grade; @@ -413,10 +451,10 @@ export class AppNotificationService { >(KEY_VER_INFO); notiReq.image = `${sessionVerinfo.profileRoot}${senderInfo.profileImageFile}`; } - } - // express noti popup - this.nativeService.notify(notiReq); + // express noti popup + this.nativeService.notify(notiReq); + } } } }