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 message, thread and member stores per account

Hampus7246d91a577f
diff --git a/fluxer_app/src/features/channel/state/ChannelFrecency.ts b/fluxer_app/src/features/channel/state/ChannelFrecency.ts
index 37baf0b3b..65be93836 100644
--- a/fluxer_app/src/features/channel/state/ChannelFrecency.ts
+++ b/fluxer_app/src/features/channel/state/ChannelFrecency.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import Initialization from '@app/features/app/state/Initialization';
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import Channels from '@app/features/channel/state/Channels';
import {
type ChannelFrecencyEntry,
@@ -226,4 +227,8 @@ class ChannelFrecency {
}
}
-export default new ChannelFrecency();
+const channelFrecency = new ChannelFrecency();
+
+ResettableStates.register(channelFrecency, () => channelFrecency.handleLogout());
+
+export default channelFrecency;
diff --git a/fluxer_app/src/features/channel/state/CrosspostSourceCards.ts b/fluxer_app/src/features/channel/state/CrosspostSourceCards.ts
index f4b94e492..ad0d3d5bf 100644
--- a/fluxer_app/src/features/channel/state/CrosspostSourceCards.ts
+++ b/fluxer_app/src/features/channel/state/CrosspostSourceCards.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {fetchCrosspostSource} from '@app/features/channel/commands/CrosspostSourceCommands';
import {HttpError} from '@app/features/platform/types/EndpointError';
import type {CrosspostSourceGuildResponse} from '@fluxer/schema/src/domains/message/CrosspostSourceSchemas';
@@ -58,6 +59,15 @@ class CrosspostSourceCards {
private setEntry(sourceGuildId: string, state: CrosspostSourceCardState): void {
this.entries = new Map(this.entries).set(sourceGuildId, state);
}
+
+ reset(): void {
+ this.entries = new Map();
+ this.inflight.clear();
+ }
}
-export default new CrosspostSourceCards();
+const crosspostSourceCards = new CrosspostSourceCards();
+
+ResettableStates.register(crosspostSourceCards, () => crosspostSourceCards.reset());
+
+export default crosspostSourceCards;
diff --git a/fluxer_app/src/features/channel/state/PublishNudge.ts b/fluxer_app/src/features/channel/state/PublishNudge.ts
index 0defe5431..b1c624344 100644
--- a/fluxer_app/src/features/channel/state/PublishNudge.ts
+++ b/fluxer_app/src/features/channel/state/PublishNudge.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import type {Message} from '@app/features/messaging/models/MessagingMessage';
import MessagingMessages from '@app/features/messaging/state/MessagingMessages';
import {makeSyncedField} from '@app/features/user/state/SyncedField';
@@ -59,6 +60,14 @@ class PublishNudge {
const newestOwn = MessagingMessages.getCachedMessages(message.channelId)?.searchFromNewest(isPublishCandidate);
return newestOwn?.id === message.id;
}
+
+ reset(): void {
+ this.dismissedMessageIds = new Set();
+ }
}
-export default new PublishNudge();
+const publishNudge = new PublishNudge();
+
+ResettableStates.register(publishNudge, () => publishNudge.reset());
+
+export default publishNudge;
diff --git a/fluxer_app/src/features/discovery/state/DiscoveryChannelPreviews.ts b/fluxer_app/src/features/discovery/state/DiscoveryChannelPreviews.ts
index 1e20a2530..817b6db41 100644
--- a/fluxer_app/src/features/discovery/state/DiscoveryChannelPreviews.ts
+++ b/fluxer_app/src/features/discovery/state/DiscoveryChannelPreviews.ts
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import type {DiscoveryChannelPreview} from '@app/features/discovery/commands/DiscoveryCommands';
import * as DiscoveryCommands from '@app/features/discovery/commands/DiscoveryCommands';
-import {AccountScopedWork} from '@app/features/platform/state/AccountScopedWork';
import {failureCode} from '@app/features/platform/utils/ResponseInspection';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {makeAutoObservable, observable, runInAction} from 'mobx';
@@ -65,6 +65,6 @@ class DiscoveryChannelPreviews {
const discoveryChannelPreviews = new DiscoveryChannelPreviews();
-AccountScopedWork.registerCancellation(() => discoveryChannelPreviews.reset());
+ResettableStates.register(discoveryChannelPreviews, () => discoveryChannelPreviews.reset());
export default discoveryChannelPreviews;
diff --git a/fluxer_app/src/features/forum/state/ForumPosts.ts b/fluxer_app/src/features/forum/state/ForumPosts.ts
index 8b173a6ba..59e971ee4 100644
--- a/fluxer_app/src/features/forum/state/ForumPosts.ts
+++ b/fluxer_app/src/features/forum/state/ForumPosts.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 {Channel, ChannelWire} from '@app/features/channel/models/Channel';
import Channels from '@app/features/channel/state/Channels';
import {getDefaultLayout, getDefaultSortOrder, getDefaultTagSetting} from '@app/features/forum/utils/ForumChannelUtils';
@@ -20,16 +21,17 @@ import {
POST_DATA_MAX_IDS,
THREAD_SEARCH_MAX_LIMIT,
} from '@fluxer/constants/src/ThreadConstants';
+import {MS_PER_MINUTE, MS_PER_SECOND} from '@fluxer/date_utils/src/DateConstants';
import type {ThreadMemberResponse} from '@fluxer/schema/src/domains/channel/ThreadSchemas';
import type {Message as WireMessage} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import {makeAutoObservable, observable, runInAction} from 'mobx';
const logger = new Logger('ForumPosts');
-export const FORUM_SEARCH_DEBOUNCE_MS = 300;
-export const POST_DATA_DEBOUNCE_MS = 50;
-export const SEARCH_RETRY_MAX_ATTEMPTS = 6;
-export const SEARCH_RETRY_MAX_DELAY_MS = 60_000;
+const FORUM_SEARCH_DEBOUNCE_MS = 300;
+const POST_DATA_DEBOUNCE_MS = 50;
+const SEARCH_RETRY_MAX_ATTEMPTS = 6;
+const SEARCH_RETRY_MAX_DELAY_MS = MS_PER_MINUTE;
export type ForumListKind = 'archived' | 'search';
@@ -121,7 +123,7 @@ export function canRequestForumPosts(forum: Channel): boolean {
}
export function searchRetryDelayMs(retryAfterSeconds: number | undefined, attempt: number): number {
- const base = Math.max(1, retryAfterSeconds ?? 1) * 1000;
+ const base = Math.max(1, retryAfterSeconds ?? 1) * MS_PER_SECOND;
return Math.min(SEARCH_RETRY_MAX_DELAY_MS, base * 2 ** attempt);
}
@@ -418,17 +420,20 @@ class ForumPosts {
return;
}
const sortOrder = this.getSortOrder(forum);
+ let sortBy: 'last_message_time' | 'creation_time' | 'relevance';
+ if (kind === 'search') {
+ sortBy = 'relevance';
+ } else if (sortOrder === ForumSortOrderTypes.CREATION_TIME) {
+ sortBy = 'creation_time';
+ } else {
+ sortBy = 'last_message_time';
+ }
const path = buildSearchPath(forum.id, {
name: kind === 'search' ? query : null,
tagIds: this.getTagFilter(forum.id),
tagSetting: getDefaultTagSetting(forum),
archived: kind === 'archived' ? true : null,
- sortBy:
- kind === 'search'
- ? 'relevance'
- : sortOrder === ForumSortOrderTypes.CREATION_TIME
- ? 'creation_time'
- : 'last_message_time',
+ sortBy,
offset: append ? current.ids.length : 0,
});
try {
@@ -597,4 +602,8 @@ class ForumPosts {
}
}
-export default new ForumPosts();
+const forumPosts = new ForumPosts();
+
+ResettableStates.register(forumPosts, () => forumPosts.reset());
+
+export default forumPosts;
diff --git a/fluxer_app/src/features/forum/state/ForumReadState.ts b/fluxer_app/src/features/forum/state/ForumReadState.ts
index fc6d7a02a..b859b9a05 100644
--- a/fluxer_app/src/features/forum/state/ForumReadState.ts
+++ b/fluxer_app/src/features/forum/state/ForumReadState.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import Authentication from '@app/features/auth/state/Authentication';
import type {Channel} from '@app/features/channel/models/Channel';
import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';
@@ -34,7 +35,7 @@ export function hasForumUnread(forum: Channel): boolean {
return isNewPostsUnreadEnabled(forum) && ReadStates.hasUnread(forum.id);
}
-export function isPostNewerThan(
+function isPostNewerThan(
post: {id: string; ownerId: string | null},
snapshotId: string,
currentUserId: string | null,
@@ -159,6 +160,12 @@ class ForumReadState {
this.resetRequests();
}
+ reset(): void {
+ this.resetRequests();
+ this.postUnreads.clear();
+ this.snapshots.clear();
+ }
+
purgeGuild(guildId: string): void {
for (const [postId, entry] of this.queue) {
if (entry.guildId === guildId) this.queue.delete(postId);
@@ -206,4 +213,8 @@ class ForumReadState {
}
}
-export default new ForumReadState();
+const forumReadState = new ForumReadState();
+
+ResettableStates.register(forumReadState, () => forumReadState.reset());
+
+export default forumReadState;
diff --git a/fluxer_app/src/features/guild/state/GuildAvailability.ts b/fluxer_app/src/features/guild/state/GuildAvailability.ts
index 2ee944940..f1f488c0c 100644
--- a/fluxer_app/src/features/guild/state/GuildAvailability.ts
+++ b/fluxer_app/src/features/guild/state/GuildAvailability.ts
@@ -62,6 +62,7 @@ class GuildAvailability {
hydrateFromSnapshot(guilds: ReadonlyArray<{readonly id: string; readonly unavailable: boolean}>): void {
this.unavailableGuilds.clear();
+ this.degradedGuilds.clear();
for (const guild of guilds) {
if (guild.unavailable) {
this.unavailableGuilds.add(guild.id);
diff --git a/fluxer_app/src/features/member/state/MemberList.ts b/fluxer_app/src/features/member/state/MemberList.ts
index a1d1c8997..34e1e2121 100644
--- a/fluxer_app/src/features/member/state/MemberList.ts
+++ b/fluxer_app/src/features/member/state/MemberList.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 {Logger} from '@app/features/platform/utils/AppLogger';
import {initializeStore} from '@app/features/platform/utils/StoreInitialization';
import {makeSyncedField} from '@app/features/user/state/SyncedField';
@@ -102,6 +102,14 @@ class MemberList {
AppStorage.setJSON(DEFAULT_HIDDEN_CHANNEL_MEMBER_LIST_STORAGE_KEY, next);
logger.debug(`Toggled default-hidden channel members list: channel=${channelId}, open=${isOpen}`);
}
+
+ reloadDefaultHiddenChannelState(): void {
+ this.defaultHiddenChannelMembersOpenByChannelId = getInitialDefaultHiddenChannelState();
+ }
}
-export default new MemberList();
+const memberList = new MemberList();
+
+subscribeAppStorageScope(memberList.reloadDefaultHiddenChannelState);
+
+export default memberList;
diff --git a/fluxer_app/src/features/member/state/MemberSearch.ts b/fluxer_app/src/features/member/state/MemberSearch.ts
index d8c9d0db6..fc8c9fa74 100644
--- a/fluxer_app/src/features/member/state/MemberSearch.ts
+++ b/fluxer_app/src/features/member/state/MemberSearch.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import Guilds from '@app/features/guild/state/Guilds';
import type {GuildMember} from '@app/features/member/models/GuildMember';
import GuildMembers from '@app/features/member/state/GuildMembers';
@@ -418,9 +419,8 @@ class MemberSearch {
if (!guildIds || guildIds.length === 0) {
return;
}
- const sortedGuildIds = priorityGuildId
- ? [...guildIds].sort((a, b) => (a === priorityGuildId ? -1 : b === priorityGuildId ? 1 : 0))
- : guildIds;
+ const priorityRank = (guildId: string) => (guildId === priorityGuildId ? 0 : 1);
+ const sortedGuildIds = priorityGuildId ? [...guildIds].sort((a, b) => priorityRank(a) - priorityRank(b)) : guildIds;
const eligibleGuildIds = sortedGuildIds.filter((guildId) => {
if (!guildId) {
return false;
@@ -457,4 +457,8 @@ class MemberSearch {
}
}
-export default new MemberSearch();
+const memberSearch = new MemberSearch();
+
+ResettableStates.register(memberSearch, () => memberSearch.handleLogout());
+
+export default memberSearch;
diff --git a/fluxer_app/src/features/messaging/state/AttachmentUrlRefresher.ts b/fluxer_app/src/features/messaging/state/AttachmentUrlRefresher.ts
index 239a4b861..5bf5565ea 100644
--- a/fluxer_app/src/features/messaging/state/AttachmentUrlRefresher.ts
+++ b/fluxer_app/src/features/messaging/state/AttachmentUrlRefresher.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 RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {
ATTACHMENT_URL_REFRESH_MARGIN_MS,
@@ -239,4 +240,8 @@ class AttachmentUrlRefresher {
}
}
-export default new AttachmentUrlRefresher();
+const attachmentUrlRefresher = new AttachmentUrlRefresher();
+
+ResettableStates.register(attachmentUrlRefresher, () => attachmentUrlRefresher.reset());
+
+export default attachmentUrlRefresher;
diff --git a/fluxer_app/src/features/messaging/state/MessageReferences.ts b/fluxer_app/src/features/messaging/state/MessageReferences.ts
index 97971ac4e..f35248b05 100644
--- a/fluxer_app/src/features/messaging/state/MessageReferences.ts
+++ b/fluxer_app/src/features/messaging/state/MessageReferences.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {Message as MessageRecord} from '@app/features/messaging/models/MessagingMessage';
import Messages from '@app/features/messaging/state/MessagingMessages';
import {MessageFlags, MessageReferenceTypes} from '@fluxer/constants/src/ChannelConstants';
@@ -229,6 +230,18 @@ class MessageReferences {
}
return NOT_LOADED_RESOLUTION;
}
+
+ reset(): void {
+ this.deletedMessageIds = new Set();
+ this.cachedMessages = new Map();
+ this.referenceVersions.clear();
+ this.referenceCount.clear();
+ this.referencingMessages.clear();
+ }
}
-export default new MessageReferences();
+const messageReferences = new MessageReferences();
+
+ResettableStates.register(messageReferences, () => messageReferences.reset());
+
+export default messageReferences;
diff --git a/fluxer_app/src/features/messaging/state/MessagingMessages.ts b/fluxer_app/src/features/messaging/state/MessagingMessages.ts
index 785393738..e859735aa 100644
--- a/fluxer_app/src/features/messaging/state/MessagingMessages.ts
+++ b/fluxer_app/src/features/messaging/state/MessagingMessages.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import Channels from '@app/features/channel/state/Channels';
import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';
import Guilds from '@app/features/guild/state/Guilds';
@@ -32,7 +33,7 @@ interface GuildMemberUpdateAction {
member: GuildMemberData;
}
-export interface PendingJumpDispatch {
+interface PendingJumpDispatch {
messageId: string;
flash?: boolean;
offset?: number;
@@ -623,6 +624,12 @@ class Messages {
return hasChanges;
}
+ forgetUnfocusedVisitChannel(channelId: string): void {
+ if (SelectedChannel.currentChannelId === channelId) return;
+ this.clearMessages(channelId);
+ this.notifyChange();
+ }
+
handleGuildThreadsPurged(guildId: string): void {
ChannelMessages.forEach(({channelId}) => {
if (Channels.getChannel(channelId)?.guildId === guildId) {
@@ -746,6 +753,8 @@ class Messages {
const messages = new Messages();
+ResettableStates.register(messages, () => messages.handleSessionInvalidated());
+
AccountScopedWork.registerTransition({
suspend: () => {},
resume: () => {},
diff --git a/fluxer_app/src/features/moderation/state/ReportFlows.ts b/fluxer_app/src/features/moderation/state/ReportFlows.ts
index 081549a4d..83ce222a6 100644
--- a/fluxer_app/src/features/moderation/state/ReportFlows.ts
+++ b/fluxer_app/src/features/moderation/state/ReportFlows.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {fetchReportFlow} from '@app/features/moderation/commands/ReportFlowCommands';
import {Logger} from '@app/features/platform/utils/AppLogger';
@@ -126,4 +127,8 @@ class ReportFlows {
}
}
-export default new ReportFlows();
+const reportFlows = new ReportFlows();
+
+ResettableStates.register(reportFlows, () => reportFlows.reset());
+
+export default reportFlows;
diff --git a/fluxer_app/src/features/presence/state/Presence.ts b/fluxer_app/src/features/presence/state/Presence.ts
index c229bef50..883ae611b 100644
--- a/fluxer_app/src/features/presence/state/Presence.ts
+++ b/fluxer_app/src/features/presence/state/Presence.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import Authentication from '@app/features/auth/state/Authentication';
import Channels from '@app/features/channel/state/Channels';
import type {SnapshotPresenceRow} from '@app/features/gateway/snapshot/SnapshotEntities';
@@ -628,4 +629,8 @@ class Presence {
}
}
-export default new Presence();
+const presence = new Presence();
+
+ResettableStates.register(presence, () => presence.handleSessionInvalidated());
+
+export default presence;
diff --git a/fluxer_app/src/features/threads/state/ChannelThreads.ts b/fluxer_app/src/features/threads/state/ChannelThreads.ts
index b4ee29450..7f9a53e0e 100644
--- a/fluxer_app/src/features/threads/state/ChannelThreads.ts
+++ b/fluxer_app/src/features/threads/state/ChannelThreads.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {Routes} from '@app/app/Routes';
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import Authentication from '@app/features/auth/state/Authentication';
import {cleanupChannelLocalState} from '@app/features/channel/events/ChannelDelete';
import type {Channel, ChannelWire} from '@app/features/channel/models/Channel';
@@ -286,4 +287,8 @@ function newestId(a: string | null | undefined, b: string | null | undefined): s
return SnowflakeUtils.compare(a, b) >= 0 ? a : b;
}
-export default new ChannelThreads();
+const channelThreads = new ChannelThreads();
+
+ResettableStates.register(channelThreads, () => channelThreads.handleGatewayReady([]));
+
+export default channelThreads;
diff --git a/fluxer_app/src/features/threads/state/ThreadGuilds.ts b/fluxer_app/src/features/threads/state/ThreadGuilds.ts
index 0165bbe40..abd80e31b 100644
--- a/fluxer_app/src/features/threads/state/ThreadGuilds.ts
+++ b/fluxer_app/src/features/threads/state/ThreadGuilds.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {Routes} from '@app/app/Routes';
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {cleanupChannelLocalState} from '@app/features/channel/events/ChannelDelete';
import Channels from '@app/features/channel/state/Channels';
import ForumPosts from '@app/features/forum/state/ForumPosts';
@@ -14,6 +15,7 @@ import ThreadPanel from '@app/features/threads/state/ThreadPanel';
import * as ContextMenuCommands from '@app/features/ui/commands/ContextMenuCommands';
import * as PopoutCommands from '@app/features/ui/commands/PopoutCommands';
import {THREAD_ONLY_CHANNEL_TYPES} from '@fluxer/constants/src/ThreadConstants';
+import {isObjectLike} from '@fluxer/record_utils/src/RecordGuards';
import {makeAutoObservable, observable} from 'mobx';
class ThreadGuilds {
@@ -87,12 +89,12 @@ class ThreadGuilds {
purgeGuild(guildId: string): void {
const openThreadId = Navigation.guildId === guildId ? (Navigation.threadId ?? Navigation.channelId) : null;
- const fallbackChannelId =
- Navigation.threadId != null
- ? Navigation.channelId
- : openThreadId != null
- ? (Channels.getChannel(openThreadId)?.parentId ?? null)
- : null;
+ let fallbackChannelId: string | null = null;
+ if (Navigation.threadId != null) {
+ fallbackChannelId = Navigation.channelId;
+ } else if (openThreadId != null) {
+ fallbackChannelId = Channels.getChannel(openThreadId)?.parentId ?? null;
+ }
const createTarget = ThreadPanel.createTarget;
if (createTarget && Channels.getChannel(createTarget.parentId)?.guildId === guildId) ThreadPanel.closeCreate();
const threadIds = ChannelThreads.purgeGuild(guildId);
@@ -110,14 +112,17 @@ class ThreadGuilds {
ContextMenuCommands.close();
PopoutCommands.closeAll();
if (openThreadId != null && threadIds.includes(openThreadId)) {
- const keepChannel = fallbackChannelId != null && Channels.getChannel(fallbackChannelId) !== undefined;
- RouterUtils.replaceWith(Routes.guildChannel(guildId, keepChannel ? fallbackChannelId : undefined));
+ let routeChannelId: string | undefined;
+ if (fallbackChannelId != null && Channels.getChannel(fallbackChannelId) !== undefined) {
+ routeChannelId = fallbackChannelId;
+ }
+ RouterUtils.replaceWith(Routes.guildChannel(guildId, routeChannelId));
}
}
isPurgedEvent(data: unknown): boolean {
- if (this.purgedThreadIds.size === 0 || data == null || typeof data !== 'object') return false;
- const channelId = (data as {channel_id?: unknown}).channel_id;
+ if (this.purgedThreadIds.size === 0 || !isObjectLike(data)) return false;
+ const channelId = data.channel_id;
return typeof channelId === 'string' && this.purgedThreadIds.has(channelId);
}
@@ -128,4 +133,8 @@ class ThreadGuilds {
}
}
-export default new ThreadGuilds();
+const threadGuilds = new ThreadGuilds();
+
+ResettableStates.register(threadGuilds, () => threadGuilds.reset());
+
+export default threadGuilds;
diff --git a/fluxer_app/src/features/threads/state/ThreadPanel.ts b/fluxer_app/src/features/threads/state/ThreadPanel.ts
index e97bd58f5..1398f1e7e 100644
--- a/fluxer_app/src/features/threads/state/ThreadPanel.ts
+++ b/fluxer_app/src/features/threads/state/ThreadPanel.ts
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {makeAutoObservable, observable} from 'mobx';
-export interface ThreadCreateTarget {
+interface ThreadCreateTarget {
readonly parentId: string;
readonly messageId: string | null;
}
@@ -35,6 +36,15 @@ class ThreadPanel {
closeCreate(): void {
this.createTarget = null;
}
+
+ reset(): void {
+ this.createTarget = null;
+ this.createCooldowns.clear();
+ }
}
-export default new ThreadPanel();
+const threadPanel = new ThreadPanel();
+
+ResettableStates.register(threadPanel, () => threadPanel.reset());
+
+export default threadPanel;
diff --git a/fluxer_app/src/features/threads/state/ThreadRoster.ts b/fluxer_app/src/features/threads/state/ThreadRoster.ts
index 127434669..9a414c1a0 100644
--- a/fluxer_app/src/features/threads/state/ThreadRoster.ts
+++ b/fluxer_app/src/features/threads/state/ThreadRoster.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import GuildMembers from '@app/features/member/state/GuildMembers';
import {
type CustomStatus,
@@ -102,4 +103,8 @@ class ThreadRoster {
}
}
-export default new ThreadRoster();
+const threadRoster = new ThreadRoster();
+
+ResettableStates.register(threadRoster, () => threadRoster.reset());
+
+export default threadRoster;
diff --git a/fluxer_app/src/features/threads/state/ThreadSubscriptions.ts b/fluxer_app/src/features/threads/state/ThreadSubscriptions.ts
index 6ae761f04..ce7abd1ee 100644
--- a/fluxer_app/src/features/threads/state/ThreadSubscriptions.ts
+++ b/fluxer_app/src/features/threads/state/ThreadSubscriptions.ts
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';
+import Guilds from '@app/features/guild/state/Guilds';
import SelectedGuild from '@app/features/navigation/state/SelectedGuild';
import {deferUntilModulesLoaded} from '@app/features/platform/utils/DeferUntilModulesLoaded';
import ThreadGuilds from '@app/features/threads/state/ThreadGuilds';
@@ -69,6 +71,12 @@ class ThreadSubscriptions {
this.connectionEpoch += 1;
}
+ reset(): void {
+ this.sent = new Map();
+ this.listGuilds = new Set();
+ this.lastGuildId = null;
+ }
+
private handleConnectionLost(): void {
this.sent = new Map();
this.armed = false;
@@ -85,10 +93,11 @@ class ThreadSubscriptions {
for (const listGuildId of this.listGuilds) {
if (listGuildId !== guildId) subscriptions[listGuildId] = {thread_member_lists: []};
}
- const memberLists = desired.memberLists.join(',');
+ const visibleMemberLists = guildId && Guilds.getGuild(guildId)?.visiting === true ? [] : desired.memberLists;
+ const memberLists = visibleMemberLists.join(',');
const previous = guildId ? this.sent.get(guildId) : undefined;
if (guildId && !(previous?.threads && previous.memberLists === memberLists)) {
- subscriptions[guildId] = {threads: true, thread_member_lists: [...desired.memberLists]};
+ subscriptions[guildId] = {threads: true, thread_member_lists: [...visibleMemberLists]};
}
if (Object.keys(subscriptions).length === 0) return;
const socket = GatewaySessions.foregroundConnection.socket;
@@ -99,7 +108,7 @@ class ThreadSubscriptions {
}
if (guildId && subscriptions[guildId]) {
this.sent.set(guildId, {threads: true, memberLists});
- if (desired.memberLists.length > 0) this.listGuilds.add(guildId);
+ if (visibleMemberLists.length > 0) this.listGuilds.add(guildId);
else this.listGuilds.delete(guildId);
}
}
@@ -120,4 +129,8 @@ class ThreadSubscriptions {
}
}
-export default new ThreadSubscriptions();
+const threadSubscriptions = new ThreadSubscriptions();
+
+ResettableStates.register(threadSubscriptions, () => threadSubscriptions.reset());
+
+export default threadSubscriptions;
diff --git a/fluxer_app/src/features/webhook/state/Webhooks.ts b/fluxer_app/src/features/webhook/state/Webhooks.ts
index 11aaa0fdb..16da04bbd 100644
--- a/fluxer_app/src/features/webhook/state/Webhooks.ts
+++ b/fluxer_app/src/features/webhook/state/Webhooks.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {ResettableStates} from '@app/features/app/state/ResettableStates';
import {Webhook} from '@app/features/webhook/models/Webhook';
import type {Webhook as WireWebhook} from '@fluxer/schema/src/domains/webhook/WebhookSchemas';
import {makeAutoObservable} from 'mobx';
@@ -237,6 +238,18 @@ class Webhooks {
this.channelFetchStatus = nextChannelFetchStatus;
this.guildFetchStatus = nextGuildFetchStatus;
}
+
+ reset(): void {
+ this.webhooks = new Map();
+ this.channelWebhooks = new Map();
+ this.channelGuildMap = new Map();
+ this.channelFetchStatus = new Map();
+ this.guildFetchStatus = new Map();
+ }
}
-export default new Webhooks();
+const webhooks = new Webhooks();
+
+ResettableStates.register(webhooks, () => webhooks.reset());
+
+export default webhooks;