From fb19642d8d8465c8578185491d6a2aba5bf4ab0a Mon Sep 17 00:00:00 2001 From: DShadow <62884000+PonyGirlDShadow@users.noreply.github.com> Date: Thu, 16 May 2024 07:07:14 +0300 Subject: [PATCH] fix(readAllNotificationsButton): Mark threads as read (#2437) --- .../readAllNotificationsButton/index.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/plugins/readAllNotificationsButton/index.tsx b/src/plugins/readAllNotificationsButton/index.tsx index 3bf53f993..7a6737a8a 100644 --- a/src/plugins/readAllNotificationsButton/index.tsx +++ b/src/plugins/readAllNotificationsButton/index.tsx @@ -22,14 +22,34 @@ import { addServerListElement, removeServerListElement, ServerListRenderPosition import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; +import { findStoreLazy } from "@webpack"; import { Button, FluxDispatcher, GuildChannelStore, GuildStore, React, ReadStateStore } from "@webpack/common"; +import { Channel } from "discord-types/general"; + +interface ThreadJoined { + channel: Channel; + joinTimestamp: number; +} + +type ThreadsJoined = Record; +type ThreadsJoinedByParent = Record; + +interface ActiveJoinedThreadsStore { + getActiveJoinedThreadsForGuild(guildId: string): ThreadsJoinedByParent; +} + +const ActiveJoinedThreadsStore: ActiveJoinedThreadsStore = findStoreLazy("ActiveJoinedThreadsStore"); function onClick() { const channels: Array = []; Object.values(GuildStore.getGuilds()).forEach(guild => { - GuildChannelStore.getChannels(guild.id).SELECTABLE - .concat(GuildChannelStore.getChannels(guild.id).VOCAL) + GuildChannelStore.getChannels(guild.id).SELECTABLE // Array<{ channel, comparator }> + .concat(GuildChannelStore.getChannels(guild.id).VOCAL) // Array<{ channel, comparator }> + .concat( + Object.values(ActiveJoinedThreadsStore.getActiveJoinedThreadsForGuild(guild.id)) + .flatMap(threadChannels => Object.values(threadChannels)) + ) .forEach((c: { channel: { id: string; }; }) => { if (!ReadStateStore.hasUnread(c.channel.id)) return;