diff --git a/src/plugins/serverListIndicators/index.tsx b/src/plugins/serverListIndicators/index.tsx
index 96833d8f..7648bc2d 100644
--- a/src/plugins/serverListIndicators/index.tsx
+++ b/src/plugins/serverListIndicators/index.tsx
@@ -20,9 +20,9 @@ import { addServerListElement, removeServerListElement, ServerListRenderPosition
import { Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
-import { useForceUpdater } from "@utils/react";
import definePlugin, { OptionType } from "@utils/types";
-import { GuildStore, PresenceStore, RelationshipStore } from "@webpack/common";
+import { findStoreLazy } from "@webpack";
+import { GuildStore, PresenceStore, RelationshipStore, useStateFromStores } from "@webpack/common";
const enum IndicatorType {
SERVER = 1 << 0,
@@ -30,13 +30,24 @@ const enum IndicatorType {
BOTH = SERVER | FRIEND,
}
-let onlineFriends = 0;
-let guildCount = 0;
-let forceUpdateFriendCount: () => void;
-let forceUpdateGuildCount: () => void;
+const UserGuildJoinRequestStore = findStoreLazy("UserGuildJoinRequestStore");
function FriendsIndicator() {
- forceUpdateFriendCount = useForceUpdater();
+ const onlineFriendsCount = useStateFromStores([RelationshipStore, PresenceStore], () => {
+ let count = 0;
+
+ const friendIds = RelationshipStore.getFriendIDs();
+ for (const id of friendIds) {
+ const status = PresenceStore.getStatus(id) ?? "offline";
+ if (status === "offline") {
+ continue;
+ }
+
+ count++;
+ }
+
+ return count;
+ });
return (
- {onlineFriends} online
+ {onlineFriendsCount} online
);
}
function ServersIndicator() {
- forceUpdateGuildCount = useForceUpdater();
+ const guildCount = useStateFromStores([GuildStore, UserGuildJoinRequestStore], () => {
+ const guildJoinRequests: string[] = UserGuildJoinRequestStore.computeGuildIds();
+ const guilds = GuildStore.getGuilds();
+
+ // Filter only pending guild join requests
+ return GuildStore.getGuildCount() + guildJoinRequests.filter(id => guilds[id] == null).length;
+ });
return (
;
},
- flux: {
- PRESENCE_UPDATES: handlePresenceUpdate,
- GUILD_CREATE: handleGuildUpdate,
- GUILD_DELETE: handleGuildUpdate,
- },
-
-
start() {
addServerListElement(ServerListRenderPosition.Above, this.renderIndicator);
-
- handlePresenceUpdate();
- handleGuildUpdate();
},
stop() {