From e9088572d5cbc229cb4a551fc618de5e1874d908 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Fri, 11 Oct 2019 16:40:55 +0900 Subject: [PATCH] notification of status is implemented --- .../src/app/services/notification.service.ts | 38 ++++++++++++++++- .../src/app/store/messenger/status/effects.ts | 20 ++++----- .../app/store/messenger/status/reducers.ts | 32 +++++++++++++-- .../src/app/store/messenger/status/state.ts | 41 ++++++++++++++++--- .../src/lib/services/room-protocol.service.ts | 2 + 5 files changed, 112 insertions(+), 21 deletions(-) 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 d0043df8..e6a268f7 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -12,8 +12,6 @@ import { LogoutRemoteNotification } from '@ucap-webmessenger/protocol-authentication'; -import * as AuthenticationStore from '@app/store/account/authentication'; -import * as EventStore from '@app/store/messenger/event'; import { NGXLogger } from 'ngx-logger'; import { EventProtocolService, @@ -53,6 +51,12 @@ import { UpdateFontNotification } from '@ucap-webmessenger/protocol-room'; +import * as AuthenticationStore from '@app/store/account/authentication'; +import * as InfoStore from '@app/store/account/info'; +import * as EventStore from '@app/store/messenger/event'; +import * as RoomStore from '@app/store/messenger/room'; +import * as StatusStore from '@app/store/messenger/status'; + @Injectable() export class AppNotificationService { constructor( @@ -175,6 +179,11 @@ export class AppNotificationService { 'Notification::infoProtocolService::UserNotification', noti ); + this.store.dispatch( + InfoStore.userNotification({ + noti + }) + ); } break; default: @@ -194,6 +203,11 @@ export class AppNotificationService { 'Notification::roomProtocolService::InviteNotification', noti ); + this.store.dispatch( + RoomStore.inviteNotification({ + noti + }) + ); } break; case SSVC_TYPE_ROOM_EXIT_NOTI: @@ -203,6 +217,11 @@ export class AppNotificationService { 'Notification::roomProtocolService::ExitNotification', noti ); + this.store.dispatch( + RoomStore.exitNotification({ + noti + }) + ); } break; case SSVC_TYPE_ROOM_EXIT_FORCING_NOTI: @@ -212,6 +231,11 @@ export class AppNotificationService { 'Notification::roomProtocolService::ExitForcingNotification', noti ); + this.store.dispatch( + RoomStore.exitForcingNotification({ + noti + }) + ); } break; case SSVC_TYPE_ROOM_FONT_UPD_NOTI: @@ -221,6 +245,11 @@ export class AppNotificationService { 'Notification::roomProtocolService::UpdateFontNotification', noti ); + this.store.dispatch( + RoomStore.updateFontNotification({ + noti + }) + ); } break; default: @@ -240,6 +269,11 @@ export class AppNotificationService { 'Notification::statusProtocolService::StatusNotification', noti ); + this.store.dispatch( + StatusStore.statusNotification({ + noti + }) + ); } break; default: 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 73ebc590..f8044353 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 @@ -73,16 +73,16 @@ export class Effects { { dispatch: false } ); - statusNotification$ = createEffect( - () => { - return this.actions$.pipe( - ofType(statusNotification), - map(action => action.noti), - tap(noti => {}) - ); - }, - { dispatch: false } - ); + // statusNotification$ = createEffect( + // () => { + // return this.actions$.pipe( + // ofType(statusNotification), + // map(action => action.noti), + // tap(noti => {}) + // ); + // }, + // { dispatch: false } + // ); constructor( private actions$: Actions, diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts index 300d62a1..ffdb69c4 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts @@ -1,15 +1,41 @@ import { createReducer, on } from '@ngrx/store'; -import { initialState } from './state'; -import { bulkInfoSuccess } from './actions'; +import { initialState, State, adapterStatusBulkInfo } from './state'; +import { bulkInfoSuccess, statusNotification } from './actions'; import * as AuthenticationStore from '@app/store/account/authentication'; +import { StatusBulkInfo } from '@ucap-webmessenger/protocol-status'; export const reducer = createReducer( initialState, on(bulkInfoSuccess, (state, action) => { return { ...state, - statusBulkInfoList: action.statusBulkInfoList + statusBulkInfo: adapterStatusBulkInfo.addAll(action.statusBulkInfoList, { + ...state.statusBulkInfo + }) + } as State; + }), + + on(statusNotification, (state, action) => { + const noti = action.noti; + + const statusBulkInfoState: StatusBulkInfo = { + ...state.statusBulkInfo.entities[noti.userSeq], + conferenceStatus: noti.conferenceStatus, + imessengerStatus: noti.imessengerStatus, + mobileConferenceStatus: noti.mobileConferenceStatus, + mobileStatus: noti.mobileStatus, + pcStatus: noti.pcStatus, + phoneStatus: noti.phoneStatus, + statusMessage: noti.statusMessage + }; + + return { + ...state, + statusBulkInfo: adapterStatusBulkInfo.updateOne( + { id: noti.userSeq, changes: statusBulkInfoState }, + { ...state.statusBulkInfo } + ) }; }), diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts index 3a0c1767..9038cc74 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts @@ -1,19 +1,48 @@ import { Selector, createSelector } from '@ngrx/store'; import { StatusBulkInfo } from '@ucap-webmessenger/protocol-status'; +import { EntityState, createEntityAdapter } from '@ngrx/entity'; + +export interface StatusBulkInfoState extends EntityState {} export interface State { - statusBulkInfoList: StatusBulkInfo[]; + statusBulkInfo: StatusBulkInfoState; } +export const adapterStatusBulkInfo = createEntityAdapter({ + selectId: statusBulkInfo => statusBulkInfo.userSeq +}); + +const statusBulkInfoInitialState: StatusBulkInfoState = adapterStatusBulkInfo.getInitialState( + {} +); + export const initialState: State = { - statusBulkInfoList: [] + statusBulkInfo: statusBulkInfoInitialState }; +const { + selectAll: ngeSelectAllStatusBulkInfo, + selectEntities: ngeSelectEntitiesStatusBulkInfo, + selectIds: ngeSelectIdsStatusBulkInfo, + selectTotal: ngeSelectTotalStatusBulkInfo +} = adapterStatusBulkInfo.getSelectors(); + export function selectors(selector: Selector) { + const selectStatusBulkInfo = createSelector( + selector, + (state: State) => state.statusBulkInfo + ); + return { - statusBulkInfoList: createSelector( - selector, - (state: State) => state.statusBulkInfoList - ) + selectAllStatusBulkInfo: createSelector( + selectStatusBulkInfo, + ngeSelectAllStatusBulkInfo + ), + selectStatusBulkInfo: (userSeq: number) => + createSelector( + selectStatusBulkInfo, + ngeSelectEntitiesStatusBulkInfo, + (_, entities) => entities[userSeq] + ) }; } diff --git a/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts b/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts index a8eface0..4172c13e 100644 --- a/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts @@ -286,6 +286,7 @@ export class RoomProtocolService { }) ); } + public updateTimerSet( req: UpdateTimerSetRequest ): Observable { @@ -302,6 +303,7 @@ export class RoomProtocolService { }) ); } + public updateFont(req: UpdateFontRequest): Observable { return this.protocolService .call(