Skip to content

Commit 180859a

Browse files
committed
Handle reconnections and clearing of selections
1 parent 9484194 commit 180859a

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

packages/app/src/app/overmind/namespaces/live/actions.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,21 @@ export const onFollow: Action<{
374374
actions.live.revealViewRange({ liveUserId });
375375
};
376376

377+
export const onUserLeft: Action<{
378+
liveUserId: string;
379+
}> = ({ state, actions }, { liveUserId }) => {
380+
if (!state.live.roomInfo) {
381+
return;
382+
}
383+
384+
if (state.live.followingUserId && state.live.followingUserId === liveUserId) {
385+
// Unfollow user if they are the one who left
386+
actions.live.onStopFollow();
387+
}
388+
389+
actions.live.internal.clearUserSelections(liveUserId);
390+
};
391+
377392
export const onStopFollow: Action = ({ state, effects, actions }) => {
378393
if (!state.live.roomInfo) {
379394
return;

packages/app/src/app/overmind/namespaces/live/liveMessageOperators.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { logError } from '@codesandbox/common/lib/utils/analytics';
1717
export const onJoin: Operator<LiveMessage<{
1818
status: 'connected';
1919
live_user_id: string;
20-
}>> = mutate(({ effects, state }, { data }) => {
20+
}>> = mutate(({ effects, actions, state }, { data }) => {
2121
state.live.liveUserId = data.live_user_id;
2222

2323
// Show message to confirm that you've joined a live session if you're not the owner
@@ -26,9 +26,15 @@ export const onJoin: Operator<LiveMessage<{
2626
}
2727

2828
if (state.live.reconnecting) {
29+
// We reconnected!
2930
effects.live.getAllClients().forEach(client => {
3031
client.serverReconnect();
3132
});
33+
34+
if (state.live.roomInfo) {
35+
// Clear all user selections
36+
actions.live.internal.clearUserSelections(null);
37+
}
3238
}
3339

3440
state.live.reconnecting = false;
@@ -129,11 +135,6 @@ export const onUserLeft: Operator<LiveMessage<{
129135
return;
130136
}
131137

132-
if (state.live.followingUserId === data.left_user_id) {
133-
// Unfollow user if they are the one who left
134-
actions.live.onStopFollow();
135-
}
136-
137138
if (!state.live.notificationsHidden) {
138139
const { users } = state.live.roomInfo;
139140
const user = users ? users.find(u => u.id === data.left_user_id) : null;
@@ -150,7 +151,7 @@ export const onUserLeft: Operator<LiveMessage<{
150151
}
151152
}
152153

153-
actions.live.internal.clearUserSelections(data.left_user_id);
154+
actions.live.onUserLeft({ liveUserId: data.left_user_id });
154155

155156
const users = camelizeKeys(data.users) as LiveUser[];
156157

0 commit comments

Comments
 (0)