Follow style guides, support for threads, and some settings

This commit is contained in:
Masterjoona 2024-07-31 12:15:01 +00:00
parent 6875ff0d9f
commit 58b8aee426
No known key found for this signature in database
GPG key ID: 2C2E7CB358A11227
5 changed files with 72 additions and 40 deletions

View file

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

View file

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

View file

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

View file

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

View file

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