mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Follow style guides, support for threads, and some settings
This commit is contained in:
parent
6875ff0d9f
commit
58b8aee426
5 changed files with 72 additions and 40 deletions
|
@ -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)
|
|
@ -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 })
|
||||
});
|
5
src/plugins/unreadCountBadge/README.md
Normal file
5
src/plugins/unreadCountBadge/README.md
Normal 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)
|
66
src/plugins/unreadCountBadge/index.tsx
Normal file
66
src/plugins/unreadCountBadge/index.tsx
Normal 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 }),
|
||||
});
|
|
@ -1,3 +1,3 @@
|
|||
.unreadCountBadge {
|
||||
.vc-unreadCountBadge {
|
||||
margin-left: 4px;
|
||||
}
|
Loading…
Reference in a new issue