Updating Session Persistence with all valid persistence calls (#5085)

* Updating Session Persistence with all valid persistence calls

* Spacing fixes

---------

Co-authored-by: Zach H <zahalpern+github@gmail.com>
This commit is contained in:
Joseph Insalaco
2024-07-29 13:25:33 -04:00
committed by GitHub
parent ef4413633a
commit cf1f4f12a9
8 changed files with 193 additions and 26 deletions

View File

@@ -1,6 +1,4 @@
import { Type } from 'protobufjs';
import { WebSocketConnectOptions } from 'types'; import { WebSocketConnectOptions } from 'types';
import { Types } from './server.types'; import { Types } from './server.types';
export const Actions = { export const Actions = {
@@ -132,5 +130,56 @@ export const Actions = {
}), }),
resetPasswordSuccess: () => ({ resetPasswordSuccess: () => ({
type: Types.RESET_PASSWORD_SUCCESS, 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,
}),
} }

View File

@@ -119,5 +119,44 @@ export const Dispatch = {
}, },
resetPasswordSuccess: () => { resetPasswordSuccess: () => {
store.dispatch(Actions.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))
},
} }

View File

@@ -1,4 +1,5 @@
import { LogItem, SortBy, User, UserSortField, WebSocketConnectOptions } from 'types'; import { LogItem, SortBy, User, UserSortField, WebSocketConnectOptions } from 'types';
import { NotifyUserData, ServerShutdownData, UserMessageData } from 'websocket/events/session/interfaces';
export interface ServerConnectParams { export interface ServerConnectParams {
host: string; host: string;
@@ -49,6 +50,14 @@ export interface ServerState {
users: User[]; users: User[];
sortUsersBy: ServerStateSortUsersBy; sortUsersBy: ServerStateSortUsersBy;
connectOptions: WebSocketConnectOptions; connectOptions: WebSocketConnectOptions;
messages: {
[userName: string]: UserMessageData[];
}
userInfo: {
[userName: string]: User;
}
notifications: NotifyUserData[];
serverShutdown: ServerShutdownData;
} }
export interface ServerStateStatus { export interface ServerStateStatus {

View File

@@ -31,6 +31,10 @@ const initialState: ServerState = {
order: SortDirection.ASC order: SortDirection.ASC
}, },
connectOptions: {}, connectOptions: {},
messages: {},
userInfo: {},
notifications: [],
serverShutdown: null,
}; };
export const serverReducer = (state = initialState, action: any) => { export const serverReducer = (state = initialState, action: any) => {
@@ -162,7 +166,9 @@ export const serverReducer = (state = initialState, action: any) => {
status: { ...status } status: { ...status }
} }
} }
case Types.UPDATE_USER: { case Types.UPDATE_USER:
case Types.ACCOUNT_EDIT_CHANGED:
case Types.ACCOUNT_IMAGE_CHANGED: {
const { user } = action; const { user } = action;
return { 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: default:
return state; return state;
} }

View File

@@ -34,5 +34,18 @@ export const Types = {
RESET_PASSWORD_REQUESTED: '[Server] Reset Password Requested', RESET_PASSWORD_REQUESTED: '[Server] Reset Password Requested',
RESET_PASSWORD_FAILED: '[Server] Reset Password Failed', RESET_PASSWORD_FAILED: '[Server] Reset Password Failed',
RESET_PASSWORD_CHALLENGE: '[Server] Reset Password Challenge', 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',
}; };

View File

