mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-22 12:57:01 -04:00
UnreadBadgeCount PR Ver
This commit is contained in:
parent
784d06090d
commit
56d2342165
2 changed files with 94 additions and 13 deletions
|
@ -4,33 +4,98 @@
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import "./styles.css";
|
||||||
|
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByPropsLazy } from "@webpack";
|
import { findByPropsLazy, findStoreLazy } from "@webpack";
|
||||||
import { ReadStateStore, useStateFromStores } from "@webpack/common";
|
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 { NumberBadge } = findByPropsLazy("NumberBadge");
|
||||||
|
|
||||||
import "./styles.css";
|
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,
|
||||||
|
},
|
||||||
|
replaceWhiteDot: {
|
||||||
|
description: "Replace the white dot with the badge",
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
default: false,
|
||||||
|
restartNeeded: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "UnreadCountBadge",
|
name: "UnreadCountBadge",
|
||||||
authors: [Devs.Joona],
|
authors: [Devs.Joona],
|
||||||
description: "Show unread count in the channel list",
|
description: "Shows unread message count badges on channels in the channel list",
|
||||||
|
settings,
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
// Kanged from typingindicators
|
// Kanged from typingindicators
|
||||||
{
|
{
|
||||||
find: "UNREAD_IMPORTANT:",
|
find: "UNREAD_IMPORTANT:",
|
||||||
replacement: {
|
replacement: [
|
||||||
match: /\.name\),.{0,120}\.children.+?:null(?<=,channel:(\i).+?)/,
|
{
|
||||||
replace: "$&,$self.CountBadge({channelId:$1.id})"
|
match: /\.name\),.{0,120}\.children.+?:null/,
|
||||||
}
|
replace: "$&,$self.CountBadge({channel: arguments[0].channel,})",
|
||||||
|
predicate: () => !settings.store.replaceWhiteDot
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: /\(0,\i\.jsx\)\("div",{className:\i\(\)\(\i\.unread,\i\?\i\.unreadImportant:void 0\)}\)/,
|
||||||
|
replace: "$self.CountBadge({channel: arguments[0].channel, whiteDot:$&})",
|
||||||
|
predicate: () => settings.store.replaceWhiteDot
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
// 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.{0,50}?null/,
|
||||||
|
replace: "$&,$self.CountBadge({channel: arguments[0].thread})",
|
||||||
|
predicate: () => !settings.store.replaceWhiteDot
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: /\(0,\i\.jsx\)\("div",{className:\i\(\)\(\i\.unread,\i\.unreadImportant\)}\)/,
|
||||||
|
replace: "$self.CountBadge({channel: arguments[0].thread, whiteDot:$&})",
|
||||||
|
predicate: () => settings.store.replaceWhiteDot
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
CountBadge: ErrorBoundary.wrap(({ channelId }: { channelId: string; }) => {
|
CountBadge: ErrorBoundary.wrap(({ channel, whiteDot }: { channel: Channel, whiteDot?: JSX.Element; }) => {
|
||||||
const unreadCount = useStateFromStores([ReadStateStore], () => ReadStateStore.getUnreadCount(channelId));
|
const unreadCount = useStateFromStores([ReadStateStore], () => ReadStateStore.getUnreadCount(channel.id));
|
||||||
if (!unreadCount) return null;
|
if (!unreadCount) return whiteDot || null;
|
||||||
return <NumberBadge count={unreadCount} color="var(--brand-500)" className="unreadCountBadge" />;
|
|
||||||
}, { noop: true })
|
if (!settings.store.showOnMutedChannels && (UserGuildSettingsStore.isChannelMuted(channel.guild_id, channel.id) || JoinedThreadsStore.isMuted(channel.id)))
|
||||||
|
return null;
|
||||||
|
const className = `vc-unreadCountBadge${whiteDot ? "-dot" : ""}${channel.threadMetadata ? "-thread" : ""}`;
|
||||||
|
return (
|
||||||
|
<NumberBadge
|
||||||
|
color="var(--brand-500)"
|
||||||
|
className={className}
|
||||||
|
count={
|
||||||
|
unreadCount > 99 && settings.store.notificationCountLimit
|
||||||
|
? "+99"
|
||||||
|
: unreadCount
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}, { noop: true }),
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,22 @@
|
||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vc-unreadCountBadge-dot {
|
||||||
|
position: absolute;
|
||||||
|
top: 25%;
|
||||||
|
margin-left: -3%;
|
||||||
|
scale: 0.9;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-unreadCountBadge-dot-thread {
|
||||||
|
position: absolute;
|
||||||
|
top: 20%;
|
||||||
|
margin-left: -18%;
|
||||||
|
scale: 0.9;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
[class*="modeMuted_"] .unreadCountBadge {
|
[class*="modeMuted_"] .unreadCountBadge {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue