From 63fc354d483b86857bbee7f540c66ba614fc0f1f Mon Sep 17 00:00:00 2001 From: V Date: Sat, 22 Apr 2023 03:18:19 +0200 Subject: feat: auto-managed flux subscriptions via plugin.flux (#959) --- src/plugins/memberCount.tsx | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'src/plugins/memberCount.tsx') diff --git a/src/plugins/memberCount.tsx b/src/plugins/memberCount.tsx index 3a68126..0b5409c 100644 --- a/src/plugins/memberCount.tsx +++ b/src/plugins/memberCount.tsx @@ -23,7 +23,7 @@ import { getCurrentChannel } from "@utils/discord"; import { useForceUpdater } from "@utils/misc"; import definePlugin from "@utils/types"; import { findStoreLazy } from "@webpack"; -import { FluxDispatcher, Tooltip } from "@webpack/common"; +import { Tooltip } from "@webpack/common"; const counts = {} as Record; let forceUpdate: () => void; @@ -107,27 +107,21 @@ export default definePlugin({ } }], - onGuildMemberListUpdate({ guildId, groups, memberCount, id }) { - // eeeeeh - sometimes it has really wrong counts??? like 10 times less than actual - // but if we only listen to everyone updates, sometimes we never get the count? - // this seems to work but isn't optional - if (id !== "everyone" && counts[guildId]) return; - - let count = 0; - for (const group of groups) { - if (group.id !== "offline") - count += group.count; + flux: { + GUILD_MEMBER_LIST_UPDATE({ guildId, groups, memberCount, id }) { + // eeeeeh - sometimes it has really wrong counts??? like 10 times less than actual + // but if we only listen to everyone updates, sometimes we never get the count? + // this seems to work but isn't optional + if (id !== "everyone" && counts[guildId]) return; + + let count = 0; + for (const group of groups) { + if (group.id !== "offline") + count += group.count; + } + counts[guildId] = [memberCount, count]; + forceUpdate?.(); } - counts[guildId] = [memberCount, count]; - forceUpdate?.(); - }, - - start() { - FluxDispatcher.subscribe("GUILD_MEMBER_LIST_UPDATE", this.onGuildMemberListUpdate); - }, - - stop() { - FluxDispatcher.unsubscribe("GUILD_MEMBER_LIST_UPDATE", this.onGuildMemberListUpdate); }, render: () => ( -- cgit