Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): reset voice and layout stores per account

Hampus43e884c04c3b
diff --git a/fluxer_app/src/features/ui/state/Dimension.ts b/fluxer_app/src/features/ui/state/Dimension.ts
index 3f661e474..238213f3f 100644
--- a/fluxer_app/src/features/ui/state/Dimension.ts
+++ b/fluxer_app/src/features/ui/state/Dimension.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {action, makeObservable, observable} from 'mobx';
const BOTTOM_TOLERANCE = 2;
@@ -40,6 +41,7 @@ class Dimension {
updateGuildDimensions: action,
updateGuildListDimensions: action,
forgetChannelDimensions: action,
+ reset: action,
});
}
@@ -127,6 +129,16 @@ class Dimension {
handleCallCreate(channelId: string): void {
this.forgetChannelDimensions(channelId);
}
+
+ reset(): void {
+ this.channelDimensions.clear();
+ this.guildDimensions.clear();
+ this.guildListDimensions.set({scrollTop: 0});
+ }
}
-export default new Dimension();
+const dimension = new Dimension();
+
+ResettableStates.register(dimension, () => dimension.reset());
+
+export default dimension;
diff --git a/fluxer_app/src/features/voice/VoiceAccountLifecycle.ts b/fluxer_app/src/features/voice/VoiceAccountLifecycle.ts
index a7ab9600d..f79e12a5b 100644
--- a/fluxer_app/src/features/voice/VoiceAccountLifecycle.ts
+++ b/fluxer_app/src/features/voice/VoiceAccountLifecycle.ts
@@ -30,6 +30,7 @@ function snapshotToRestoreAfterExit(
export async function leaveVoiceChannelForAccountExit(request: VoiceAccountExitRequest): Promise<void> {
const retained = snapshotToRestoreAfterExit(request);
await MediaEngine.disconnectFromVoiceChannel('user');
+ MediaEngine.dismissFailedVoiceConnection();
if (retained !== null) {
VoiceSessionRestore.saveSnapshot(retained);
}
diff --git a/fluxer_app/src/features/voice/components/voice_participant_tile/LastFrameSnapshotCache.ts b/fluxer_app/src/features/voice/components/voice_participant_tile/LastFrameSnapshotCache.ts
index 4560a4276..b736b186f 100644
--- a/fluxer_app/src/features/voice/components/voice_participant_tile/LastFrameSnapshotCache.ts
+++ b/fluxer_app/src/features/voice/components/voice_participant_tile/LastFrameSnapshotCache.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {videoElementHasRenderedFrame} from '@app/features/voice/components/VideoElementFrameState';
import {Store} from '@app/features/voice/engine/Store';
@@ -123,6 +124,21 @@ class LastFrameSnapshotCache extends Store {
if (!dataUrl) return;
this.retainSnapshot(key, dataUrl);
}
+
+ clear(): void {
+ const revoked = Array.from(this.snapshots.values());
+ this.update(() => {
+ this.snapshots.clear();
+ });
+ this.captureIds.clear();
+ for (const url of revoked) {
+ revokeSnapshotUrl(url);
+ }
+ }
}
-export default new LastFrameSnapshotCache();
+const lastFrameSnapshotCache = new LastFrameSnapshotCache();
+
+ResettableStates.register(lastFrameSnapshotCache, () => lastFrameSnapshotCache.clear());
+
+export default lastFrameSnapshotCache;
diff --git a/fluxer_app/src/features/voice/state/CallInitiator.ts b/fluxer_app/src/features/voice/state/CallInitiator.ts
index 0b5c369b1..ce0fc1b14 100644
--- a/fluxer_app/src/features/voice/state/CallInitiator.ts
+++ b/fluxer_app/src/features/voice/state/CallInitiator.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {makeAutoObservable} from 'mobx';
class CallInitiator {
@@ -30,6 +31,14 @@ class CallInitiator {
clearChannel(channelId: string): void {
this.initiatedRecipients.delete(channelId);
}
+
+ reset(): void {
+ this.initiatedRecipients.clear();
+ }
}
-export default new CallInitiator();
+const callInitiator = new CallInitiator();
+
+ResettableStates.register(callInitiator, () => callInitiator.reset());
+
+export default callInitiator;
diff --git a/fluxer_app/src/features/voice/state/CallState.ts b/fluxer_app/src/features/voice/state/CallState.ts
index c92651fd5..ca59ec0a5 100644
--- a/fluxer_app/src/features/voice/state/CallState.ts
+++ b/fluxer_app/src/features/voice/state/CallState.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import MediaEngine from '@app/features/voice/engine/MediaEngineFacade';
import CallInitiator from '@app/features/voice/state/CallInitiator';
import {
@@ -120,6 +121,15 @@ class CallState {
}
}
}
+
+ reset(): void {
+ this.snapshot = createCallStateSnapshot();
+ this.calls.clear();
+ }
}
-export default new CallState();
+const callState = new CallState();
+
+ResettableStates.register(callState, () => callState.reset());
+
+export default callState;
diff --git a/fluxer_app/src/features/voice/state/CompactVoiceCallHeight.ts b/fluxer_app/src/features/voice/state/CompactVoiceCallHeight.ts
index 91c7bb83a..9ad3b901d 100644
--- a/fluxer_app/src/features/voice/state/CompactVoiceCallHeight.ts
+++ b/fluxer_app/src/features/voice/state/CompactVoiceCallHeight.ts
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import AppStorage from '@app/features/platform/state/PersistentStorage';
+import AppStorage, {subscribeAppStorageScope} from '@app/features/platform/state/PersistentStorage';
import {isRecord} from '@fluxer/record_utils/src/RecordGuards';
import {makeAutoObservable} from 'mobx';
@@ -77,6 +77,10 @@ class CompactVoiceCallHeight {
constructor() {
makeAutoObservable(this, {}, {autoBind: true});
+ this.reload();
+ }
+
+ reload(): void {
const initialState = getInitialState();
this.defaultHeight = initialState.defaultHeight;
this.heightsByKey = initialState.heightsByKey;
@@ -133,4 +137,8 @@ export function getCompactVoiceCallExpansionKey(channelId: string, callMessageId
export {COMPACT_VOICE_CALL_HEIGHT_MAX, COMPACT_VOICE_CALL_HEIGHT_MIN};
-export default new CompactVoiceCallHeight();
+const compactVoiceCallHeight = new CompactVoiceCallHeight();
+
+subscribeAppStorageScope(compactVoiceCallHeight.reload);
+
+export default compactVoiceCallHeight;
diff --git a/fluxer_app/src/features/voice/state/EntranceSoundLibrary.ts b/fluxer_app/src/features/voice/state/EntranceSoundLibrary.ts
index 30bdd4cdd..e99284df0 100644
--- a/fluxer_app/src/features/voice/state/EntranceSoundLibrary.ts
+++ b/fluxer_app/src/features/voice/state/EntranceSoundLibrary.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {Endpoints} from '@app/features/app/constants/Endpoints';
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {
type EntranceSoundScope,
getEntranceSoundFallbackScopes,
@@ -177,6 +178,18 @@ class EntranceSoundLibrary {
this.selections = next;
});
}
+
+ reset(): void {
+ this.sounds = {};
+ this.selections = {};
+ this.loaded = false;
+ this.loading = false;
+ this.loadPromise = null;
+ }
}
-export default new EntranceSoundLibrary();
+const entranceSoundLibrary = new EntranceSoundLibrary();
+
+ResettableStates.register(entranceSoundLibrary, () => entranceSoundLibrary.reset());
+
+export default entranceSoundLibrary;