noti popup 에 사용자 정보 표시.

This commit is contained in:
leejinho 2020-03-23 16:34:27 +09:00
parent 8d5127c261
commit 23ae97caab
4 changed files with 252 additions and 138 deletions

View File

@ -1,7 +1,6 @@
import { delGroupSuccess, buddy2 } from './../store/messenger/sync/actions';
import { Injectable, Inject } from '@angular/core'; 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'; import { Store, select } from '@ngrx/store';
@ -95,7 +94,11 @@ import {
NotificationType, NotificationType,
WindowState WindowState
} from '@ucap-webmessenger/native'; } from '@ucap-webmessenger/native';
import { StringUtil, DialogService } from '@ucap-webmessenger/ui'; import {
StringUtil,
DialogService,
TranslateService as UcapTranslateService
} from '@ucap-webmessenger/ui';
import { import {
UmgProtocolService, UmgProtocolService,
SSVC_TYPE_UMG_NOTI, SSVC_TYPE_UMG_NOTI,
@ -110,10 +113,10 @@ import {
import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type'; import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
import { NotificationMethod } from '@ucap-webmessenger/core'; import { NotificationMethod, LocaleCode } from '@ucap-webmessenger/core';
import { Dictionary } from '@ngrx/entity'; import { Dictionary } from '@ngrx/entity';
import { MessageType } from '@ucap-webmessenger/api-message'; 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 { TranslateService } from '@ngx-translate/core';
import { deleteMessageSuccess } from '@app/store/messenger/message'; import { deleteMessageSuccess } from '@app/store/messenger/message';
import { ServerErrorCode } from '@ucap-webmessenger/protocol'; import { ServerErrorCode } from '@ucap-webmessenger/protocol';
@ -131,6 +134,10 @@ import {
} from '@ucap-webmessenger/ui-settings'; } from '@ucap-webmessenger/ui-settings';
import clone from 'clone'; import clone from 'clone';
import { ElectronBrowserWindowChannel } from '@ucap-webmessenger/electron-core'; 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() @Injectable()
export class AppNotificationService { export class AppNotificationService {
@ -141,8 +148,10 @@ export class AppNotificationService {
private roomProtocolService: RoomProtocolService, private roomProtocolService: RoomProtocolService,
private groupProtocolService: GroupProtocolService, private groupProtocolService: GroupProtocolService,
private buddyProtocolService: BuddyProtocolService, private buddyProtocolService: BuddyProtocolService,
private queryProtocolService: QueryProtocolService,
private statusProtocolService: StatusProtocolService, private statusProtocolService: StatusProtocolService,
private translateService: TranslateService, private translateService: TranslateService,
private ucapTranslateService: UcapTranslateService,
private optionProtocolService: OptionProtocolService, private optionProtocolService: OptionProtocolService,
private umgProtocolService: UmgProtocolService, private umgProtocolService: UmgProtocolService,
private localStorageService: LocalStorageService, private localStorageService: LocalStorageService,
@ -205,161 +214,262 @@ export class AppNotificationService {
this.store.pipe( this.store.pipe(
select((state: any) => state.messenger.room.roomInfo as RoomInfo) 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( this.store.pipe(
select( select(
(state: any) => (state: any) =>
state.messenger.sync.room.entities as Dictionary<RoomInfo> state.messenger.sync.room.entities as Dictionary<RoomInfo>
) )
),
this.store.pipe(
select(
(state: any) =>
state.messenger.sync.buddy2.entities as Dictionary<UserInfo>
)
),
this.store.pipe(
select(
(state: any) =>
state.messenger.sync.roomUserShort.entities as Dictionary<
RoomUserData
>
)
) )
), ),
tap(([notiOrRes, curRoomInfo, roomList]) => { tap(
switch (notiOrRes.SSVC_TYPE) { ([
case SSVC_TYPE_EVENT_SEND_RES: notiOrRes,
case SSVC_TYPE_EVENT_SEND_NOTI: curRoomInfo,
{ curRoomUserInfo,
const noti = notiOrRes as SendNotification; roomList,
this.logger.debug( buddyList,
'Notification::eventProtocolService::SendNotification', roomUserShorts
noti ]) => {
); switch (notiOrRes.SSVC_TYPE) {
case SSVC_TYPE_EVENT_SEND_RES:
this.store.dispatch( case SSVC_TYPE_EVENT_SEND_NOTI:
EventStore.sendNotification({ {
const noti = notiOrRes as SendNotification;
this.logger.debug(
'Notification::eventProtocolService::SendNotification',
noti noti
}) );
);
// notification.. this.store.dispatch(
if (notiOrRes.SSVC_TYPE === SSVC_TYPE_EVENT_SEND_NOTI) { EventStore.sendNotification({
let doNoti = true; noti
})
);
const windowState = this.nativeService.getWindowState(); // notification..
if (notiOrRes.SSVC_TYPE === SSVC_TYPE_EVENT_SEND_NOTI) {
let doNoti = true;
// 현재 열려 있는 방일경우 노티 안함. const windowState = this.nativeService.getWindowState();
if (
!!curRoomInfo &&
!!curRoomInfo.roomSeq &&
curRoomInfo.roomSeq === noti.roomSeq &&
!!windowState &&
windowState.windowState !== WindowState.Minimized &&
windowState.windowState !== WindowState.Hidden
) {
doNoti = false;
}
// // 포커스 아웃일때 무조건 노티. // 현재 열려 있는 방일경우 노티 안함.
// // Case 1 : 단순 포커스 아웃. if (
// // Case 2 : hidden 시 포커스 인 상태이지만 위에서 필터링 됨. !!curRoomInfo &&
// console.log(windowState); !!curRoomInfo.roomSeq &&
// if ( curRoomInfo.roomSeq === noti.roomSeq &&
// windowState.windowFocusState !== !!windowState &&
// ElectronBrowserWindowChannel.Focus windowState.windowState !== WindowState.Minimized &&
// ) { windowState.windowState !== WindowState.Hidden
// doNoti = true; ) {
// } doNoti = false;
}
// 방별 알림이 꺼져 있으면 노티 안함. > 우선순위 최상위. // // 포커스 아웃일때 무조건 노티.
if ( // // Case 1 : 단순 포커스 아웃.
!!roomList[noti.roomSeq] && // // Case 2 : hidden 시 포커스 인 상태이지만 위에서 필터링 됨.
!roomList[noti.roomSeq].receiveAlarm // console.log(windowState);
) { // if (
doNoti = false; // windowState.windowFocusState !==
} // ElectronBrowserWindowChannel.Focus
// ) {
// doNoti = true;
// }
if (doNoti) { // 방별 알림이 꺼져 있으면 노티 안함. > 우선순위 최상위.
const appUserInfo = this.localStorageService.encGet< if (
AppUserInfo !!roomList[noti.roomSeq] &&
>(KEY_APP_USER_INFO, environment.customConfig.appKey); !roomList[noti.roomSeq].receiveAlarm
) {
doNoti = false;
}
if (appUserInfo.settings.notification.use) { if (doNoti) {
if ( const appUserInfo = this.localStorageService.encGet<
appUserInfo.settings.notification.method === AppUserInfo
NotificationMethod.Sound >(KEY_APP_USER_INFO, environment.customConfig.appKey);
) {
const audio = new Audio(
'assets/sounds/messageAlarm.mp3'
);
audio.play();
} else {
const contents = StringUtil.convertFinalEventMessage(
noti.eventType,
noti.info.sentMessageJson
);
if (!!contents) { if (appUserInfo.settings.notification.use) {
const notiReq: NotificationRequest = { if (
type: NotificationType.Event, appUserInfo.settings.notification.method ===
seq: noti.roomSeq, NotificationMethod.Sound
title: this.translateService.instant( ) {
'notification.titleChatEventArrived' const audio = new Audio(
), 'assets/sounds/messageAlarm.mp3'
contents, );
image: '', audio.play();
useSound: [ } else {
NotificationMethod.Sound, const contents = StringUtil.convertFinalEventMessage(
NotificationMethod.SoundAndAlert noti.eventType,
].some( noti.info.sentMessageJson
n => );
n === appUserInfo.settings.notification.method
) if (!!contents) {
? true const notiReq: NotificationRequest = {
: false, type: NotificationType.Event,
displayTime: seq: noti.roomSeq,
appUserInfo.settings.notification title: this.translateService.instant(
.alertExposureTime * 1000 'notification.titleChatEventArrived'
}; ),
this.nativeService.notify(notiReq); 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;
break; case SSVC_TYPE_EVENT_READ_RES:
case SSVC_TYPE_EVENT_READ_RES: case SSVC_TYPE_EVENT_READ_NOTI:
case SSVC_TYPE_EVENT_READ_NOTI: {
{ // 대화방 unread count 처리.
// 대화방 unread count 처리. const noti = notiOrRes as ReadNotification;
const noti = notiOrRes as ReadNotification; this.logger.debug(
this.logger.debug( 'Notification::eventProtocolService::ReadNotification',
'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({
noti noti
}) );
); this.store.dispatch(EventStore.readNotification(noti));
} }
break; break;
case SSVC_TYPE_EVENT_DEL_RES: case SSVC_TYPE_EVENT_CANCEL_NOTI:
{ {
const noti = notiOrRes as DelNotification; const noti = notiOrRes as CancelNotification;
this.logger.debug( this.logger.debug(
'Notification::eventProtocolService::DelNotification', 'Notification::eventProtocolService::CancelNotification',
noti
);
this.store.dispatch(
EventStore.delNotification({
noti noti
}) );
); this.store.dispatch(
} EventStore.cancelNotification({
break; noti
default: })
break; );
}
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(); .subscribe();
this.infoProtocolService.notification$ this.infoProtocolService.notification$

View File

@ -383,7 +383,9 @@
"label": "Update" "label": "Update"
}, },
"notification": { "notification": {
"titleChatEventArrivedByUser": "A Message of chat from {{userInfo}}.",
"titleChatEventArrived": "A message of chat has arrived.", "titleChatEventArrived": "A message of chat has arrived.",
"titleMessageArrivedByUser": "A Message from {{userInfo}}.",
"titleMessageArrived": "A message has arrived." "titleMessageArrived": "A message has arrived."
}, },
"common": { "common": {

View File

@ -383,7 +383,9 @@
"label": "업데이트" "label": "업데이트"
}, },
"notification": { "notification": {
"titleChatEventArrivedByUser": "{{userInfo}} 님의 메세지.",
"titleChatEventArrived": "메세지가 도착했습니다.", "titleChatEventArrived": "메세지가 도착했습니다.",
"titleMessageArrivedByUser": "{{userInfo}} 님의 쪽지.",
"titleMessageArrived": "쪽지가 도착했습니다." "titleMessageArrived": "쪽지가 도착했습니다."
}, },
"common": { "common": {

View File

@ -22,7 +22,7 @@ export interface UserSeqRequest extends ProtocolRequest {
// 기관코드(s) // 기관코드(s)
companyCode: string; companyCode: string;
// 상세정보여부(s) // 상세정보여부(s)
isDetail: boolean; detailType: string;
// 발신자회사코드(s) // 발신자회사코드(s)
senderCompanyCode: string; senderCompanyCode: string;
// 발신자임직원유형(s) // 발신자임직원유형(s)
@ -51,7 +51,7 @@ export const encodeUserSeq: ProtocolEncoder<UserSeqRequest> = (
{ type: PacketBodyValue.String, value: req.divCd }, { type: PacketBodyValue.String, value: req.divCd },
{ type: PacketBodyValue.String, value: req.loginIds.join(',') }, { type: PacketBodyValue.String, value: req.loginIds.join(',') },
{ type: PacketBodyValue.String, value: req.companyCode }, { 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.senderCompanyCode },
{ type: PacketBodyValue.String, value: req.senderEmployeeType } { type: PacketBodyValue.String, value: req.senderEmployeeType }
); );