Notification 사전작업

This commit is contained in:
leejh 2019-11-01 11:25:54 +09:00
parent 5c7ac7f199
commit 9aff7114f8
8 changed files with 143 additions and 89 deletions

View File

@ -194,3 +194,7 @@ ipcMain.on(Channel.saveFile, (event: IpcMainEvent, ...args: any[]) => {
event.returnValue = false; event.returnValue = false;
} }
}); });
ipcMain.on(Channel.showNotify, (event: IpcMainEvent, ...args: any[]) => {
console.log('Channel.showNotify', args);
});

View File

@ -1,5 +1,5 @@
import { delGroupSuccess, buddy2 } from './../store/messenger/sync/actions'; 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'; 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 SyncStore from '@app/store/messenger/sync';
import * as RoomStore from '@app/store/messenger/room'; import * as RoomStore from '@app/store/messenger/room';
import * as StatusStore from '@app/store/messenger/status'; 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() @Injectable()
export class AppNotificationService { export class AppNotificationService {
@ -90,6 +96,7 @@ export class AppNotificationService {
private groupProtocolService: GroupProtocolService, private groupProtocolService: GroupProtocolService,
private buddyProtocolService: BuddyProtocolService, private buddyProtocolService: BuddyProtocolService,
private statusProtocolService: StatusProtocolService, private statusProtocolService: StatusProtocolService,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private store: Store<any>, private store: Store<any>,
private logger: NGXLogger private logger: NGXLogger
) {} ) {}
@ -143,6 +150,22 @@ export class AppNotificationService {
noti 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; break;
case SSVC_TYPE_EVENT_READ_RES: case SSVC_TYPE_EVENT_READ_RES:

View File

@ -1,4 +1,3 @@
import { JsonObject } from 'type-fest';
import { createReducer, on } from '@ngrx/store'; import { createReducer, on } from '@ngrx/store';
import { import {
initialState, initialState,
@ -29,9 +28,7 @@ import {
import * as RoomStore from '@app/store/messenger/room'; import * as RoomStore from '@app/store/messenger/room';
import { RoomInfo } from '@ucap-webmessenger/protocol-room'; import { RoomInfo } from '@ucap-webmessenger/protocol-room';
import { EventType } from '@ucap-webmessenger/protocol-event'; import { StringUtil } from '@ucap-webmessenger/core';
import { FileType } from '@ucap-webmessenger/protocol-file';
import { JsonAnalization } from '@ucap-webmessenger/api';
export const reducer = createReducer( export const reducer = createReducer(
initialState, initialState,
@ -103,63 +100,36 @@ export const reducer = createReducer(
}), }),
on(updateRoomForNewEventMessage, (state, action) => { on(updateRoomForNewEventMessage, (state, action) => {
let finalEventMessage: string = action.info.sentMessage; const finalEventMessage:
switch (action.info.type) { | string
case EventType.Join: | null = StringUtil.convertFinalEventMessage(
case EventType.Exit: action.info.type,
case EventType.RenameRoom: action.info.sentMessage
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
};
return { if (!finalEventMessage) {
...state, /**
room: adapterRoom.updateOne( * .
{ id: action.roomSeq, changes: roomInfo }, * @description Edit with ui-chat > messages.component.ts
{ ...state.room } */
) 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) => { on(RoomStore.updateSuccess, (state, action) => {

View File

@ -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;
}
}
}

View File

@ -21,3 +21,4 @@ export * from './lib/types/status-type.type';
export * from './lib/types/video-conference-type.type'; export * from './lib/types/video-conference-type.type';
export * from './lib/utils/mime.util'; export * from './lib/utils/mime.util';
export * from './lib/utils/string.util';

View File

@ -1,17 +1,15 @@
import { Observable } from 'rxjs'; 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 { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
export class BrowserNativeService implements NativeService { export class BrowserNativeService implements NativeService {
showNotify( showNotify(noti: NotiRequest): void {}
roomSeq: number,
title: string,
contents: string,
image: string,
useSound: boolean
): void {}
checkForUpdates(): Observable<boolean> { checkForUpdates(): Observable<boolean> {
return new Observable<boolean>(subscriber => { return new Observable<boolean>(subscriber => {

View File

@ -2,7 +2,11 @@ import { ipcRenderer, remote, IpcRendererEvent } from 'electron';
import { Observable, Subject } from 'rxjs'; 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 { Channel } from '../types/channel.type';
import { share } from 'rxjs/operators'; import { share } from 'rxjs/operators';
@ -10,20 +14,15 @@ export class ElectronNativeService implements NativeService {
private windowStateChangedSubject: Subject<WindowState> | null = null; private windowStateChangedSubject: Subject<WindowState> | null = null;
private windowStateChanged$: Observable<WindowState> | null = null; private windowStateChanged$: Observable<WindowState> | null = null;
showNotify( showNotify(noti: NotiRequest): void {
roomSeq: number,
title: string,
contents: string,
image: string,
useSound: boolean
): void {
ipcRenderer.send( ipcRenderer.send(
Channel.showNotify, Channel.showNotify,
roomSeq, noti.roomSeq,
title, noti.title,
contents, noti.contents,
image, noti.image,
useSound noti.useSound,
noti.interval
); );
} }

View File

@ -3,13 +3,7 @@ import { Observable } from 'rxjs';
import { WindowState } from '../types/window-state.type'; import { WindowState } from '../types/window-state.type';
export interface NativeService { export interface NativeService {
showNotify( showNotify(noti: NotiRequest): void;
roomSeq: number,
title: string,
contents: string,
image: string,
useSound: boolean
): void;
checkForUpdates(): Observable<boolean>; checkForUpdates(): Observable<boolean>;
@ -23,3 +17,12 @@ export interface NativeService {
windowMinimize(): void; windowMinimize(): void;
windowMaximize(): void; windowMaximize(): void;
} }
export interface NotiRequest {
roomSeq: string;
title: string;
contents: string;
image: string;
useSound: boolean;
interval?: number;
}