From 97e65426f3b4c6287d83fba20c730dda74d3760f Mon Sep 17 00:00:00 2001 From: leejinho Date: Thu, 26 Dec 2019 13:22:32 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8C=80=ED=99=94=EB=B0=A9=EB=A9=B8=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EC=84=A4=EC=A0=95=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=85=B8=ED=8B=B0=20=EC=B6=9C=EB=A0=A5=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80,=20=ED=98=84=EC=9E=AC=20=EB=B0=A9=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=EB=85=B8?= =?UTF-8?q?=ED=8B=B0=20=EC=B6=9C=EB=A0=A5=EC=97=AC=EB=B6=80=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/services/notification.service.ts | 90 +++++++++++++------ 1 file changed, 62 insertions(+), 28 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 05d09839..57893ab4 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -41,7 +41,8 @@ import { SSVC_TYPE_ROOM_EXIT_FORCING_RES, SSVC_TYPE_ROOM_EXIT_RES, SSVC_TYPE_ROOM_INVITE_RES, - ExitForcingResponse + ExitForcingResponse, + RoomInfo } from '@ucap-webmessenger/protocol-room'; import { StatusProtocolService, @@ -100,6 +101,7 @@ 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 { Dictionary } from '@ngrx/entity'; @Injectable() export class AppNotificationService { @@ -151,7 +153,18 @@ export class AppNotificationService { this.eventProtocolService.notification$ .pipe( - tap(notiOrRes => { + withLatestFrom( + this.store.pipe( + select((state: any) => state.messenger.room.roomInfo as RoomInfo) + ), + this.store.pipe( + select( + (state: any) => + state.messenger.sync.room.entities as Dictionary + ) + ) + ), + tap(([notiOrRes, curRoomInfo, roomList]) => { switch (notiOrRes.SSVC_TYPE) { case SSVC_TYPE_EVENT_SEND_RES: case SSVC_TYPE_EVENT_SEND_NOTI: @@ -170,33 +183,54 @@ export class AppNotificationService { // notification.. if (notiOrRes.SSVC_TYPE === SSVC_TYPE_EVENT_SEND_NOTI) { - const appUserInfo = this.localStorageService.encGet< - AppUserInfo - >(KEY_APP_USER_INFO, environment.customConfig.appKey); + let doNoti = true; - if (appUserInfo.settings.notification.use) { - const notiReq: NotificationRequest = { - type: NotificationType.Event, - seq: noti.roomSeq, - title: '메세지가 도착했습니다.', - contents: StringUtil.convertFinalEventMessage( - noti.eventType, - noti.message - ), - 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 ( + !!roomList[noti.roomSeq] && + !roomList[noti.roomSeq].receiveAlarm + ) { + doNoti = false; + } + + // 현재 열려 있는 방일경우 노티 안함. + if ( + !!curRoomInfo && + !!curRoomInfo.roomSeq && + curRoomInfo.roomSeq === noti.roomSeq + ) { + doNoti = false; + } + + if (doNoti) { + const appUserInfo = this.localStorageService.encGet< + AppUserInfo + >(KEY_APP_USER_INFO, environment.customConfig.appKey); + + if (appUserInfo.settings.notification.use) { + const notiReq: NotificationRequest = { + type: NotificationType.Event, + seq: noti.roomSeq, + title: '메세지가 도착했습니다.', + contents: StringUtil.convertFinalEventMessage( + noti.eventType, + noti.message + ), + 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); + } } } }