clean up data structures

This commit is contained in:
seavor 2026-04-16 17:14:49 -05:00
parent 53639a8448
commit d04aa83258
9 changed files with 61 additions and 42 deletions

View file

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