mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-19 11:27:02 -04:00
feat: auto-managed flux subscriptions via plugin.flux (#959)
This commit is contained in:
parent
c6f0c84935
commit
63fc354d48
10 changed files with 210 additions and 253 deletions
|
@ -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;
|
||||
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;
|
||||
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: () => (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue