Plugin

ReadAllNotificationsButton

Read all server notifications with a single button click!

Notifications Shortcuts
index.tsx
Download

Source

src/plugins/readAllNotificationsButton/index.tsx
1import "./style.css";
2
3import { addServerListElement, removeServerListElement, ServerListRenderPosition } from "@api/ServerList";
4import { TextButton } from "@components/Button";
5import ErrorBoundary from "@components/ErrorBoundary";
6import { Devs } from "@utils/constants";
7import definePlugin from "@utils/types";
8import { ActiveJoinedThreadsStore, FluxDispatcher, GuildChannelStore, GuildStore, React, ReadStateStore } from "@webpack/common";
9
10function onClick() {
11 const channels: Array<any> = [];
12
13 Object.values(GuildStore.getGuilds()).forEach(guild => {
14 GuildChannelStore.getChannels(guild.id).SELECTABLE
15 .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: 0
27 });
28 });
29 });
30
31 FluxDispatcher.dispatch({
32 type: "BULK_ACK",
33 context: "APP",
34 channels: channels
35 });
36}
37
38const ReadAllButton = () => (
39 <TextButton
40 variant="secondary"
41 onClick={onClick}
42 className="vc-ranb-button"
43 >
44 Read All
45 </TextButton>
46);
47
48export 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