From cf1f4f12a98660b27328f05e8a6ba96b48039d49 Mon Sep 17 00:00:00 2001 From: Joseph Insalaco Date: Mon, 29 Jul 2024 13:25:33 -0400 Subject: [PATCH] Updating Session Persistence with all valid persistence calls (#5085) * Updating Session Persistence with all valid persistence calls * Spacing fixes --------- Co-authored-by: Zach H --- webclient/src/store/server/server.actions.ts | 55 ++++++++++++++++++- webclient/src/store/server/server.dispatch.ts | 41 +++++++++++++- .../src/store/server/server.interfaces.ts | 9 +++ webclient/src/store/server/server.reducer.ts | 53 +++++++++++++++++- webclient/src/store/server/server.types.ts | 15 ++++- .../commands/session/accountImage.ts | 6 +- .../websocket/persistence/AdminPresistence.ts | 8 ++- .../persistence/SessionPersistence.ts | 32 ++++++----- 8 files changed, 193 insertions(+), 26 deletions(-) diff --git a/webclient/src/store/server/server.actions.ts b/webclient/src/store/server/server.actions.ts index 45c4d1900..17ab2fa66 100644 --- a/webclient/src/store/server/server.actions.ts +++ b/webclient/src/store/server/server.actions.ts @@ -1,6 +1,4 @@ -import { Type } from 'protobufjs'; import { WebSocketConnectOptions } from 'types'; - import { Types } from './server.types'; export const Actions = { @@ -132,5 +130,56 @@ export const Actions = { }), resetPasswordSuccess: () => ({ type: Types.RESET_PASSWORD_SUCCESS, - }) + }), + reloadConfig: () => ({ + type: Types.RELOAD_CONFIG, + }), + shutdownServer: () => ({ + type: Types.SHUTDOWN_SERVER, + }), + updateServerMessage: () => ({ + type: Types.UPDATE_SERVER_MESSAGE, + }), + accountPasswordChange: () => ({ + type: Types.ACCOUNT_PASSWORD_CHANGE, + }), + accountEditChanged: (user) => ({ + type: Types.ACCOUNT_EDIT_CHANGED, + user, + }), + accountImageChanged: (user) => ({ + type: Types.ACCOUNT_IMAGE_CHANGED, + user, + }), + directMessageSent: (userName, message) => ({ + type: Types.DIRECT_MESSAGE_SENT, + userName, + message, + }), + getUserInfo: (userInfo) => ({ + type: Types.GET_USER_INFO, + userInfo, + }), + notifyUser: (notification) => ({ + type: Types.NOTIFY_USER, + notification, + }), + serverShutdown: (data) => ({ + type: Types.SERVER_SHUTDOWN, + data, + }), + userMessage: (messageData) => ({ + type: Types.USER_MESSAGE, + messageData, + }), + addToList: (list, userName) => ({ + type: Types.ADD_TO_LIST, + list, + userName, + }), + removeFromList: (list, userName) => ({ + type: Types.REMOVE_FROM_LIST, + list, + userName, + }), } diff --git a/webclient/src/store/server/server.dispatch.ts b/webclient/src/store/server/server.dispatch.ts index 364ad8593..50b09ca9c 100644 --- a/webclient/src/store/server/server.dispatch.ts +++ b/webclient/src/store/server/server.dispatch.ts @@ -119,5 +119,44 @@ export const Dispatch = { }, resetPasswordSuccess: () => { store.dispatch(Actions.resetPasswordSuccess()); - } + }, + reloadConfig: () => { + store.dispatch(Actions.reloadConfig()); + }, + shutdownServer: () => { + store.dispatch(Actions.shutdownServer()); + }, + updateServerMessage: () => { + store.dispatch(Actions.updateServerMessage()); + }, + accountPasswordChange: () => { + store.dispatch(Actions.accountPasswordChange()); + }, + accountEditChanged: (user) => { + store.dispatch(Actions.accountEditChanged(user)); + }, + accountImageChanged: (user) => { + store.dispatch(Actions.accountImageChanged(user)); + }, + directMessageSent: (userName, message) => { + store.dispatch(Actions.directMessageSent(userName, message)); + }, + getUserInfo: (userInfo) => { + store.dispatch(Actions.getUserInfo(userInfo)); + }, + notifyUser: (notification) => { + store.dispatch(Actions.notifyUser(notification)) + }, + serverShutdown: (data) => { + store.dispatch(Actions.serverShutdown(data)) + }, + userMessage: (messageData) => { + store.dispatch(Actions.userMessage(messageData)) + }, + addToList: (list, userName) => { + store.dispatch(Actions.addToList(list, userName)) + }, + removeFromList: (list, userName) => { + store.dispatch(Actions.removeFromList(list, userName)) + }, } diff --git a/webclient/src/store/server/server.interfaces.ts b/webclient/src/store/server/server.interfaces.ts index 3e012256a..bd68fc861 100644 --- a/webclient/src/store/server/server.interfaces.ts +++ b/webclient/src/store/server/server.interfaces.ts @@ -1,4 +1,5 @@ import { LogItem, SortBy, User, UserSortField, WebSocketConnectOptions } from 'types'; +import { NotifyUserData, ServerShutdownData, UserMessageData } from 'websocket/events/session/interfaces'; export interface ServerConnectParams { host: string; @@ -49,6 +50,14 @@ export interface ServerState { users: User[]; sortUsersBy: ServerStateSortUsersBy; connectOptions: WebSocketConnectOptions; + messages: { + [userName: string]: UserMessageData[]; + } + userInfo: { + [userName: string]: User; + } + notifications: NotifyUserData[]; + serverShutdown: ServerShutdownData; } export interface ServerStateStatus { diff --git a/webclient/src/store/server/server.reducer.ts b/webclient/src/store/server/server.reducer.ts index 060f512f9..5fd29e47b 100644 --- a/webclient/src/store/server/server.reducer.ts +++ b/webclient/src/store/server/server.reducer.ts @@ -31,6 +31,10 @@ const initialState: ServerState = { order: SortDirection.ASC }, connectOptions: {}, + messages: {}, + userInfo: {}, + notifications: [], + serverShutdown: null, }; export const serverReducer = (state = initialState, action: any) => { @@ -162,7 +166,9 @@ export const serverReducer = (state = initialState, action: any) => { status: { ...status } } } - case Types.UPDATE_USER: { + case Types.UPDATE_USER: + case Types.ACCOUNT_EDIT_CHANGED: + case Types.ACCOUNT_IMAGE_CHANGED: { const { user } = action; return { @@ -227,6 +233,51 @@ export const serverReducer = (state = initialState, action: any) => { } } } + case Types.USER_MESSAGE: { + const { senderName, receiverName } = action.messageData; + const userName = state.user.name === senderName ? receiverName : senderName; + + return { + ...state, + messages: { + ...state.messages, + [userName]: [ + ...state.messages[userName], + action.messageData, + ], + } + }; + } + case Types.GET_USER_INFO: { + const { userInfo } = action; + + return { + ...state, + userInfo: { + ...state.userInfo, + [userInfo.name]: userInfo, + } + }; + } + case Types.NOTIFY_USER: { + const { notification } = action; + + return { + ...state, + notifications: [ + ...state.notifications, + notification + ] + }; + } + case Types.SERVER_SHUTDOWN: { + const { data } = action; + + return { + ...state, + serverShutdown: data, + }; + } default: return state; } diff --git a/webclient/src/store/server/server.types.ts b/webclient/src/store/server/server.types.ts index 336560d14..2a6a63104 100644 --- a/webclient/src/store/server/server.types.ts +++ b/webclient/src/store/server/server.types.ts @@ -34,5 +34,18 @@ export const Types = { RESET_PASSWORD_REQUESTED: '[Server] Reset Password Requested', RESET_PASSWORD_FAILED: '[Server] Reset Password Failed', RESET_PASSWORD_CHALLENGE: '[Server] Reset Password Challenge', - RESET_PASSWORD_SUCCESS: '[Server] Reset Password Success' + RESET_PASSWORD_SUCCESS: '[Server] Reset Password Success', + RELOAD_CONFIG: '[Server] Reload Config', + SHUTDOWN_SERVER: '[Server] Shutdown Server', + UPDATE_SERVER_MESSAGE: '[Server] Update Server Message', + ACCOUNT_PASSWORD_CHANGE: '[Server] Account Password Change', + ACCOUNT_EDIT_CHANGED: '[Server] Account Edit Changed', + ACCOUNT_IMAGE_CHANGED: '[Server] Account Image Changed', + DIRECT_MESSAGE_SENT: '[Server] Direct Message Sent', + GET_USER_INFO: '[Server] Get User Info', + NOTIFY_USER: '[Server] Notify User', + SERVER_SHUTDOWN: '[Server] Server Shutdown', + USER_MESSAGE: '[Server] User Message', + ADD_TO_LIST: '[Server] Add To List', + REMOVE_FROM_LIST: '[Server] Remove From List', }; diff --git a/webclient/src/websocket/commands/session/accountImage.ts b/webclient/src/websocket/commands/session/accountImage.ts index 4add7db13..b735696a9 100644 --- a/webclient/src/websocket/commands/session/accountImage.ts +++ b/webclient/src/websocket/commands/session/accountImage.ts @@ -1,7 +1,9 @@ import webClient from '../../WebClient'; import { SessionPersistence } from '../../persistence'; +import { common } from 'protobufjs'; +import IBytesValue = common.IBytesValue; -export function accountImage(image: unknown): void { +export function accountImage(image: IBytesValue): void { const command = webClient.protobuf.controller.Command_AccountImage.create({ image }); const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountImage.ext': command }); @@ -10,7 +12,7 @@ export function accountImage(image: unknown): void { switch (responseCode) { case webClient.protobuf.controller.Response.ResponseCode.RespOk: - SessionPersistence.accountImageChanged(); + SessionPersistence.accountImageChanged(image); break; case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed: console.log('Not allowed'); diff --git a/webclient/src/websocket/persistence/AdminPresistence.ts b/webclient/src/websocket/persistence/AdminPresistence.ts index 2e03a811a..1fd9c3db6 100644 --- a/webclient/src/websocket/persistence/AdminPresistence.ts +++ b/webclient/src/websocket/persistence/AdminPresistence.ts @@ -1,17 +1,19 @@ +import { ServerDispatch } from 'store'; + export class AdminPersistence { static adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean) { console.log('adjustMod'); } static reloadConfig() { - console.log('reloadConfig'); + ServerDispatch.reloadConfig(); } static shutdownServer() { - console.log('shutdownServer'); + ServerDispatch.shutdownServer(); } static updateServerMessage() { - console.log('updateServerMessage'); + ServerDispatch.updateServerMessage(); } } diff --git a/webclient/src/websocket/persistence/SessionPersistence.ts b/webclient/src/websocket/persistence/SessionPersistence.ts index cda905cf5..62c21268d 100644 --- a/webclient/src/websocket/persistence/SessionPersistence.ts +++ b/webclient/src/websocket/persistence/SessionPersistence.ts @@ -11,6 +11,8 @@ import { } from '../events/session/interfaces'; import NormalizeService from '../utils/NormalizeService'; import { DeckList } from '../../types/deckList'; +import { common } from 'protobufjs'; +import IBytesValue = common.IBytesValue; export class SessionPersistence { static initialized() { @@ -156,23 +158,23 @@ export class SessionPersistence { } static accountPasswordChange(): void { - console.log('accountPassword'); + ServerDispatch.accountPasswordChange(); } static accountEditChanged(realName?: string, email?: string, country?: string): void { - console.log('accountEditChange'); + ServerDispatch.accountEditChanged({ realName, email, country }); } - static accountImageChanged(): void { - console.log('accountImageChanged'); + static accountImageChanged(avatarBmp: IBytesValue): void { + ServerDispatch.accountImageChanged({ avatarBmp }); } static directMessageSent(userName: string, message: string): void { - console.log('directMessageSent'); + ServerDispatch.directMessageSent(userName, message); } - static getUserInfo(userInfo: string) { - console.log('getUserInfo'); + static getUserInfo(userInfo: User) { + ServerDispatch.getUserInfo(userInfo); } static getGamesOfUser(userName: string, response: any): void { @@ -183,28 +185,28 @@ export class SessionPersistence { console.log('gameJoined', gameJoinedData); } - static notifyUser(payload: NotifyUserData): void { - console.log('notifyUser', payload); + static notifyUser(notification: NotifyUserData): void { + ServerDispatch.notifyUser(notification); } static playerPropertiesChanged(payload: PlayerGamePropertiesData): void { console.log('playerPropertiesChanged', payload); } - static serverShutdown(payload: ServerShutdownData): void { - console.log('serverShutdown', payload); + static serverShutdown(data: ServerShutdownData): void { + ServerDispatch.serverShutdown(data); } - static userMessage(payload: UserMessageData): void { - console.log('userMessage', payload); + static userMessage(messageData: UserMessageData): void { + ServerDispatch.userMessage(messageData); } static addToList(list: string, userName: string): void { - console.log('addToList', list, userName); + ServerDispatch.addToList(list, userName) } static removeFromList(list: string, userName: string): void { - console.log('removeFromList', list, userName); + ServerDispatch.removeFromList(list, userName); } static deckDelete(deckId: number): void {