bug where if someone totally quit or disconnected, need to remove them as well

This commit is contained in:
talksik
2022-06-19 14:14:50 -05:00
parent a90da3f4b9
commit 3d1c1f20dc
@@ -7,6 +7,7 @@ import {
ServerRequestChannels,
ServerResponseChannels,
SomeoneConnectedResponse,
SomeoneDisconnectedResponse,
SomeoneTunedResponse,
SomeoneUntunedFromLineResponse,
TuneToLineRequest,
@@ -134,6 +135,26 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
);
}, [$ws, setConversationMap]);
// remove them from the line connected list and tuned list if they are there
$ws.on(
ServerResponseChannels.SOMEONE_DISCONNECTED_FROM_LINE,
(res: SomeoneDisconnectedResponse) => {
setConversationMap((draft) => {
if (!draft[res.lineId]) {
toast.error('there was a problem updating rooms!!!');
return;
}
draft[res.lineId].connectedUserIds = draft[res.lineId].connectedUserIds?.filter(
(userId) => userId !== res.userId,
);
draft[res.lineId].tunedInUsers = draft[res.lineId].tunedInUsers?.filter(
(userId) => userId !== res.userId,
);
});
},
);
// add the conversation to the conversation map/client side cache
// has implications on realtime listening and also the ui on whether or not it's shown
const handleAddConversationCache = useCallback(