From 37691a565f802fb206c10cdf7f71dae0b6aa0ad9 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Fri, 11 Oct 2019 14:01:43 +0900 Subject: [PATCH] effects of notification are added --- .../src/app/services/notification.service.ts | 29 +++++---- .../src/app/store/account/index.ts | 17 ++++- .../src/app/store/account/info/actions.ts | 8 +++ .../src/app/store/account/info/effects.ts | 29 +++++++++ .../src/app/store/account/info/index.ts | 4 ++ .../src/app/store/account/info/reducers.ts | 4 ++ .../src/app/store/account/info/state.ts | 18 ++++++ .../src/app/store/messenger/event/actions.ts | 26 +++++++- .../src/app/store/messenger/event/effects.ts | 63 ++++++++++++++++++- .../src/app/store/messenger/room/actions.ts | 26 +++++++- .../src/app/store/messenger/room/effects.ts | 51 ++++++++++++++- .../src/app/store/messenger/status/actions.ts | 8 ++- .../src/app/store/messenger/status/effects.ts | 18 +++++- 13 files changed, 281 insertions(+), 20 deletions(-) create mode 100644 projects/ucap-webmessenger-app/src/app/store/account/info/actions.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/account/info/effects.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/account/info/index.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/account/info/reducers.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/account/info/state.ts 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 d07d3af2..d0043df8 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -108,19 +108,9 @@ export class AppNotificationService { noti ); - const appendInfo: Info = { - seq: noti.seq, - type: noti.eventType, - senderSeq: noti.SENDER_SEQ, - sendDate: noti.sendDate, - sentMessage: noti.message, - receiverCount: noti.receiverCount - }; - this.store.dispatch( - EventStore.newInfo({ - roomSeq: noti.roomSeq, - info: appendInfo + EventStore.sendNotification({ + noti }) ); } @@ -133,6 +123,11 @@ export class AppNotificationService { 'Notification::eventProtocolService::ReadNotification', noti ); + this.store.dispatch( + EventStore.readNotification({ + noti + }) + ); } break; case SSVC_TYPE_EVENT_CANCEL_NOTI: @@ -142,6 +137,11 @@ export class AppNotificationService { 'Notification::eventProtocolService::CancelNotification', noti ); + this.store.dispatch( + EventStore.cancelNotification({ + noti + }) + ); } break; case SSVC_TYPE_EVENT_DEL_RES: @@ -151,6 +151,11 @@ export class AppNotificationService { 'Notification::eventProtocolService::DelNotification', noti ); + this.store.dispatch( + EventStore.delNotification({ + noti + }) + ); } break; default: diff --git a/projects/ucap-webmessenger-app/src/app/store/account/index.ts b/projects/ucap-webmessenger-app/src/app/store/account/index.ts index 13adc103..208c7ea7 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/index.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/index.ts @@ -2,16 +2,22 @@ import { Type } from '@angular/core'; import { Action, combineReducers, Selector, createSelector } from '@ngrx/store'; import * as AuthenticationStore from './authentication'; +import * as InfoStore from './info'; export interface State { authentication: AuthenticationStore.State; + info: InfoStore.State; } -export const effects: Type[] = [AuthenticationStore.Effects]; +export const effects: Type[] = [ + AuthenticationStore.Effects, + InfoStore.Effects +]; export function reducers(state: State | undefined, action: Action) { return combineReducers({ - authentication: AuthenticationStore.reducer + authentication: AuthenticationStore.reducer, + info: InfoStore.reducer })(state, action); } @@ -22,6 +28,13 @@ export function selectors(selector: Selector) { selector, (state: State) => state.authentication ) + ), + + InfoSelector: InfoStore.selectors( + createSelector( + selector, + (state: State) => state.info + ) ) }; } diff --git a/projects/ucap-webmessenger-app/src/app/store/account/info/actions.ts b/projects/ucap-webmessenger-app/src/app/store/account/info/actions.ts new file mode 100644 index 00000000..50a28554 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/account/info/actions.ts @@ -0,0 +1,8 @@ +import { createAction, props } from '@ngrx/store'; + +import { UserNotification } from '@ucap-webmessenger/protocol-info'; + +export const userNotification = createAction( + '[Account::Info] User Notification', + props<{ noti: UserNotification }>() +); diff --git a/projects/ucap-webmessenger-app/src/app/store/account/info/effects.ts b/projects/ucap-webmessenger-app/src/app/store/account/info/effects.ts new file mode 100644 index 00000000..57c12f8b --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/account/info/effects.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@angular/core'; + +import { Actions, createEffect, ofType } from '@ngrx/effects'; + +import { Store } from '@ngrx/store'; + +import { NGXLogger } from 'ngx-logger'; +import { userNotification } from './actions'; +import { map, tap } from 'rxjs/operators'; + +@Injectable() +export class Effects { + userNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(userNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + + constructor( + private actions$: Actions, + private store: Store, + private logger: NGXLogger + ) {} +} diff --git a/projects/ucap-webmessenger-app/src/app/store/account/info/index.ts b/projects/ucap-webmessenger-app/src/app/store/account/info/index.ts new file mode 100644 index 00000000..2663cade --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/account/info/index.ts @@ -0,0 +1,4 @@ +export * from './actions'; +export * from './effects'; +export * from './reducers'; +export * from './state'; diff --git a/projects/ucap-webmessenger-app/src/app/store/account/info/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/account/info/reducers.ts new file mode 100644 index 00000000..70e7e209 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/account/info/reducers.ts @@ -0,0 +1,4 @@ +import { createReducer, on } from '@ngrx/store'; +import { initialState } from './state'; + +export const reducer = createReducer(initialState); diff --git a/projects/ucap-webmessenger-app/src/app/store/account/info/state.ts b/projects/ucap-webmessenger-app/src/app/store/account/info/state.ts new file mode 100644 index 00000000..24114eb8 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/account/info/state.ts @@ -0,0 +1,18 @@ +import { Selector, createSelector } from '@ngrx/store'; + +export interface State { + selectedRoom: string | null; +} + +export const initialState: State = { + selectedRoom: null +}; + +export function selectors(selector: Selector) { + return { + selectedRoom: createSelector( + selector, + (state: State) => state.selectedRoom + ) + }; +} diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts index 25947104..b095f29a 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts @@ -4,7 +4,11 @@ import { Info, InfoResponse, SendResponse, - SendRequest + SendRequest, + SendNotification, + ReadNotification, + CancelNotification, + DelNotification } from '@ucap-webmessenger/protocol-event'; export const info = createAction( @@ -57,3 +61,23 @@ export const sendFailure = createAction( '[Messenger::Event] Send Failure', props<{ error: any }>() ); + +export const sendNotification = createAction( + '[Messenger::Event] Send Notification', + props<{ noti: SendNotification }>() +); + +export const readNotification = createAction( + '[Messenger::Event] Read Notification', + props<{ noti: ReadNotification }>() +); + +export const cancelNotification = createAction( + '[Messenger::Event] Cancel Notification', + props<{ noti: CancelNotification }>() +); + +export const delNotification = createAction( + '[Messenger::Event] Delete Notification', + props<{ noti: DelNotification }>() +); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts index 09a9448c..70e435dd 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts @@ -35,7 +35,11 @@ import { sendSuccess, sendFailure, appendInfoList, - newInfo + newInfo, + sendNotification, + readNotification, + cancelNotification, + delNotification } from './actions'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { RoomInfo } from '@ucap-webmessenger/protocol-room'; @@ -130,6 +134,30 @@ export class Effects { { dispatch: false } ); + sendNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(sendNotification), + map(action => action.noti), + tap(noti => { + const appendInfo: Info = { + seq: noti.seq, + type: noti.eventType, + senderSeq: noti.SENDER_SEQ, + sendDate: noti.sendDate, + sentMessage: noti.message, + receiverCount: noti.receiverCount + }; + + this.store.dispatch( + newInfo({ roomSeq: noti.roomSeq, info: appendInfo }) + ); + }) + ); + }, + { dispatch: false } + ); + newInfo$ = createEffect( () => { return this.actions$.pipe( @@ -151,6 +179,39 @@ export class Effects { { dispatch: false } ); + readNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(readNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + + cancelNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(cancelNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + + delNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(delNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + constructor( private actions$: Actions, private store: Store, diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/room/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/room/actions.ts index c2668f19..1b6fcb4b 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/room/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/room/actions.ts @@ -3,7 +3,11 @@ import { InfoRequest, RoomInfo, UserInfoShort, - UserInfo + UserInfo, + InviteNotification, + ExitNotification, + ExitForcingNotification, + UpdateFontNotification } from '@ucap-webmessenger/protocol-room'; export const info = createAction( @@ -24,3 +28,23 @@ export const infoFailure = createAction( '[Messenger::Room] Info Failure', props<{ error: any }>() ); + +export const inviteNotification = createAction( + '[Messenger::Room] Invite Notification', + props<{ noti: InviteNotification }>() +); + +export const exitNotification = createAction( + '[Messenger::Room] Exit Notification', + props<{ noti: ExitNotification }>() +); + +export const exitForcingNotification = createAction( + '[Messenger::Room] Exit Forcing Notification', + props<{ noti: ExitForcingNotification }>() +); + +export const updateFontNotification = createAction( + '[Messenger::Room] Update Font Notification', + props<{ noti: UpdateFontNotification }>() +); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts index 6c1d1228..9c76f45d 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts @@ -24,7 +24,15 @@ import { import * as ChatStore from '@app/store/messenger/chat'; -import { info, infoSuccess, infoFailure } from './actions'; +import { + info, + infoSuccess, + infoFailure, + inviteNotification, + exitNotification, + exitForcingNotification, + updateFontNotification +} from './actions'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; @@ -91,6 +99,47 @@ export class Effects { { dispatch: false } ); + inviteNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(inviteNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + exitNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(exitNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + exitForcingNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(exitForcingNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + updateFontNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(updateFontNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + constructor( private actions$: Actions, private store: Store, diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts index 4dc37685..fb0a082f 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts @@ -1,7 +1,8 @@ import { createAction, props } from '@ngrx/store'; import { BulkInfoRequest, - StatusBulkInfo + StatusBulkInfo, + StatusNotification } from '@ucap-webmessenger/protocol-status'; export const bulkInfo = createAction( @@ -18,3 +19,8 @@ export const bulkInfoFailure = createAction( '[Messenger::Status] Bulk Info Failure', props<{ error: any }>() ); + +export const statusNotification = createAction( + '[Messenger::Status] Status Notification', + props<{ noti: StatusNotification }>() +); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts index c040ed71..73ebc590 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts @@ -6,7 +6,12 @@ import { Store } from '@ngrx/store'; import { NGXLogger } from 'ngx-logger'; import * as SyncStore from '@app/store/messenger/sync'; -import { bulkInfo, bulkInfoSuccess, bulkInfoFailure } from './actions'; +import { + bulkInfo, + bulkInfoSuccess, + bulkInfoFailure, + statusNotification +} from './actions'; import { tap, switchMap, map, catchError } from 'rxjs/operators'; import { StatusProtocolService, @@ -68,6 +73,17 @@ export class Effects { { dispatch: false } ); + statusNotification$ = createEffect( + () => { + return this.actions$.pipe( + ofType(statusNotification), + map(action => action.noti), + tap(noti => {}) + ); + }, + { dispatch: false } + ); + constructor( private actions$: Actions, private store: Store,