fix: Fix bookmarked/tab new forum posts not showing unread count (#944)

This commit is contained in:
Jake 2026-03-29 17:10:09 +01:00 • committed by GitHub
parent 726fdb86a2
commit 3df077bdab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,7 @@ import { getGuildAcronym, getIntlMessage, getUniqueUsername } from "@utils/disco
import { classes } from "@utils/misc";
import { Channel, Guild, User } from "@vencord/discord-types";
import { findComponentByCodeLazy, findCssClassesLazy } from "@webpack";
import { Avatar, ChannelStore, ContextMenuApi, GuildStore, PresenceStore, ReadStateStore, ThemeStore, TypingStore, useDrag, useDrop, useEffect, useRef, UserStore, useState, useStateFromStores } from "@webpack/common";
import { ActiveJoinedThreadsStore, Avatar, ChannelStore, ContextMenuApi, GuildStore, PresenceStore, ReadStateStore, ThemeStore, TypingStore, useDrag, useDrop, useEffect, useRef, UserStore, useState, useStateFromStores } from "@webpack/common";
import { JSX } from "react";
import { TabContextMenu } from "./ContextMenus";
@ -75,19 +75,29 @@ function TypingIndicator({ isTyping }: { isTyping: boolean; }) {
: null;
}
function getChannelUnreadState(channelId: string) {
const channel = ChannelStore.getChannel(channelId);
const newForumPostCount = channel?.guild_id && channel.isForumLikeChannel?.()
? ActiveJoinedThreadsStore.getNewThreadCount(channel.guild_id, channel.id)
: 0;
const unreadCount = ReadStateStore.getUnreadCount(channelId) || newForumPostCount;
return {
channelId,
hasUnread: ReadStateStore.hasUnread(channelId) || newForumPostCount > 0,
mentionCount: ReadStateStore.getMentionCount(channelId),
unreadCount
};
}
export const NotificationDot = ({ channelIds }: { channelIds: string[]; }) => {
const userId = UserStore.getCurrentUser()?.id;
const { persistUnreadCountFallback } = settings.use(["persistUnreadCountFallback"]);
const [, forceUpdate] = useState(0);
const channelStateKey = channelIds.join(",");
const channelStates = useStateFromStores(
[ReadStateStore],
() => channelIds.map(channelId => ({
channelId,
hasUnread: ReadStateStore.hasUnread(channelId),
mentionCount: ReadStateStore.getMentionCount(channelId),
unreadCount: ReadStateStore.getUnreadCount(channelId)
}))
[ActiveJoinedThreadsStore, ReadStateStore],
() => channelIds.map(getChannelUnreadState)
);
const stateSignature = channelStates.map(state => `${state.channelId}:${Number(state.hasUnread)}:${state.mentionCount}:${state.unreadCount}`).join("|");
const { badgeText, hasMention, shouldShow } = getNotificationDotState(