@@ -1,7 +1,9 @@
import webClient from '../../WebClient'; import webClient from '../../WebClient';
import { SessionPersistence } from '../../persistence'; 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 command = webClient.protobuf.controller.Command_AccountImage.create({ image });
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountImage.ext': command }); const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountImage.ext': command });
@@ -10,7 +12,7 @@ export function accountImage(image: unknown): void {
switch (responseCode) { switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk: case webClient.protobuf.controller.Response.ResponseCode.RespOk:
SessionPersistence.accountImageChanged(); SessionPersistence.accountImageChanged(image);
break; break;
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed: case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
console.log('Not allowed'); console.log('Not allowed');

View File

@@ -1,17 +1,19 @@
import { ServerDispatch } from 'store';
export class AdminPersistence { export class AdminPersistence {
static adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean) { static adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean) {
console.log('adjustMod'); console.log('adjustMod');
} }
static reloadConfig() { static reloadConfig() {
console.log('reloadConfig'); ServerDispatch.reloadConfig();
} }
static shutdownServer() { static shutdownServer() {
console.log('shutdownServer'); ServerDispatch.shutdownServer();
} }
static updateServerMessage() { static updateServerMessage() {
console.log('updateServerMessage'); ServerDispatch.updateServerMessage();
} }
} }

View File

@@ -11,6 +11,8 @@ import {
} from '../events/session/interfaces'; } from '../events/session/interfaces';
import NormalizeService from '../utils/NormalizeService'; import NormalizeService from '../utils/NormalizeService';
import { DeckList } from '../../types/deckList'; import { DeckList } from '../../types/deckList';
import { common } from 'protobufjs';
import IBytesValue = common.IBytesValue;
export class SessionPersistence { export class SessionPersistence {
static initialized() { static initialized() {
@@ -156,23 +158,23 @@ export class SessionPersistence {
} }
static accountPasswordChange(): void { static accountPasswordChange(): void {
console.log('accountPassword'); ServerDispatch.accountPasswordChange();
} }
static accountEditChanged(realName?: string, email?: string, country?: string): void { static accountEditChanged(realName?: string, email?: string, country?: string): void {
console.log('accountEditChange'); ServerDispatch.accountEditChanged({ realName, email, country });
} }
static accountImageChanged(): void { static accountImageChanged(avatarBmp: IBytesValue): void {
console.log('accountImageChanged'); ServerDispatch.accountImageChanged({ avatarBmp });
} }
static directMessageSent(userName: string, message: string): void { static directMessageSent(userName: string, message: string): void {
console.log('directMessageSent'); ServerDispatch.directMessageSent(userName, message);
} }
static getUserInfo(userInfo: string) { static getUserInfo(userInfo: User) {
console.log('getUserInfo'); ServerDispatch.getUserInfo(userInfo);
} }
static getGamesOfUser(userName: string, response: any): void { static getGamesOfUser(userName: string, response: any): void {
@@ -183,28 +185,28 @@ export class SessionPersistence {
console.log('gameJoined', gameJoinedData); console.log('gameJoined', gameJoinedData);
} }
static notifyUser(payload: NotifyUserData): void { static notifyUser(notification: NotifyUserData): void {
console.log('notifyUser', payload); ServerDispatch.notifyUser(notification);
} }
static playerPropertiesChanged(payload: PlayerGamePropertiesData): void { static playerPropertiesChanged(payload: PlayerGamePropertiesData): void {
console.log('playerPropertiesChanged', payload); console.log('playerPropertiesChanged', payload);
} }
static serverShutdown(payload: ServerShutdownData): void { static serverShutdown(data: ServerShutdownData): void {
console.log('serverShutdown', payload); ServerDispatch.serverShutdown(data);
} }
static userMessage(payload: UserMessageData): void { static userMessage(messageData: UserMessageData): void {
console.log('userMessage', payload); ServerDispatch.userMessage(messageData);
} }
static addToList(list: string, userName: string): void { static addToList(list: string, userName: string): void {
console.log('addToList', list, userName); ServerDispatch.addToList(list, userName)
} }
static removeFromList(list: string, userName: string): void { static removeFromList(list: string, userName: string): void {
console.log('removeFromList', list, userName); ServerDispatch.removeFromList(list, userName);
} }
static deckDelete(deckId: number): void { static deckDelete(deckId: number): void {