From fb212d12a064ca56ba48aa41f729eff876fc8039 Mon Sep 17 00:00:00 2001 From: refact0r Date: Wed, 3 Apr 2024 16:21:30 -0700 Subject: [PATCH] fix #2129 --- src/plugins/showMeYourName/index.tsx | 51 ++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx index 62d0645d20..49b4ee0e03 100644 --- a/src/plugins/showMeYourName/index.tsx +++ b/src/plugins/showMeYourName/index.tsx @@ -13,12 +13,16 @@ import { Message, User } from "discord-types/general"; interface UsernameProps { author: { nick: string; }; - message: Message; + message?: Message; withMentionPrefix?: boolean; isRepliedMessage: boolean; userOverride?: User; } +interface NickUser extends User { + nick: string; +} + const settings = definePluginSettings({ mode: { type: OptionType.SELECT, @@ -53,12 +57,29 @@ export default definePlugin({ replace: "$self.renderUsername(arguments[0])}" } }, + // Keep the user object and nick when creating the list of typing users + { + find: "getCooldownTextStyle", + replacement: { + match: /\.map\((\i)=>(\i)\.(\i)\.getName\((\i),this\.props\.channel\.id,(\i)\)\)/, + replace: ".map($1 => { let user = $1; user.nick = $2.$3.getName($4, this.props.channel.id, $5); return user; })" + } + }, + // Style the indicator and add function call to modify the children before rendering + { + find: "getCooldownTextStyle", + replacement: { + match: /(?<=children:\[(\i)\.length>0.{0,200}?"aria-atomic":!0,children:)\i/, + replace: "$self.renderTypingNames(this.props, $1, $&)" + } + }, ], settings, renderUsername: ({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => { try { - const user = userOverride ?? message.author; + const user = userOverride ?? message?.author; + if (!user) return author?.nick; let { username } = user; if (settings.store.displayNames) username = (user as any).globalName || username; @@ -76,4 +97,30 @@ export default definePlugin({ return author?.nick; } }, + + renderTypingNames(props: any, users: NickUser[], children: any) { + if (!Array.isArray(children)) return children; + + let index = 0; + + console.log("children", children); + console.log("props", props); + console.log("users", users); + + return children.map(c => { + if (c.type === "strong") { + const user = users[index++]; + console.log("user", user); + if (!user) return c; + return <>{this.renderUsername({ + author: { nick: user.nick }, + message: undefined, + isRepliedMessage: false, + withMentionPrefix: false, + userOverride: user + })}; + } + return c; + }); + }, });