From ca810250d1fcc5fa543890bdab9f19a0005e5a8e Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 14 Jun 2024 22:56:21 +0200 Subject: [PATCH 1/2] ConsoleShortcuts: add `Stores` map with all stores --- src/plugins/consoleShortcuts/index.ts | 10 +++++++++- src/webpack/common/types/stores.d.ts | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index 0a1323e75..2fdf87356 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -141,7 +141,15 @@ function makeShortcuts() { guildId: { getter: () => Common.SelectedGuildStore.getGuildId(), preload: false }, me: { getter: () => Common.UserStore.getCurrentUser(), preload: false }, meId: { getter: () => Common.UserStore.getCurrentUser().id, preload: false }, - messages: { getter: () => Common.MessageStore.getMessages(Common.SelectedChannelStore.getChannelId()), preload: false } + messages: { getter: () => Common.MessageStore.getMessages(Common.SelectedChannelStore.getChannelId()), preload: false }, + + Stores: { + getter: () => Object.fromEntries( + Common.Flux.Store.getAll() + .map(store => [store.getName(), store] as const) + .filter(([name]) => name.length > 1) + ) + } }; } diff --git a/src/webpack/common/types/stores.d.ts b/src/webpack/common/types/stores.d.ts index f1fc68e8b..037b2d81c 100644 --- a/src/webpack/common/types/stores.d.ts +++ b/src/webpack/common/types/stores.d.ts @@ -39,6 +39,8 @@ export class FluxStore { syncWith: GenericFunction; waitFor: GenericFunction; __getLocalVars(): Record; + + static getAll(): FluxStore[]; } export class FluxEmitter { From e79430ca84fef990eb79a3404e054ab6f981be73 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 14 Jun 2024 23:04:43 +0200 Subject: [PATCH 2/2] RelationShipNotifier: try to fix false positives for unavailable guilds --- src/plugins/relationshipNotifier/functions.ts | 4 ++-- src/plugins/relationshipNotifier/utils.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/plugins/relationshipNotifier/functions.ts b/src/plugins/relationshipNotifier/functions.ts index 980b11300..5bff474b6 100644 --- a/src/plugins/relationshipNotifier/functions.ts +++ b/src/plugins/relationshipNotifier/functions.ts @@ -21,7 +21,7 @@ import { UserUtils } from "@webpack/common"; import settings from "./settings"; import { ChannelDelete, ChannelType, GuildDelete, RelationshipRemove, RelationshipType } from "./types"; -import { deleteGroup, deleteGuild, getGroup, getGuild, notify } from "./utils"; +import { deleteGroup, deleteGuild, getGroup, getGuild, GuildAvailabilityStore, notify } from "./utils"; let manuallyRemovedFriend: string | undefined; let manuallyRemovedGuild: string | undefined; @@ -63,7 +63,7 @@ export async function onRelationshipRemove({ relationship: { type, id } }: Relat export function onGuildDelete({ guild: { id, unavailable } }: GuildDelete) { if (!settings.store.servers) return; - if (unavailable) return; + if (unavailable || GuildAvailabilityStore.isUnavailable(id)) return; if (manuallyRemovedGuild === id) { deleteGuild(id); diff --git a/src/plugins/relationshipNotifier/utils.ts b/src/plugins/relationshipNotifier/utils.ts index 16f1892af..053cff835 100644 --- a/src/plugins/relationshipNotifier/utils.ts +++ b/src/plugins/relationshipNotifier/utils.ts @@ -19,11 +19,20 @@ import { DataStore, Notices } from "@api/index"; import { showNotification } from "@api/Notifications"; import { getUniqueUsername, openUserProfile } from "@utils/discord"; +import { findStoreLazy } from "@webpack"; import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common"; +import { FluxStore } from "@webpack/types"; import settings from "./settings"; import { ChannelType, RelationshipType, SimpleGroupChannel, SimpleGuild } from "./types"; +export const GuildAvailabilityStore = findStoreLazy("GuildAvailabilityStore") as FluxStore & { + totalGuilds: number; + totalUnavailableGuilds: number; + unavailableGuilds: string[]; + isUnavailable(guildId: string): boolean; +}; + const guilds = new Map(); const groups = new Map(); const friends = { @@ -59,7 +68,7 @@ export async function syncAndRunChecks() { if (settings.store.servers && oldGuilds?.size) { for (const [id, guild] of oldGuilds) { - if (!guilds.has(id)) + if (!guilds.has(id) && !GuildAvailabilityStore.isUnavailable(id)) notify(`You are no longer in the server ${guild.name}.`, guild.iconURL); } }