diff options
author | V <vendicated@riseup.net> | 2023-04-22 03:18:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-22 01:18:19 +0000 |
commit | 63fc354d483b86857bbee7f540c66ba614fc0f1f (patch) | |
tree | 6ebe100e5ff63254adfdb0c44cb473dcc339cf35 /src/plugins/memberCount.tsx | |
parent | c6f0c84935db37e2a18578a081404d84292fe36a (diff) | |
download | Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.tar.gz Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.tar.bz2 Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.zip |
feat: auto-managed flux subscriptions via plugin.flux (#959)
Diffstat (limited to 'src/plugins/memberCount.tsx')
-rw-r--r-- | src/plugins/memberCount.tsx | 36 |
1 files changed, 15 insertions, 21 deletions
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<string, [number, number]>; 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: () => ( |