From 6875ff0d9fe4a7977aea972f4eb162b9b4ef10f4 Mon Sep 17 00:00:00 2001 From: Masterjoona <69722179+Masterjoona@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:22:40 +0300 Subject: [PATCH] A pr was wanted --- src/plugins/UnreadCountBadge/README.md | 3 +++ src/plugins/UnreadCountBadge/index.tsx | 36 +++++++++++++++++++++++++ src/plugins/UnreadCountBadge/styles.css | 3 +++ 3 files changed, 42 insertions(+) create mode 100644 src/plugins/UnreadCountBadge/README.md create mode 100644 src/plugins/UnreadCountBadge/index.tsx create mode 100644 src/plugins/UnreadCountBadge/styles.css diff --git a/src/plugins/UnreadCountBadge/README.md b/src/plugins/UnreadCountBadge/README.md new file mode 100644 index 000000000..bd9a8eb32 --- /dev/null +++ b/src/plugins/UnreadCountBadge/README.md @@ -0,0 +1,3 @@ +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 new file mode 100644 index 000000000..20a7736fe --- /dev/null +++ b/src/plugins/UnreadCountBadge/index.tsx @@ -0,0 +1,36 @@ +/* + * 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/styles.css b/src/plugins/UnreadCountBadge/styles.css new file mode 100644 index 000000000..b13bcd8b0 --- /dev/null +++ b/src/plugins/UnreadCountBadge/styles.css @@ -0,0 +1,3 @@ +.unreadCountBadge { + margin-left: 4px; +}