Skip to content

Commit ab2e9f6

Browse files
committed
Fix classroom quirks with autorization
1 parent 3ff1096 commit ab2e9f6

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

packages/app/src/app/overmind/namespaces/editor/internalActions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ export const initializeLiveSandbox: AsyncAction<Sandbox> = async (
6464
return;
6565
}
6666

67-
await actions.live.internal.disconnect();
67+
if (
68+
// If the joinSource is /live/ and the user is only a viewer,
69+
// we won't get the roomId and the user will disconnect automatically,
70+
// we want to prevent this by only re-initializing the live session on joinSource === 'sandbox'. Because
71+
// for joinSource === 'sandbox' we know for sure that the user will get a roomId if they have permissions
72+
// to join
73+
state.live.joinSource === 'sandbox'
74+
) {
75+
await actions.live.internal.disconnect();
76+
}
6877
}
6978

7079
if (sandbox.roomId) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export const roomJoined: AsyncAction<{
6363
await effects.vscode.initialized;
6464
await effects.vscode.closeAllTabs();
6565

66+
state.live.joinSource = 'live';
67+
6668
if (state.live.isLive) {
6769
actions.live.internal.disconnect();
6870
}
@@ -81,6 +83,7 @@ export const roomJoined: AsyncAction<{
8183

8284
await actions.internal.setCurrentSandbox(sandbox);
8385

86+
actions.editor.listenToSandboxChanges({ sandboxId: sandbox.id });
8487
const items = getItems(state);
8588
const defaultItem = items.find(i => i.defaultOpen) || items[0];
8689

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const reset: Action = ({ state, actions, effects }) => {
4343
state.live.error = null;
4444
state.live.isLoading = false;
4545
state.live.roomInfo = null;
46+
state.live.joinSource = 'sandbox';
4647
effects.live.resetClients();
4748
};
4849

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,15 @@ export const onLiveAddEditor: Operator<LiveMessage<{
535535

536536
export const onLiveRemoveEditor: Operator<LiveMessage<{
537537
editor_user_id: string;
538-
}>> = mutate(({ state }, { _isOwnMessage, data }) => {
538+
}>> = mutate(({ state, actions }, { _isOwnMessage, data }) => {
539539
if (!state.live.roomInfo) {
540540
return;
541541
}
542542

543-
if (!_isOwnMessage) {
544-
const userId = data.editor_user_id;
543+
const userId = data.editor_user_id;
544+
actions.live.internal.clearUserSelections(userId);
545545

546+
if (!_isOwnMessage) {
546547
const editors = state.live.roomInfo.editorIds;
547548
const newEditors = editors.filter(id => id !== userId);
548549

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ type State = {
1616
followingUserId: string | null;
1717
liveUserId: string | null;
1818
roomInfo: RoomInfo | null;
19+
/**
20+
* Whether we joined from /s/ or from /live/
21+
*/
22+
joinSource: 'sandbox' | 'live';
1923
currentSelection: UserSelection | null;
2024
currentViewRange: UserViewRange | null;
2125
liveUser: Derive<State, LiveUser | null>;
@@ -42,6 +46,7 @@ export const state: State = {
4246
roomInfo: null,
4347
currentSelection: null,
4448
currentViewRange: null,
49+
joinSource: 'sandbox',
4550
liveUser: currentState =>
4651
currentState.roomInfo?.users.find(u => u.id === currentState.liveUserId) ||
4752
null,

0 commit comments

Comments
 (0)