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); + } } } }