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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 193 additions and 26 deletions

View file

@ -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,
}),
}

View file

@ -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))
},
}

View file

@ -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 {

View file

@ -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;
}

View file

@ -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',
};