MemberCount: Fix misleading count, add tooltip

This commit is contained in:
Vendicated 2022-11-28 23:01:04 +01:00
parent c583bad6bf
commit e884738f42
No known key found for this signature in database
GPG Key ID: EC781ADFB93EFFA3

@ -22,7 +22,7 @@ import { Devs } from "@utils/constants";
import { getCurrentChannel } from "@utils/discord"; import { getCurrentChannel } from "@utils/discord";
import { useForceUpdater } from "@utils/misc"; import { useForceUpdater } from "@utils/misc";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { FluxDispatcher } from "@webpack/common"; import { FluxDispatcher, Tooltip } from "@webpack/common";
const counts = {} as Record<string, [number, number]>; const counts = {} as Record<string, [number, number]>;
let forceUpdate: () => void; let forceUpdate: () => void;
@ -49,33 +49,41 @@ function MemberCount() {
alignContent: "center", alignContent: "center",
gap: 0 gap: 0
}}> }}>
<div> <Tooltip text={`${c[1]} Online`} position="bottom">
<span {props => (
style={{ <div {...props}>
backgroundColor: "var(--status-green-600)", <span
width: "12px", style={{
height: "12px", backgroundColor: "var(--status-green-600)",
borderRadius: "50%", width: "12px",
display: "inline-block", height: "12px",
marginRight: "0.5em" borderRadius: "50%",
}} display: "inline-block",
/> marginRight: "0.5em"
<span style={{ color: "var(--status-green-600)" }}>{c[1]}</span> }}
</div> />
<div> <span style={{ color: "var(--status-green-600)" }}>{c[1]}</span>
<span </div>
style={{ )}
width: "6px", </Tooltip>
height: "6px", <Tooltip text={`${c[0] || "?"} Total Members`} position="bottom">
borderRadius: "50%", {props => (
border: "3px solid var(--status-grey-500)", <div {...props}>
display: "inline-block", <span
marginRight: "0.5em", style={{
marginLeft: "1em" width: "6px",
}} height: "6px",
/> borderRadius: "50%",
<span style={{ color: "var(--status-grey-500)" }}>{total}</span> border: "3px solid var(--status-grey-500)",
</div> display: "inline-block",
marginRight: "0.5em",
marginLeft: "1em"
}}
/>
<span style={{ color: "var(--status-grey-500)" }}>{total}</span>
</div>
)}
</Tooltip>
</Flex> </Flex>
); );
} }
@ -93,7 +101,12 @@ export default definePlugin({
} }
}], }],
onGuildMemberListUpdate({ guildId, groups, memberCount }) { 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; let count = 0;
for (const group of groups) { for (const group of groups) {
if (group.id !== "offline") if (group.id !== "offline")