From 2f1e86f3335160d3fa80272215bdd2778883eff5 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 21 Nov 2023 00:51:12 -0300 Subject: [PATCH] TypingIndicator: support threads --- src/plugins/typingIndicator/index.tsx | 34 +++++++++++++++++---------- src/webpack/common/types/utils.d.ts | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/plugins/typingIndicator/index.tsx b/src/plugins/typingIndicator/index.tsx index 9111af44..86bfbb4f 100644 --- a/src/plugins/typingIndicator/index.tsx +++ b/src/plugins/typingIndicator/index.tsx @@ -21,8 +21,8 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { LazyComponent } from "@utils/react"; import definePlugin, { OptionType } from "@utils/types"; -import { find, findLazy, findStoreLazy } from "@webpack"; -import { ChannelStore, GuildMemberStore, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; +import { find, findStoreLazy } from "@webpack"; +import { ChannelStore, GuildMemberStore, i18n, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; import { buildSeveralUsers } from "../typingTweaks"; @@ -36,10 +36,9 @@ const ThreeDots = LazyComponent(() => { const TypingStore = findStoreLazy("TypingStore"); const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore"); -const Formatters = findLazy(m => m.Messages?.SEVERAL_USERS_TYPING); - function getDisplayName(guildId: string, userId: string) { - return GuildMemberStore.getNick(guildId, userId) ?? UserStore.getUser(userId).username; + const user = UserStore.getUser(userId); + return GuildMemberStore.getNick(guildId, userId) ?? (user as any).globalName ?? user.username; } function TypingIndicator({ channelId }: { channelId: string; }) { @@ -51,7 +50,7 @@ function TypingIndicator({ channelId }: { channelId: string; }) { const oldKeys = Object.keys(old); const currentKeys = Object.keys(current); - return oldKeys.length === currentKeys.length && JSON.stringify(oldKeys) === JSON.stringify(currentKeys); + return oldKeys.length === currentKeys.length && currentKeys.every(key => old[key] != null); } ); @@ -70,21 +69,21 @@ function TypingIndicator({ channelId }: { channelId: string; }) { switch (typingUsersArray.length) { case 0: break; case 1: { - tooltipText = Formatters.Messages.ONE_USER_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]) }); + tooltipText = i18n.Messages.ONE_USER_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]) }); break; } case 2: { - tooltipText = Formatters.Messages.TWO_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]) }); + tooltipText = i18n.Messages.TWO_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]) }); break; } case 3: { - tooltipText = Formatters.Messages.THREE_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), c: getDisplayName(guildId, typingUsersArray[2]) }); + tooltipText = i18n.Messages.THREE_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), c: getDisplayName(guildId, typingUsersArray[2]) }); break; } default: { tooltipText = Settings.plugins.TypingTweaks.enabled ? buildSeveralUsers({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), count: typingUsersArray.length - 2 }) - : Formatters.Messages.SEVERAL_USERS_TYPING; + : i18n.Messages.SEVERAL_USERS_TYPING; break; } } @@ -92,11 +91,10 @@ function TypingIndicator({ channelId }: { channelId: string; }) { if (typingUsersArray.length > 0) { return ( - {({ onMouseLeave, onMouseEnter }) => ( + {props => (
@@ -128,12 +126,22 @@ export default definePlugin({ settings, patches: [ + // Normal channel { find: "UNREAD_IMPORTANT:", replacement: { match: /channel:(\i).{0,100}?channelEmoji,.{0,250}?\.children.{0,50}?:null/, replace: "$&,$self.TypingIndicator($1.id)" } + }, + // Theads + { + // 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.TypingIndicator($1.id)" + } } ], diff --git a/src/webpack/common/types/utils.d.ts b/src/webpack/common/types/utils.d.ts index 7eb5711a..64a68f2c 100644 --- a/src/webpack/common/types/utils.d.ts +++ b/src/webpack/common/types/utils.d.ts @@ -159,5 +159,5 @@ export interface i18n { loadPromise: Promise; - Messages: Record; + Messages: Record; }