mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 02:53:56 -07:00
clean up data structures
This commit is contained in:
parent
53639a8448
commit
d04aa83258
9 changed files with 61 additions and 42 deletions
|
|
@ -69,14 +69,21 @@ export const roomsSlice = createSlice({
|
|||
const { roomId } = action.payload;
|
||||
|
||||
delete state.joinedRoomIds[roomId];
|
||||
delete state.joinedGameIds[roomId];
|
||||
delete state.messages[roomId];
|
||||
|
||||
const room = state.rooms[roomId];
|
||||
if (room) {
|
||||
room.games = {};
|
||||
room.users = {};
|
||||
}
|
||||
},
|
||||
|
||||
addMessage: (state, action: PayloadAction<{ roomId: number; message: Enriched.Message }>) => {
|
||||
const { roomId, message } = action.payload;
|
||||
|
||||
const existing = state.messages[roomId] ?? [];
|
||||
const normalized = normalizeUserMessage({ ...message, timeReceived: Date.now() });
|
||||
const normalized = normalizeUserMessage(message);
|
||||
const next =
|
||||
existing.length >= MAX_ROOM_MESSAGES
|
||||
? [...existing.slice(existing.length - MAX_ROOM_MESSAGES + 1), normalized]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue