diff --git a/src/plugins/UnreadCountBadge/README.md b/src/plugins/UnreadCountBadge/README.md deleted file mode 100644 index bd9a8eb32..000000000 --- a/src/plugins/UnreadCountBadge/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Show a badge in the channel list for unread messages. - -![image](https://github.com/user-attachments/assets/fdec8682-8db6-4a24-be48-b13a16ad9d00) diff --git a/src/plugins/UnreadCountBadge/index.tsx b/src/plugins/UnreadCountBadge/index.tsx deleted file mode 100644 index 20a7736fe..000000000 --- a/src/plugins/UnreadCountBadge/index.tsx +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Vencord, a Discord client mod - * Copyright (c) 2024 Vendicated and contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -import ErrorBoundary from "@components/ErrorBoundary"; -import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { ReadStateStore, useStateFromStores } from "@webpack/common"; -const { NumberBadge } = findByPropsLazy("NumberBadge"); - -import "./styles.css"; - -export default definePlugin({ - name: "UnreadCountBadge", - authors: [Devs.Joona], - description: "Show unread count in the channel list", - patches: [ - // Kanged from typingindicators - { - find: "UNREAD_IMPORTANT:", - replacement: { - match: /\.name\),.{0,120}\.children.+?:null(?<=,channel:(\i).+?)/, - replace: "$&,$self.CountBadge({channelId:$1.id})" - } - }, - ], - - CountBadge: ErrorBoundary.wrap(({ channelId }: { channelId: string; }) => { - const unreadCount = useStateFromStores([ReadStateStore], () => ReadStateStore.getUnreadCount(channelId)); - if (!unreadCount) return null; - return ; - }, { noop: true }) -}); diff --git a/src/plugins/unreadCountBadge/README.md b/src/plugins/unreadCountBadge/README.md new file mode 100644 index 000000000..ce63cd455 --- /dev/null +++ b/src/plugins/unreadCountBadge/README.md @@ -0,0 +1,5 @@ +# UnreadCountBadge + +Show a badge in the channel list for unread messages. + +![](https://github.com/user-attachments/assets/58beb269-259c-47aa-84dc-60f2354e6207) diff --git a/src/plugins/unreadCountBadge/index.tsx b/src/plugins/unreadCountBadge/index.tsx new file mode 100644 index 000000000..d4af9774d --- /dev/null +++ b/src/plugins/unreadCountBadge/index.tsx @@ -0,0 +1,66 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./styles.css"; + +import { definePluginSettings } from "@api/Settings"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { findByPropsLazy, findStoreLazy } from "@webpack"; +import { ReadStateStore, useStateFromStores } from "@webpack/common"; +import { Channel } from "discord-types/general"; + +const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore"); +const JoinedThreadsStore = findStoreLazy("JoinedThreadsStore"); +const { NumberBadge } = findByPropsLazy("NumberBadge"); + +const settings = definePluginSettings({ + ShowOnMutedChannels: { + description: "Show unread count on muted channels", + type: OptionType.BOOLEAN, + default: false, + }, + NotificationCountLimit: { + description: "Show +99 instead of true amount", + type: OptionType.BOOLEAN, + default: false, + }, +}); + +export default definePlugin({ + name: "UnreadCountBadge", + authors: [Devs.Joona], + description: "Show unread count in the channel list", + patches: [ + // Kanged from typingindicators + { + find: "UNREAD_IMPORTANT:", + replacement: { + match: /\.name\),.{0,120}\.children.+?:null(?<=,channel:(\i),guild:(\i).+?)/, + replace: "$&,$self.CountBadge({channel: $1})" + } + }, + // Threads + { + // This is the thread "spine" that shows in the left + find: "M11 9H4C2.89543 9 2 8.10457 2 7V1C2 0.447715 1.55228 0 1 0C0.447715 0 0 0.447715 0 1V7C0 9.20914 1.79086 11 4 11H11C11.5523 11 12 10.5523 12 10C12 9.44771 11.5523 9 11 9Z", + replacement: + { + match: /mentionsCount:\i.+?null(?<=channel:(\i).+?)/, + replace: "$&,$self.CountBadge({channel: $1})" + } + + }, + ], + settings, + CountBadge: ErrorBoundary.wrap(({ channel }: { channel: Channel; }) => { + let unreadCount = useStateFromStores([ReadStateStore], () => ReadStateStore.getUnreadCount(channel.id)); + if (!unreadCount || (!settings.store.ShowOnMutedChannels && (UserGuildSettingsStore.isChannelMuted(channel.guild_id, channel.id) || JoinedThreadsStore.isMuted(channel.id)))) return null; + if (settings.store.NotificationCountLimit && unreadCount > 99) unreadCount = "+99"; + return ; + }, { noop: true }), +}); diff --git a/src/plugins/UnreadCountBadge/styles.css b/src/plugins/unreadCountBadge/styles.css similarity index 51% rename from src/plugins/UnreadCountBadge/styles.css rename to src/plugins/unreadCountBadge/styles.css index b13bcd8b0..d54621e5d 100644 --- a/src/plugins/UnreadCountBadge/styles.css +++ b/src/plugins/unreadCountBadge/styles.css @@ -1,3 +1,3 @@ -.unreadCountBadge { +.vc-unreadCountBadge { margin-left: 4px; }