A pr was wanted

This commit is contained in:
Masterjoona 2024-07-29 21:22:40 +03:00
parent 5e9a9fe836
commit 6875ff0d9f
No known key found for this signature in database
GPG key ID: F8032EB7D47E12ED
3 changed files with 42 additions and 0 deletions

View file

@ -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)

View file

@ -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 <NumberBadge count={unreadCount} color="var(--brand-500)" className="unreadCountBadge" />;
}, { noop: true })
});

View file

@ -0,0 +1,3 @@
.unreadCountBadge {
margin-left: 4px;
}