From 9aff7114f82e7b8978acafa6c4305b0d6371cdf9 Mon Sep 17 00:00:00 2001 From: leejh Date: Fri, 1 Nov 2019 11:25:54 +0900 Subject: [PATCH] =?UTF-8?q?Notification=20=EC=82=AC=EC=A0=84=EC=9E=91?= =?UTF-8?q?=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/src/index.ts | 4 + .../src/app/services/notification.service.ts | 25 +++++- .../src/app/store/messenger/sync/reducers.ts | 90 +++++++------------ .../src/lib/utils/string.util.ts | 56 ++++++++++++ .../ucap-webmessenger-core/src/public-api.ts | 1 + .../lib/services/browser-native.service.ts | 14 ++- .../lib/services/electron-native.service.ts | 25 +++--- .../src/lib/services/native.service.ts | 17 ++-- 8 files changed, 143 insertions(+), 89 deletions(-) create mode 100644 projects/ucap-webmessenger-core/src/lib/utils/string.util.ts diff --git a/main/src/index.ts b/main/src/index.ts index a6023ee1..4cbd0ebe 100644 --- a/main/src/index.ts +++ b/main/src/index.ts @@ -194,3 +194,7 @@ ipcMain.on(Channel.saveFile, (event: IpcMainEvent, ...args: any[]) => { event.returnValue = false; } }); + +ipcMain.on(Channel.showNotify, (event: IpcMainEvent, ...args: any[]) => { + console.log('Channel.showNotify', args); +}); 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 20f000e7..bc2a1ecd 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -1,5 +1,5 @@ import { delGroupSuccess, buddy2 } from './../store/messenger/sync/actions'; -import { Injectable } from '@angular/core'; +import { Injectable, Inject } from '@angular/core'; import { tap, withLatestFrom } from 'rxjs/operators'; @@ -79,6 +79,12 @@ import * as EventStore from '@app/store/messenger/event'; import * as SyncStore from '@app/store/messenger/sync'; import * as RoomStore from '@app/store/messenger/room'; import * as StatusStore from '@app/store/messenger/status'; +import { + NotiRequest, + NativeService, + UCAP_NATIVE_SERVICE +} from '@ucap-webmessenger/native'; +import { StringUtil } from '@ucap-webmessenger/core'; @Injectable() export class AppNotificationService { @@ -90,6 +96,7 @@ export class AppNotificationService { private groupProtocolService: GroupProtocolService, private buddyProtocolService: BuddyProtocolService, private statusProtocolService: StatusProtocolService, + @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, private store: Store, private logger: NGXLogger ) {} @@ -143,6 +150,22 @@ export class AppNotificationService { noti }) ); + + // notification.. + if (notiOrRes.SSVC_TYPE === SSVC_TYPE_EVENT_SEND_NOTI) { + const notiReq: NotiRequest = { + roomSeq: noti.roomSeq, + title: '메세지가 도착했습니다.', + contents: StringUtil.convertFinalEventMessage( + noti.eventType, + noti.message + ), + image: '', + useSound: true, + interval: 0 + }; + this.nativeService.showNotify(notiReq); + } } break; case SSVC_TYPE_EVENT_READ_RES: diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts index 0b78043e..8420f361 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts @@ -1,4 +1,3 @@ -import { JsonObject } from 'type-fest'; import { createReducer, on } from '@ngrx/store'; import { initialState, @@ -29,9 +28,7 @@ import { import * as RoomStore from '@app/store/messenger/room'; import { RoomInfo } from '@ucap-webmessenger/protocol-room'; -import { EventType } from '@ucap-webmessenger/protocol-event'; -import { FileType } from '@ucap-webmessenger/protocol-file'; -import { JsonAnalization } from '@ucap-webmessenger/api'; +import { StringUtil } from '@ucap-webmessenger/core'; export const reducer = createReducer( initialState, @@ -103,63 +100,36 @@ export const reducer = createReducer( }), on(updateRoomForNewEventMessage, (state, action) => { - let finalEventMessage: string = action.info.sentMessage; - switch (action.info.type) { - case EventType.Join: - case EventType.Exit: - case EventType.RenameRoom: - case EventType.NotificationForTimerRoom: - case EventType.GuideForRoomTimerChanged: { - /** - * 해당 타입은 메시지를 갱신하지 않는다. - * @description Edit with ui-chat > messages.component.ts - */ - return { - ...state - }; - } - case EventType.Sticker: - finalEventMessage = '스티커'; - break; - case EventType.File: - { - const contentJson = JSON.parse(finalEventMessage); - if (contentJson.FileType === FileType.Image) { - finalEventMessage = '이미지'; - } else { - finalEventMessage = '첨부파일'; - } - } - break; - case EventType.VideoConference: - finalEventMessage = '화상회의'; - break; - case EventType.MassText: - { - try { - const json: JsonObject | Error = JsonAnalization.receiveAnalization( - finalEventMessage - ); - finalEventMessage = json.Content.toString(); - } catch (e) { - finalEventMessage = '대용량 텍스트'; - } - } - break; - } - const roomInfo = { - ...state.room.entities[action.roomSeq], - finalEventDate: action.info.sendDate, - finalEventMessage - }; + const finalEventMessage: + | string + | null = StringUtil.convertFinalEventMessage( + action.info.type, + action.info.sentMessage + ); - return { - ...state, - room: adapterRoom.updateOne( - { id: action.roomSeq, changes: roomInfo }, - { ...state.room } - ) - }; + if (!finalEventMessage) { + /** + * 해당 타입은 메시지를 갱신하지 않는다. + * @description Edit with ui-chat > messages.component.ts + */ + return { + ...state + }; + } else { + const roomInfo = { + ...state.room.entities[action.roomSeq], + finalEventDate: action.info.sendDate, + finalEventMessage + }; + + return { + ...state, + room: adapterRoom.updateOne( + { id: action.roomSeq, changes: roomInfo }, + { ...state.room } + ) + }; + } }), on(RoomStore.updateSuccess, (state, action) => { diff --git a/projects/ucap-webmessenger-core/src/lib/utils/string.util.ts b/projects/ucap-webmessenger-core/src/lib/utils/string.util.ts new file mode 100644 index 00000000..997492d4 --- /dev/null +++ b/projects/ucap-webmessenger-core/src/lib/utils/string.util.ts @@ -0,0 +1,56 @@ +import { EventType } from '@ucap-webmessenger/protocol-event'; +import { FileType } from '@ucap-webmessenger/protocol-file'; +import { JsonObject } from 'type-fest'; +import { JsonAnalization } from '@ucap-webmessenger/api'; + +export class StringUtil { + public static convertFinalEventMessage( + eventType: EventType, + finalEventMessage: string + ): string | null { + switch (eventType) { + case EventType.Join: + case EventType.Exit: + case EventType.RenameRoom: + case EventType.NotificationForTimerRoom: + case EventType.GuideForRoomTimerChanged: { + /** + * 해당 타입은 메시지를 갱신하지 않는다. + * @description Edit with ui-chat > messages.component.ts + */ + return null; + } + case EventType.Sticker: + finalEventMessage = '스티커'; + break; + case EventType.File: + { + const contentJson = JSON.parse(finalEventMessage); + if (contentJson.FileType === FileType.Image) { + finalEventMessage = '이미지'; + } else { + finalEventMessage = '첨부파일'; + } + } + break; + case EventType.VideoConference: + finalEventMessage = '화상회의'; + break; + case EventType.MassText: + { + try { + const json: JsonObject | Error = JsonAnalization.receiveAnalization( + finalEventMessage + ); + finalEventMessage = json.Content.toString(); + } catch (e) { + finalEventMessage = '대용량 텍스트'; + } + } + break; + + default: + return finalEventMessage; + } + } +} diff --git a/projects/ucap-webmessenger-core/src/public-api.ts b/projects/ucap-webmessenger-core/src/public-api.ts index 00883831..74c4c846 100644 --- a/projects/ucap-webmessenger-core/src/public-api.ts +++ b/projects/ucap-webmessenger-core/src/public-api.ts @@ -21,3 +21,4 @@ export * from './lib/types/status-type.type'; export * from './lib/types/video-conference-type.type'; export * from './lib/utils/mime.util'; +export * from './lib/utils/string.util'; diff --git a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts index 5a5f6297..9c73c342 100644 --- a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts +++ b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts @@ -1,17 +1,15 @@ import { Observable } from 'rxjs'; -import { NativeService, WindowState } from '@ucap-webmessenger/native'; +import { + NativeService, + WindowState, + NotiRequest +} from '@ucap-webmessenger/native'; import { HttpClient } from '@angular/common/http'; import { map } from 'rxjs/operators'; export class BrowserNativeService implements NativeService { - showNotify( - roomSeq: number, - title: string, - contents: string, - image: string, - useSound: boolean - ): void {} + showNotify(noti: NotiRequest): void {} checkForUpdates(): Observable { return new Observable(subscriber => { diff --git a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts index d0002df4..28b1e5a8 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts @@ -2,7 +2,11 @@ import { ipcRenderer, remote, IpcRendererEvent } from 'electron'; import { Observable, Subject } from 'rxjs'; -import { NativeService, WindowState } from '@ucap-webmessenger/native'; +import { + NativeService, + WindowState, + NotiRequest +} from '@ucap-webmessenger/native'; import { Channel } from '../types/channel.type'; import { share } from 'rxjs/operators'; @@ -10,20 +14,15 @@ export class ElectronNativeService implements NativeService { private windowStateChangedSubject: Subject | null = null; private windowStateChanged$: Observable | null = null; - showNotify( - roomSeq: number, - title: string, - contents: string, - image: string, - useSound: boolean - ): void { + showNotify(noti: NotiRequest): void { ipcRenderer.send( Channel.showNotify, - roomSeq, - title, - contents, - image, - useSound + noti.roomSeq, + noti.title, + noti.contents, + noti.image, + noti.useSound, + noti.interval ); } diff --git a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts index ff0ef123..1944c2f8 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -3,13 +3,7 @@ import { Observable } from 'rxjs'; import { WindowState } from '../types/window-state.type'; export interface NativeService { - showNotify( - roomSeq: number, - title: string, - contents: string, - image: string, - useSound: boolean - ): void; + showNotify(noti: NotiRequest): void; checkForUpdates(): Observable; @@ -23,3 +17,12 @@ export interface NativeService { windowMinimize(): void; windowMaximize(): void; } + +export interface NotiRequest { + roomSeq: string; + title: string; + contents: string; + image: string; + useSound: boolean; + interval?: number; +}