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 { 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<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]) => {
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$

View File

@ -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": {

View File

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

View File

@ -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<UserSeqRequest> = (
{ 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 }
);