From 3d1c1f20dce945af9f1f6f6effe50a8cd7a8484e Mon Sep 17 00:00:00 2001 From: talksik Date: Sun, 19 Jun 2022 14:14:50 -0500 Subject: [PATCH] bug where if someone totally quit or disconnected, need to remove them as well --- .../src/providers/ConversationProvider.tsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/desktop/src/providers/ConversationProvider.tsx b/packages/desktop/src/providers/ConversationProvider.tsx index 9dac84a..341b656 100644 --- a/packages/desktop/src/providers/ConversationProvider.tsx +++ b/packages/desktop/src/providers/ConversationProvider.tsx @@ -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(