A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): reset per-account stores and GIF import on switch
Hampusa3501c846433
diff --git a/fluxer_app/src/features/auth/passkey_migration/PasskeyMigration.ts b/fluxer_app/src/features/auth/passkey_migration/PasskeyMigration.tsindex 6d9f822a5..b82dfd0e4 100644--- a/fluxer_app/src/features/auth/passkey_migration/PasskeyMigration.ts+++ b/fluxer_app/src/features/auth/passkey_migration/PasskeyMigration.ts@@ -2,6 +2,7 @@import {Endpoints} from '@app/features/app/constants/Endpoints';import {readDomainMigrationDiscovery} from '@app/features/app/domain_migration/DomainMigrationBrowser';+import {ResettableStates} from '@app/features/app/state/ResettableStates';import {isPasskeyMigrationOrigin} from '@app/features/auth/passkey_migration/PasskeyMigrationOrigin';import {openPasskeyUpdateModal} from '@app/features/auth/passkey_migration/PasskeyUpdateModal';import {http} from '@app/features/platform/transport/RestTransport';@@ -70,4 +71,8 @@ class PasskeyMigration {}}-export default new PasskeyMigration();+const passkeyMigration = new PasskeyMigration();++ResettableStates.register(passkeyMigration, () => passkeyMigration.clear());++export default passkeyMigration;diff --git a/fluxer_app/src/features/auth/state/AuthSession.ts b/fluxer_app/src/features/auth/state/AuthSession.tsindex 0633162e8..ab7508ac6 100644--- a/fluxer_app/src/features/auth/state/AuthSession.ts+++ b/fluxer_app/src/features/auth/state/AuthSession.ts@@ -1,5 +1,6 @@// SPDX-License-Identifier: AGPL-3.0-or-later+import {ResettableStates} from '@app/features/app/state/ResettableStates';import {AuthSession as AuthSessionModel} from '@app/features/auth/models/AuthSession';import type {AuthSessionResponse} from '@fluxer/schema/src/domains/auth/AuthSchemas';import {makeAutoObservable} from 'mobx';@@ -48,6 +49,16 @@ class AuthSessions {logoutError(): void {this.isDeleteError = true;}++ reset(): void {+ this.authSessions = [];+ this.fetchStatus = 'idle';+ this.isDeleteError = false;+ }}-export default new AuthSessions();+const authSessions = new AuthSessions();++ResettableStates.register(authSessions, () => authSessions.reset());++export default authSessions;diff --git a/fluxer_app/src/features/expressions/state/ExpressionMetadata.ts b/fluxer_app/src/features/expressions/state/ExpressionMetadata.tsindex 68899df14..f21bc8a46 100644--- a/fluxer_app/src/features/expressions/state/ExpressionMetadata.ts+++ b/fluxer_app/src/features/expressions/state/ExpressionMetadata.ts@@ -1,5 +1,6 @@// SPDX-License-Identifier: AGPL-3.0-or-later+import {ResettableStates} from '@app/features/app/state/ResettableStates';import * as ExpressionMetadataCommands from '@app/features/expressions/commands/ExpressionMetadataCommands';import {action, makeAutoObservable, runInAction} from 'mobx';@@ -115,6 +116,17 @@ class ExpressionMetadataState {throw error;}});++ reset(): void {+ this.emojiMetadata = new Map();+ this.stickerMetadata = new Map();+ this.pendingEmojiRequests.clear();+ this.pendingStickerRequests.clear();+ }}-export default new ExpressionMetadataState();+const expressionMetadata = new ExpressionMetadataState();++ResettableStates.register(expressionMetadata, () => expressionMetadata.reset());++export default expressionMetadata;diff --git a/fluxer_app/src/features/expressions/state/ExpressionSource.ts b/fluxer_app/src/features/expressions/state/ExpressionSource.tsindex afe4154b6..ed1891d6c 100644--- a/fluxer_app/src/features/expressions/state/ExpressionSource.ts+++ b/fluxer_app/src/features/expressions/state/ExpressionSource.ts@@ -1,5 +1,6 @@// SPDX-License-Identifier: AGPL-3.0-or-later+import {ResettableStates} from '@app/features/app/state/ResettableStates';import type {ExpressionKind} from '@app/features/expressions/commands/ExpressionMetadataCommands';import {type ExpressionSourceGuild,@@ -47,6 +48,14 @@ class ExpressionSourceStore {private setSource(key: string, state: ExpressionSourceState): void {this.sources = new Map(this.sources).set(key, state);}++ reset(): void {+ this.sources = new Map();+ }}-export default new ExpressionSourceStore();+const expressionSource = new ExpressionSourceStore();++ResettableStates.register(expressionSource, () => expressionSource.reset());++export default expressionSource;diff --git a/fluxer_app/src/features/expressions/state/FavoriteGifImport.ts b/fluxer_app/src/features/expressions/state/FavoriteGifImport.tsindex d3f1d7a26..0095df425 100644--- a/fluxer_app/src/features/expressions/state/FavoriteGifImport.ts+++ b/fluxer_app/src/features/expressions/state/FavoriteGifImport.ts@@ -3,6 +3,7 @@import type {FavoriteGifEntry} from '@app/features/channel/components/pickers/gif/FavoriteGifTypes';import * as FavoriteGifCommands from '@app/features/expressions/commands/FavoriteGifCommands';import FavoriteGif from '@app/features/expressions/state/FavoriteGif';+import {AccountScopedWork} from '@app/features/platform/state/AccountScopedWork';import {MAX_FAVORITE_GIFS} from '@fluxer/constants/src/LimitConstants';import {makeAutoObservable, runInAction} from 'mobx';@@ -25,6 +26,7 @@ class FavoriteGifImport {processedCount = 0;importedCount = 0;skippedCount = 0;+ private run = 0;constructor() {makeAutoObservable(this, {}, {autoBind: true});@@ -36,6 +38,7 @@ class FavoriteGifImport {}reset(): void {+ this.run += 1;this.isRunning = false;this.isDone = false;this.totalToImport = 0;@@ -56,6 +59,7 @@ class FavoriteGifImport {.filter((line) => line.length > 0 && isValidUrl(line));const uniqueUrls = [...new Set(lines)];if (uniqueUrls.length === 0) return;+ const run = this.run;runInAction(() => {this.isRunning = true;this.isDone = false;@@ -91,6 +95,9 @@ class FavoriteGifImport {resolveFailures = urlsToResolve.length;}}+ if (run !== this.run) {+ return;+ }const currentUrls = new Set(FavoriteGif.favoriteGifs.map((entry) => entry.url));const uniqueResolved: Array<FavoriteGifEntry> = [];let resolvedDuplicates = 0;@@ -114,6 +121,9 @@ class FavoriteGifImport {await new Promise<void>((resolve) => setTimeout(resolve, BATCH_DELAY_MS));}}+ if (run !== this.run) {+ return;+ }runInAction(() => {this.isRunning = false;this.isDone = true;@@ -121,4 +131,8 @@ class FavoriteGifImport {}}-export default new FavoriteGifImport();+const favoriteGifImport = new FavoriteGifImport();++AccountScopedWork.registerCancellation(() => favoriteGifImport.reset());++export default favoriteGifImport;diff --git a/fluxer_app/src/features/expressions/state/FavoriteMemes.ts b/fluxer_app/src/features/expressions/state/FavoriteMemes.tsindex af6eabd66..12f0c944b 100644--- a/fluxer_app/src/features/expressions/state/FavoriteMemes.ts+++ b/fluxer_app/src/features/expressions/state/FavoriteMemes.ts@@ -1,5 +1,6 @@// SPDX-License-Identifier: AGPL-3.0-or-later+import {ResettableStates} from '@app/features/app/state/ResettableStates';import {FavoriteMeme, type FavoriteMemeWire} from '@app/features/expressions/models/FavoriteMeme';import {makeAutoObservable} from 'mobx';@@ -40,4 +41,8 @@ class FavoriteMemes {}}-export default new FavoriteMemes();+const favoriteMemes = new FavoriteMemes();++ResettableStates.register(favoriteMemes, () => favoriteMemes.reset());++export default favoriteMemes;diff --git a/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationsTabState.ts b/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationsTabState.tsindex 821405897..5affc1fab 100644--- a/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationsTabState.ts+++ b/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationsTabState.ts@@ -1,6 +1,7 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport {Endpoints} from '@app/features/app/constants/Endpoints';+import {ResettableStates} from '@app/features/app/state/ResettableStates';import type {DeveloperApplicationWire} from '@app/features/devtools/models/DeveloperApplication';import {DeveloperApplication} from '@app/features/devtools/models/DeveloperApplication';import {http} from '@app/features/platform/transport/RestTransport';@@ -219,6 +220,23 @@ class ApplicationsTabState {this.applicationOrder = nextOrder;return record;}++ reset(): void {+ this.listAbortController?.abort();+ this.detailAbortController?.abort();+ this.listAbortController = null;+ this.detailAbortController = null;+ this.navigationState = NavigationState.LOADING_LIST;+ this.applicationOrder = [];+ this.applicationsById = {};+ this.selectedAppId = null;+ this.error = null;+ this.isLoading = false;+ }}-export default new ApplicationsTabState();+const applicationsTabState = new ApplicationsTabState();++ResettableStates.register(applicationsTabState, () => applicationsTabState.reset());++export default applicationsTabState;