MemberCount: add thread support (#2785)
Co-authored-by: v <vendicated@riseup.net>
This commit is contained in:
parent
ed9b28febf
commit
2569c39ddf
|
@ -5,9 +5,10 @@
|
|||
*/
|
||||
|
||||
import { getCurrentChannel } from "@utils/discord";
|
||||
import { isObjectEmpty } from "@utils/misc";
|
||||
import { SelectedChannelStore, Tooltip, useEffect, useStateFromStores } from "@webpack/common";
|
||||
|
||||
import { ChannelMemberStore, cl, GuildMemberCountStore, numberFormat } from ".";
|
||||
import { ChannelMemberStore, cl, GuildMemberCountStore, numberFormat, ThreadMemberListStore } from ".";
|
||||
import { OnlineMemberCountStore } from "./OnlineMemberCountStore";
|
||||
|
||||
export function MemberCount({ isTooltip, tooltipGuildId }: { isTooltip?: true; tooltipGuildId?: string; }) {
|
||||
|
@ -30,10 +31,19 @@ export function MemberCount({ isTooltip, tooltipGuildId }: { isTooltip?: true; t
|
|||
() => ChannelMemberStore.getProps(guildId, currentChannel?.id)
|
||||
);
|
||||
|
||||
const threadGroups = useStateFromStores(
|
||||
[ThreadMemberListStore],
|
||||
() => ThreadMemberListStore.getMemberListSections(currentChannel.id)
|
||||
);
|
||||
|
||||
if (!isTooltip && (groups.length >= 1 || groups[0].id !== "unknown")) {
|
||||
onlineCount = groups.reduce((total, curr) => total + (curr.id === "offline" ? 0 : curr.count), 0);
|
||||
}
|
||||
|
||||
if (!isTooltip && threadGroups && !isObjectEmpty(threadGroups)) {
|
||||
onlineCount = Object.values(threadGroups).reduce((total, curr) => total + (curr.sectionId === "offline" ? 0 : curr.userIds.length), 0);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
OnlineMemberCountStore.ensureCount(guildId);
|
||||
}, [guildId]);
|
||||
|
|
|
@ -32,6 +32,10 @@ export const GuildMemberCountStore = findStoreLazy("GuildMemberCountStore") as F
|
|||
export const ChannelMemberStore = findStoreLazy("ChannelMemberStore") as FluxStore & {
|
||||
getProps(guildId: string, channelId: string): { groups: { count: number; id: string; }[]; };
|
||||
};
|
||||
export const ThreadMemberListStore = findStoreLazy("ThreadMemberListStore") as FluxStore & {
|
||||
getMemberListSections(channelId: string): { [sectionId: string]: { sectionId: string; userIds: string[]; }; };
|
||||
};
|
||||
|
||||
|
||||
const settings = definePluginSettings({
|
||||
toolTip: {
|
||||
|
|
Loading…
Reference in a new issue