From 67e27594ea5e5a59977deebc947e32858b1a16d5 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 19 Nov 2019 15:33:25 +0900 Subject: [PATCH 1/4] build config is modified --- docker/docker-compose.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index b3b36ded..4a910294 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,7 +4,7 @@ services: nginx: image: nginx:1.17.5-alpine volumes: - - ../dist/ucap-webmessenger-app-browser:/usr/share/nginx/html:ro + - ../dist/web:/usr/share/nginx/html:ro - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro ports: - 8099:80 diff --git a/package.json b/package.json index f3de5fed..9136dd26 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "start:browser": "cross-env UCAP_ENV_RUNTIME=BROWSER ng serve -c browser-development -o", "build": "npm-run-all -p build:renderer build:main:production", "build:renderer": "cross-env NODE_ENV=production ng build -c renderer-development --base-href ./", - "build:browser": "cross-env UCAP_ENV_RUNTIME=BROWSER ng build -c browser-development", + "build:browser": "cross-env UCAP_ENV_RUNTIME=BROWSER ng build -c browser-development --base-href ./NextMessenger_POC", "build:main:development": "cross-env NODE_ENV=development TS_NODE_PROJECT='./config/tsconfig.webpack.json' parallel-webpack --config=config/main.webpack.config.ts", "build:main:production": "cross-env NODE_ENV=production TS_NODE_PROJECT='./config/tsconfig.webpack.json' NODE_OPTIONS='--max_old_space_size=4096' parallel-webpack --config=config/main.webpack.config.ts", "electron:local": "electron .", From 44e576fc72b07abc4f9488c3c828022fdeafe3f4 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 19 Nov 2019 16:44:50 +0900 Subject: [PATCH 2/4] native notifications are added --- .../ucap-webmessenger-electron/src/index.ts | 56 +++++++++---------- .../src/app/services/app.service.ts | 5 +- .../src/app/services/index.ts | 4 +- .../src/app/services/native.service.ts | 25 +++++++++ .../lib/services/browser-native.service.ts | 39 ++++++++++++- .../lib/services/electron-native.service.ts | 56 ++++++++++++++++++- .../src/lib/types/channel.type.ts | 18 ++++-- .../src/lib/services/native.service.ts | 5 ++ 8 files changed, 166 insertions(+), 42 deletions(-) create mode 100644 projects/ucap-webmessenger-app/src/app/services/native.service.ts diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index 4bf3964f..fc6df23c 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -21,7 +21,8 @@ import { FileChannel, IdleStateChannel, NotificationChannel, - ChatChannel + ChatChannel, + MessengerChannel } from '@ucap-webmessenger/native-electron'; import { ElectronNotificationService } from '@ucap-webmessenger/electron-notification'; @@ -156,18 +157,7 @@ function createWindow() { appWindow = window; } -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -// Some APIs can only be used after this event occurs. -app.on(ElectronAppChannel.Ready, () => { - if (isDuplicateInstance) { - return; - } - - readyTime = now() - launchTime; - - createWindow(); - +function createTray() { appTray = new Tray(appIconPath); const contextMenu = Menu.buildFromTemplate([ @@ -176,22 +166,15 @@ app.on(ElectronAppChannel.Ready, () => { // accelerator: 'Q', // selector: 'terminate:', click: () => { - // 로그아웃 후 로그인화면. - const options = { - type: 'question', - buttons: ['취소', '로그아웃'], - defaultId: 2, - title: 'Question', - message: '로그아웃', - detail: '로그아웃 하시겠습니까?' - // checkboxLabel: 'Remember my answer', - // checkboxChecked: true, - }; - const choice = dialog.showMessageBoxSync(null, options); - if (1 === choice) { - // logout - appWindow.browserWindow.webContents.send(ChatChannel.OpenRoom); - } + appWindow.browserWindow.webContents.send(MessengerChannel.Logout); + } + }, + { + label: '설정', + // accelerator: 'Q', + // selector: 'terminate:', + click: () => { + appWindow.browserWindow.webContents.send(MessengerChannel.ShowSetting); } }, { label: '버전', submenu: [{ label: 'Ver. ' + app.getVersion() }] }, @@ -212,6 +195,21 @@ app.on(ElectronAppChannel.Ready, () => { appTray.on('click', () => { appWindow.isVisible() ? appWindow.hide() : appWindow.show(); }); +} + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +// Some APIs can only be used after this event occurs. +app.on(ElectronAppChannel.Ready, () => { + if (isDuplicateInstance) { + return; + } + + readyTime = now() - launchTime; + + createWindow(); + + createTray(); notificationService = new ElectronNotificationService({ width: 340, diff --git a/projects/ucap-webmessenger-app/src/app/services/app.service.ts b/projects/ucap-webmessenger-app/src/app/services/app.service.ts index d52cdadf..4cb57f1e 100644 --- a/projects/ucap-webmessenger-app/src/app/services/app.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/app.service.ts @@ -5,6 +5,7 @@ import { DeviceType } from '@ucap-webmessenger/core'; import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types'; import { AppNotificationService } from './notification.service'; import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native'; +import { AppNativeService } from './native.service'; @Injectable() export class AppService { @@ -12,6 +13,7 @@ export class AppService { private enviromentUtilService: EnviromentUtilService, private sessionStorageService: SessionStorageService, private appNotificationService: AppNotificationService, + private appNativeService: AppNativeService, @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService ) {} @@ -32,10 +34,11 @@ export class AppService { this.sessionStorageService.set( KEY_ENVIRONMENTS_INFO, { - deviceType, + deviceType } ); + this.appNativeService.subscribe(); this.appNotificationService.subscribe(); this.nativeService.postAppInit(); resolve(); diff --git a/projects/ucap-webmessenger-app/src/app/services/index.ts b/projects/ucap-webmessenger-app/src/app/services/index.ts index 9e6d24ef..699b607c 100644 --- a/projects/ucap-webmessenger-app/src/app/services/index.ts +++ b/projects/ucap-webmessenger-app/src/app/services/index.ts @@ -2,10 +2,12 @@ import { AppService } from './app.service'; import { AppAuthenticationService } from './authentication.service'; import { AppLoaderService } from './loader.service'; import { AppNotificationService } from './notification.service'; +import { AppNativeService } from './native.service'; export const SERVICES = [ AppService, AppAuthenticationService, AppLoaderService, - AppNotificationService + AppNotificationService, + AppNativeService ]; diff --git a/projects/ucap-webmessenger-app/src/app/services/native.service.ts b/projects/ucap-webmessenger-app/src/app/services/native.service.ts new file mode 100644 index 00000000..b5ed1a91 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/services/native.service.ts @@ -0,0 +1,25 @@ +import { Injectable, Inject } from '@angular/core'; +import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native'; +import { Store } from '@ngrx/store'; +import { NGXLogger } from 'ngx-logger'; + +import * as AuthenticationStore from '@app/store/account/authentication'; + +@Injectable({ + providedIn: 'root' +}) +export class AppNativeService { + constructor( + @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, + private store: Store, + private logger: NGXLogger + ) {} + + subscribe(): void { + this.nativeService.logout().subscribe(() => { + this.store.dispatch(AuthenticationStore.logout()); + }); + this.nativeService.changeStatus().subscribe(statusCode => {}); + this.nativeService.showSetting().subscribe(() => {}); + } +} 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 42a40760..0a0396b7 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 @@ -4,7 +4,7 @@ import { NativeService, WindowState, NotificationRequest, - WindowIdle, + WindowIdle } from '@ucap-webmessenger/native'; import { HttpClient } from '@angular/common/http'; import { map, share } from 'rxjs/operators'; @@ -12,10 +12,10 @@ import { TranslateLoader } from '@ngx-translate/core'; import { TranslateLoaderService } from '../translate/browser-loader'; import { NotificationService } from '../notification/notification.service'; import { Injectable } from '@angular/core'; -import { FileUtil } from '@ucap-webmessenger/core'; +import { FileUtil, StatusCode } from '@ucap-webmessenger/core'; @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class BrowserNativeService extends NativeService { private notificationService: NotificationService; @@ -27,6 +27,39 @@ export class BrowserNativeService extends NativeService { this.notificationService.requestPermission(); } + logout(): Observable { + return new Observable(subscriber => { + try { + } catch (error) { + subscriber.error(error); + } finally { + subscriber.complete(); + } + }); + } + + changeStatus(): Observable { + return new Observable(subscriber => { + try { + } catch (error) { + subscriber.error(error); + } finally { + subscriber.complete(); + } + }); + } + + showSetting(): Observable { + return new Observable(subscriber => { + try { + } catch (error) { + subscriber.error(error); + } finally { + subscriber.complete(); + } + }); + } + notify(noti: NotificationRequest): void { this.notificationService.notify(noti, () => { window.focus(); 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 a1fe7ca5..94986d66 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 @@ -6,7 +6,7 @@ import { NativeService, WindowState, NotificationRequest, - WindowIdle, + WindowIdle } from '@ucap-webmessenger/native'; import { share } from 'rxjs/operators'; import { @@ -16,18 +16,29 @@ import { WindowStateChannel, IdleStateChannel, ChatChannel, + MessengerChannel } from '../types/channel.type'; import { Injectable } from '@angular/core'; import { TranslateLoaderService } from '../translate/electron-loader'; import { TranslateLoader } from '@ngx-translate/core'; +import { StatusCode } from '@ucap-webmessenger/core'; @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class ElectronNativeService implements NativeService { private ipcRenderer: typeof ipcRenderer; private remote: typeof remote; + private logoutSubject: Subject | null = null; + private logout$: Observable | null = null; + + private changeStatusSubject: Subject | null = null; + private changeStatus$: Observable | null = null; + + private showSettingSubject: Subject | null = null; + private showSetting$: Observable | null = null; + private windowStateChangedSubject: Subject | null = null; private windowStateChanged$: Observable | null = null; @@ -39,6 +50,47 @@ export class ElectronNativeService implements NativeService { postAppInit(): void {} + logout(): Observable { + if (!this.logoutSubject) { + this.logoutSubject = new Subject(); + this.logout$ = this.logoutSubject.asObservable().pipe(share()); + } + + this.ipcRenderer.on(MessengerChannel.Logout, (event: any) => { + this.logoutSubject.next(); + }); + return this.logout$; + } + + changeStatus(): Observable { + if (!this.changeStatusSubject) { + this.changeStatusSubject = new Subject(); + this.changeStatus$ = this.changeStatusSubject + .asObservable() + .pipe(share()); + } + + this.ipcRenderer.on( + MessengerChannel.ChangeStatus, + (event: any, statusCode: StatusCode) => { + this.changeStatusSubject.next(statusCode); + } + ); + return this.changeStatus$; + } + + showSetting(): Observable { + if (!this.showSettingSubject) { + this.showSettingSubject = new Subject(); + this.showSetting$ = this.showSettingSubject.asObservable().pipe(share()); + } + + this.ipcRenderer.on(MessengerChannel.ShowSetting, (event: any) => { + this.showSettingSubject.next(); + }); + return this.showSetting$; + } + notify(noti: NotificationRequest): void { this.ipcRenderer.send(NotificationChannel.Notify, noti); } diff --git a/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts b/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts index 3d93aac3..2b3aa1e1 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts @@ -1,27 +1,33 @@ +export enum MessengerChannel { + Logout = 'UCAP::messenger::logout', + ChangeStatus = 'UCAP::messenger::changeStatus', + ShowSetting = 'UCAP::messenger::showSetting' +} + export enum ChatChannel { - OpenRoom = 'UCAP::chat::openRoom', + OpenRoom = 'UCAP::chat::openRoom' } export enum NotificationChannel { Notify = 'UCAP::notification::notify', - CloseAllNotify = 'UCAP::notification::closeAllNotify', + CloseAllNotify = 'UCAP::notification::closeAllNotify' } export enum UpdaterChannel { - Check = 'UCAP::updater::check', + Check = 'UCAP::updater::check' } export enum FileChannel { ShowImageViewer = 'UCAP::file::showImageViewer', SaveFile = 'UCAP::file::saveFile', - ReadFile = 'UCAP::file::readFile', + ReadFile = 'UCAP::file::readFile' } export enum WindowStateChannel { - Changed = 'UCAP::windowState::windowStateChanged', + Changed = 'UCAP::windowState::windowStateChanged' } export enum IdleStateChannel { Changed = 'UCAP::idleState::changed', - StartCheck = 'UCAP::idleState::startCheck', + StartCheck = 'UCAP::idleState::startCheck' } 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 af261391..29a7491e 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -4,10 +4,15 @@ import { WindowState } from '../types/window-state.type'; import { WindowIdle } from '../types/window-idle.type'; import { NotificationRequest } from '../models/notification'; import { TranslateLoader } from '@ngx-translate/core'; +import { StatusCode } from '@ucap-webmessenger/core'; export abstract class NativeService { abstract postAppInit(): void; + abstract logout(): Observable; + abstract changeStatus(): Observable; + abstract showSetting(): Observable; + abstract notify(noti: NotificationRequest): void; abstract closeAllNotify(): void; From 81c3cbe43ad65e587a002e5964de9a59139e03cb Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 19 Nov 2019 18:43:49 +0900 Subject: [PATCH 3/4] initialization of logout is modified --- .../store/account/authentication/actions.ts | 4 ++ .../store/account/authentication/effects.ts | 40 +++++++++++++------ .../store/account/authentication/reducers.ts | 11 ++++- .../src/app/store/messenger/chat/reducers.ts | 8 ++++ .../src/app/store/messenger/event/reducers.ts | 5 ++- .../app/store/messenger/option/reducers.ts | 2 +- .../src/app/store/messenger/query/reducers.ts | 2 +- .../src/app/store/messenger/room/reducers.ts | 5 ++- .../app/store/messenger/status/reducers.ts | 2 +- .../src/app/store/messenger/sync/reducers.ts | 8 ++++ .../src/app/store/setting/company/reducers.ts | 9 +++++ .../store/setting/version-info/reducers.ts | 8 ++++ 12 files changed, 84 insertions(+), 20 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts index b7b9849c..ec4aa37f 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts @@ -66,6 +66,10 @@ export const logoutConfirmationDismiss = createAction( '[Account::Authentication] Logout Confirmation Dismiss' ); +export const logoutInitialize = createAction( + '[Account::Authentication] Logout Initialize' +); + export const postLogin = createAction( '[Account::Authentication] Post Login', props<{ diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts index 331398e1..90100265 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts @@ -1,4 +1,4 @@ -import { Injectable, Inject } from '@angular/core'; +import { Injectable, Inject, NgZone } from '@angular/core'; import { Router } from '@angular/router'; import { of, Observable } from 'rxjs'; @@ -36,7 +36,8 @@ import { changePasswordFailure, changePasswordSuccess, increaseLoginFailCount, - initialLoginFailCount + initialLoginFailCount, + logoutInitialize } from './actions'; import { LoginInfo, @@ -52,6 +53,7 @@ import { ServiceProtocolService, UserPasswordSetResponse } from '@ucap-webmessenger/protocol-service'; +import { AuthenticationProtocolService } from '@ucap-webmessenger/protocol-authentication'; @Injectable() export class Effects { @@ -122,21 +124,33 @@ export class Effects { this.actions$.pipe( ofType(loginRedirect), tap(authed => { - this.router.navigate(['/account/login']); + this.ngZone.run(() => { + this.router.navigate(['/account/login']).then(() => { + this.store.dispatch(logoutInitialize()); + location.reload(); + }); + }); }) ), { dispatch: false } ); - logout$ = createEffect(() => - this.actions$.pipe( - ofType(logout), - map(action => action), - map(() => { - this.appAuthenticationService.logout(); - return loginRedirect(); - }) - ) + logout$ = createEffect( + () => { + return this.actions$.pipe( + ofType(logout), + switchMap(action => { + return this.authenticationProtocolService.logout({}).pipe( + map(res => { + this.appAuthenticationService.logout(); + this.store.dispatch(loginRedirect()); + }), + catchError(error => of(error)) + ); + }) + ); + }, + { dispatch: false } ); logoutConfirmation$ = createEffect(() => @@ -288,11 +302,13 @@ export class Effects { constructor( private actions$: Actions, + private ngZone: NgZone, private router: Router, private store: Store, private sessionStorageService: SessionStorageService, private piService: PiService, private appAuthenticationService: AppAuthenticationService, + private authenticationProtocolService: AuthenticationProtocolService, private serviceProtocolService: ServiceProtocolService, private dialogService: DialogService, @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts index 1f91456d..a00d9ba7 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts @@ -3,7 +3,9 @@ import { State, initialState } from './state'; import { loginSuccess, increaseLoginFailCount, - initialLoginFailCount + initialLoginFailCount, + logout, + logoutInitialize } from './actions'; export const reducer = createReducer( @@ -21,10 +23,17 @@ export const reducer = createReducer( loginFailCount: state.loginFailCount + 1 }; }), + on(initialLoginFailCount, (state, action) => { return { ...state, loginFailCount: 0 }; + }), + + on(logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts index 7dbb464e..4e2d4aab 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts @@ -11,6 +11,8 @@ import { clearRightDrawer } from './actions'; +import * as AuthenticationStore from '@app/store/account/authentication'; + export const reducer = createReducer( initialState, on(selectedRoom, (state, action) => { @@ -64,5 +66,11 @@ export const reducer = createReducer( ...state, selectedRightDrawer: null }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts index a6706e54..418faec2 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts @@ -128,12 +128,13 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(ChatStore.clearSelectedRoom, (state, action) => { return { ...initialState }; }), - on(ChatStore.clearSelectedRoom, (state, action) => { + + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts index df652195..148e07aa 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts @@ -17,7 +17,7 @@ export const reducer = createReducer( reg: action.res }; }), - on(AuthenticationStore.logout, (state, action) => { + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts index 4e26fb20..fecef243 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts @@ -49,7 +49,7 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts index e33bc262..aa09416f 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts @@ -64,12 +64,13 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(ChatStore.clearSelectedRoom, (state, action) => { return { ...initialState }; }), - on(ChatStore.clearSelectedRoom, (state, action) => { + + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; 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 97e46b0f..c65060d2 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 @@ -42,7 +42,7 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; 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 6e9ad92b..e253f0de 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 @@ -30,6 +30,8 @@ import * as RoomStore from '@app/store/messenger/room'; import { RoomInfo } from '@ucap-webmessenger/protocol-room'; import { StringUtil } from '@ucap-webmessenger/ui'; +import * as AuthenticationStore from '@app/store/account/authentication'; + export const reducer = createReducer( initialState, on(buddy2Success, (state, action) => { @@ -283,5 +285,11 @@ export const reducer = createReducer( ...state, buddy2: adapterBuddy2.upsertOne(userInfo, { ...state.buddy2 }) }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts index 53a9e594..18e6202e 100644 --- a/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts @@ -1,4 +1,7 @@ import { createReducer, on } from '@ngrx/store'; + +import * as AuthenticationStore from '@app/store/account/authentication'; + import { initialState } from './state'; import { companyListSuccess } from './actions'; @@ -9,5 +12,11 @@ export const reducer = createReducer( ...state, companyList: action.companyList }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts index b924cee4..dc00e708 100644 --- a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts @@ -2,6 +2,8 @@ import { createReducer, on } from '@ngrx/store'; import { initialState } from './state'; import { versionInfo2Success } from './actions'; +import * as AuthenticationStore from '@app/store/account/authentication'; + export const reducer = createReducer( initialState, on(versionInfo2Success, (state, action) => { @@ -19,5 +21,11 @@ export const reducer = createReducer( fileDownloadUrl: action.res.downloadUrl, serverIp: action.res.serverIp }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); From 92129ef2d78bc88b1c827c303f51bf7832aca109 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 19 Nov 2019 19:03:58 +0900 Subject: [PATCH 4/4] logout notification is modified --- .../src/app/services/notification.service.ts | 2 +- .../src/app/store/account/authentication/effects.ts | 8 +++----- 2 files changed, 4 insertions(+), 6 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 d89323af..b53ea095 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -127,7 +127,7 @@ export class AppNotificationService { default: break; } - this.store.dispatch(AuthenticationStore.logout()); + this.store.dispatch(AuthenticationStore.loginRedirect()); }) ) .subscribe(); diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts index 90100265..33ef6d5c 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts @@ -125,10 +125,9 @@ export class Effects { ofType(loginRedirect), tap(authed => { this.ngZone.run(() => { - this.router.navigate(['/account/login']).then(() => { - this.store.dispatch(logoutInitialize()); - location.reload(); - }); + this.appAuthenticationService.logout(); + this.store.dispatch(logoutInitialize()); + location.href = this.router.parseUrl('/account/login').toString(); }); }) ), @@ -142,7 +141,6 @@ export class Effects { switchMap(action => { return this.authenticationProtocolService.logout({}).pipe( map(res => { - this.appAuthenticationService.logout(); this.store.dispatch(loginRedirect()); }), catchError(error => of(error))