Plugin
ReadAllNotificationsButton
Read all server notifications with a single button click!
1
import "./style.css";2
3
import { addServerListElement, removeServerListElement, ServerListRenderPosition } from "@api/ServerList";4
import { TextButton } from "@components/Button";5
import ErrorBoundary from "@components/ErrorBoundary";6
import { Devs } from "@utils/constants";7
import definePlugin from "@utils/types";8
import { ActiveJoinedThreadsStore, FluxDispatcher, GuildChannelStore, GuildStore, React, ReadStateStore } from "@webpack/common";9
10
function onClick() {11
const channels: Array<any> = [];12
13
Object.values(GuildStore.getGuilds()).forEach(guild => {14
GuildChannelStore.getChannels(guild.id).SELECTABLE15
.concat(GuildChannelStore.getChannels(guild.id).VOCAL)16
.concat(17
Object.values(ActiveJoinedThreadsStore.getActiveJoinedThreadsForGuild(guild.id))18
.flatMap(threadChannels => Object.values(threadChannels))19
)20
.forEach((c: { channel: { id: string; }; }) => {21
if (!ReadStateStore.hasUnread(c.channel.id)) return;22
23
channels.push({24
channelId: c.channel.id,25
messageId: ReadStateStore.lastMessageId(c.channel.id),26
readStateType: 027
});28
});29
});30
31
FluxDispatcher.dispatch({32
type: "BULK_ACK",33
context: "APP",34
channels: channels35
});36
}37
38
const ReadAllButton = () => (39
<TextButton40
variant="secondary"41
onClick={onClick}42
className="vc-ranb-button"43
>44
Read All45
</TextButton>46
);47
48
export default definePlugin({49
name: "ReadAllNotificationsButton",50
description: "Read all server notifications with a single button click!",51
tags: ["Notifications", "Shortcuts"],52
authors: [Devs.kemo],53
dependencies: ["ServerListAPI"],54
55
renderReadAllButton: ErrorBoundary.wrap(ReadAllButton, { noop: true }),56
57
start() {58
addServerListElement(ServerListRenderPosition.Above, this.renderReadAllButton);59
},60
61
stop() {62
removeServerListElement(ServerListRenderPosition.Above, this.renderReadAllButton);63
}64
});65