fix(readAllNotificationsButton): Mark threads as read (#2437)
This commit is contained in:
parent
4281b7a94a
commit
fb19642d8d
1 changed files with 22 additions and 2 deletions
|
@ -22,14 +22,34 @@ import { addServerListElement, removeServerListElement, ServerListRenderPosition
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
|
import { findStoreLazy } from "@webpack";
|
||||||
import { Button, FluxDispatcher, GuildChannelStore, GuildStore, React, ReadStateStore } from "@webpack/common";
|
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<string, ThreadJoined>;
|
||||||
|
type ThreadsJoinedByParent = Record<string, ThreadsJoined>;
|
||||||
|
|
||||||
|
interface ActiveJoinedThreadsStore {
|
||||||
|
getActiveJoinedThreadsForGuild(guildId: string): ThreadsJoinedByParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ActiveJoinedThreadsStore: ActiveJoinedThreadsStore = findStoreLazy("ActiveJoinedThreadsStore");
|
||||||
|
|
||||||
function onClick() {
|
function onClick() {
|
||||||
const channels: Array<any> = [];
|
const channels: Array<any> = [];
|
||||||
|
|
||||||
Object.values(GuildStore.getGuilds()).forEach(guild => {
|
Object.values(GuildStore.getGuilds()).forEach(guild => {
|
||||||
GuildChannelStore.getChannels(guild.id).SELECTABLE
|
GuildChannelStore.getChannels(guild.id).SELECTABLE // Array<{ channel, comparator }>
|
||||||
.concat(GuildChannelStore.getChannels(guild.id).VOCAL)
|
.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; }; }) => {
|
.forEach((c: { channel: { id: string; }; }) => {
|
||||||
if (!ReadStateStore.hasUnread(c.channel.id)) return;
|
if (!ReadStateStore.hasUnread(c.channel.id)) return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue