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;
}
});
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 { 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<any>,
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:

View File

@ -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) => {

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/utils/mime.util';
export * from './lib/utils/string.util';

View File

@ -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<boolean> {
return new Observable<boolean>(subscriber => {

View File

@ -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<WindowState> | null = null;
private windowStateChanged$: Observable<WindowState> | 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
);
}

View File

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