Adding remove messages to persistence layer (#5066)

This commit is contained in:
Joseph Insalaco 2024-06-26 20:44:40 -04:00 committed by GitHub
parent 8687163cca
commit f8bc6cf998
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 4 deletions

View file

@ -28,6 +28,7 @@ export const roomsReducer = (state = initialState, action: any) => {
...initialState
};
}
case Types.UPDATE_ROOMS: {
const rooms = {
...state.rooms
@ -52,6 +53,7 @@ export const roomsReducer = (state = initialState, action: any) => {
return { ...state, rooms };
}
case Types.JOIN_ROOM: {
const { roomInfo } = action;
const { joined, rooms, sortGamesBy, sortUsersBy } = state;
@ -87,6 +89,7 @@ export const roomsReducer = (state = initialState, action: any) => {
},
}
}
case Types.LEAVE_ROOM: {
const { roomId } = action;
const { joined, messages } = state;
@ -109,6 +112,7 @@ export const roomsReducer = (state = initialState, action: any) => {
messages: _messages,
}
}
case Types.ADD_MESSAGE: {
const { roomId, message } = action;
const { messages } = state;
@ -134,6 +138,7 @@ export const roomsReducer = (state = initialState, action: any) => {
}
}
// @TODO improve this reducer, likely by improving the store model
case Types.UPDATE_GAMES: {
const { roomId, games } = action;
const { rooms, sortGamesBy } = state;
@ -196,6 +201,7 @@ export const roomsReducer = (state = initialState, action: any) => {
}
}
}
case Types.USER_JOINED: {
const { roomId, user } = action;
const { rooms, sortUsersBy } = state;
@ -220,6 +226,7 @@ export const roomsReducer = (state = initialState, action: any) => {
}
};
}
case Types.USER_LEFT: {
const { roomId, name } = action;
const { rooms } = state;
@ -238,6 +245,7 @@ export const roomsReducer = (state = initialState, action: any) => {
}
};
}
case Types.SORT_GAMES: {
const { field, order, roomId } = action;
const { rooms } = state;
@ -264,6 +272,36 @@ export const roomsReducer = (state = initialState, action: any) => {
sortGamesBy
}
}
case Types.REMOVE_MESSAGES: {
const { name, amount, roomId } = action;
const { messages } = state;
let amountRemoved = 0;
return {
...state,
messages: {
...messages,
[roomId]: messages[roomId]
.reverse()
.filter(({ message }) => {
if (amount === amountRemoved) {
return true;
}
const keep = message.indexOf(`${name}:`) !== 0;
if (!keep) {
amountRemoved++;
}
return keep;
})
.reverse()
}
}
}
default:
return state;
}