From 0f14e675baf1cfea92c35434cd327d2241e8488d Mon Sep 17 00:00:00 2001 From: 7w1 Date: Tue, 17 Mar 2026 21:15:38 -0500 Subject: [PATCH 1/3] pronoun pills for all --- .changeset/pronoun-pills.md | 5 ++ src/app/features/room/message/Message.tsx | 58 ++++++++++++++++--- .../features/settings/cosmetics/Cosmetics.tsx | 8 +++ src/app/state/settings.ts | 2 + 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 .changeset/pronoun-pills.md diff --git a/.changeset/pronoun-pills.md b/.changeset/pronoun-pills.md new file mode 100644 index 00000000..416f3764 --- /dev/null +++ b/.changeset/pronoun-pills.md @@ -0,0 +1,5 @@ +--- +default: minor +--- + +Added a setting to Appearance that attempts to convert text in names like (it/its) into a pronoun pill, enlabed by default. diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index 9dd200ed..fdd015c2 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -390,11 +390,6 @@ function MessageInternal( return mxc ? mxcUrlToHttp(mx, mxc, useAuthentication, 48, 48, 'crop') : undefined; }, [pmp, collapse, profile.avatarUrl, senderId, mx, room, useAuthentication]); - const displayName = useMemo( - () => pmp?.displayname || senderDisplayName, - [pmp, senderDisplayName] - ); - const cachedAvatar = useBlobCache(avatarUrl ?? undefined); // UI State @@ -423,9 +418,56 @@ function MessageInternal( const [mobileOptionsOpen, setMobileOptionsOpen] = useState(false); const optionsRef = useRef(null); + const [showPronouns] = useSetting(settingsAtom, 'showPronouns'); + const [parsePronouns] = useSetting(settingsAtom, 'parsePronouns'); + const [useRightBubbles] = useSetting(settingsAtom, 'useRightBubbles'); + const { cleanedDisplayName, inlinePronoun } = useMemo(() => { + const rawName = pmp?.displayname || senderDisplayName || ''; + + if (!parsePronouns) { + return { cleanedDisplayName: rawName, inlinePronoun: null }; + } + + // match text like (she/her) or [he/they/them] but not (hi) + const regex = /[\(\[]?([a-zA-Z]+\/[a-zA-Z]+(?:\/[a-zA-Z]+)?)[\)\]]?/; + const match = rawName.match(regex); + + if (match) { + let strippedName = rawName.replace(match[0], '').trim(); + + if (!strippedName || strippedName === '') { + strippedName = rawName; + } + + return { + cleanedDisplayName: strippedName, + inlinePronoun: match[1].toLowerCase().slice(0, 16), + }; + } + + return { cleanedDisplayName: rawName, inlinePronoun: null }; + }, [pmp, senderDisplayName, parsePronouns]); + + const mergedPronouns = useMemo(() => { + const existing = profile.pronouns ? [...profile.pronouns] : []; + + if (inlinePronoun) { + const isDupe = existing.some((p) => p.summary?.toLowerCase() === inlinePronoun); + + if (!isDupe) { + existing.push({ + summary: inlinePronoun, + language: 'en', + }); + } + } + + return existing; + }, [profile.pronouns, inlinePronoun]); + useEffect(() => { if (!mobileOptionsOpen) return undefined; const handleClickOutside = (e: globalThis.Event) => { @@ -457,11 +499,11 @@ function MessageInternal( onClick={onUsernameClick} > - {displayName} + {cleanedDisplayName} {showPronouns && ( - + )} {tagIconSrc && } @@ -500,7 +542,7 @@ function MessageInternal( } /> diff --git a/src/app/features/settings/cosmetics/Cosmetics.tsx b/src/app/features/settings/cosmetics/Cosmetics.tsx index d1a65b6b..f0bf1d8f 100644 --- a/src/app/features/settings/cosmetics/Cosmetics.tsx +++ b/src/app/features/settings/cosmetics/Cosmetics.tsx @@ -165,6 +165,7 @@ function IdentityCosmetics() { 'legacyUsernameColor' ); const [showPronouns, setShowPronouns] = useSetting(settingsAtom, 'showPronouns'); + const [parsePronouns, setParsePronouns] = useSetting(settingsAtom, 'parsePronouns'); const [renderGlobalColors, setRenderGlobalColors] = useSetting( settingsAtom, 'renderGlobalNameColors' @@ -196,6 +197,13 @@ function IdentityCosmetics() { after={} /> + + } + /> + Date: Tue, 17 Mar 2026 21:23:18 -0500 Subject: [PATCH 2/3] cache things --- src/app/features/room/message/Message.tsx | 27 ++------------- src/app/utils/pronouns.ts | 42 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index fdd015c2..2602ab26 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -79,7 +79,7 @@ import { MessageSourceCodeItem } from '$components/message/modals/MessageSource' import { MessageForwardItem } from '$components/message/modals/MessageForward'; import { MessageDeleteItem } from '$components/message/modals/MessageDelete'; import { MessageReportItem } from '$components/message/modals/MessageReport'; -import { filterPronounsByLanguage } from '$utils/pronouns'; +import { filterPronounsByLanguage, getParsedPronouns } from '$utils/pronouns'; import { useMentionClickHandler } from '$hooks/useMentionClickHandler'; import { addStickerToDefaultPack, @@ -423,32 +423,9 @@ function MessageInternal( const [parsePronouns] = useSetting(settingsAtom, 'parsePronouns'); const [useRightBubbles] = useSetting(settingsAtom, 'useRightBubbles'); - const { cleanedDisplayName, inlinePronoun } = useMemo(() => { const rawName = pmp?.displayname || senderDisplayName || ''; - - if (!parsePronouns) { - return { cleanedDisplayName: rawName, inlinePronoun: null }; - } - - // match text like (she/her) or [he/they/them] but not (hi) - const regex = /[\(\[]?([a-zA-Z]+\/[a-zA-Z]+(?:\/[a-zA-Z]+)?)[\)\]]?/; - const match = rawName.match(regex); - - if (match) { - let strippedName = rawName.replace(match[0], '').trim(); - - if (!strippedName || strippedName === '') { - strippedName = rawName; - } - - return { - cleanedDisplayName: strippedName, - inlinePronoun: match[1].toLowerCase().slice(0, 16), - }; - } - - return { cleanedDisplayName: rawName, inlinePronoun: null }; + return getParsedPronouns(rawName, parsePronouns); }, [pmp, senderDisplayName, parsePronouns]); const mergedPronouns = useMemo(() => { diff --git a/src/app/utils/pronouns.ts b/src/app/utils/pronouns.ts index c653d9fd..6d111a2a 100644 --- a/src/app/utils/pronouns.ts +++ b/src/app/utils/pronouns.ts @@ -63,3 +63,45 @@ export function filterPronounsByLanguage( return filteredPronouns; } + +const pronounParseCache = new Map< + string, + { cleanedDisplayName: string; inlinePronoun: string | null } +>(); + +export function getParsedPronouns(rawName: string, parseSetting: boolean) { + if (!parseSetting || !rawName) { + return { cleanedDisplayName: rawName, inlinePronoun: null }; + } + + if (pronounParseCache.has(rawName)) { + return pronounParseCache.get(rawName)!; + } + + // match text like (she/her) or [he/they/them] but not (hi) + const regex = /[([]?([a-zA-Z]+\/[a-zA-Z]+(?:\/[a-zA-Z]+)?)[)\]]?/; + const match = rawName.match(regex); + + let result: { cleanedDisplayName: string; inlinePronoun: string | null } = { + cleanedDisplayName: rawName, + inlinePronoun: null, + }; + + if (match) { + let strippedName = rawName.replace(match[0], '').trim(); + if (!strippedName || strippedName === '') { + strippedName = rawName; + } + result = { + cleanedDisplayName: strippedName, + inlinePronoun: match[1].toLowerCase().slice(0, 16), + }; + } + + if (pronounParseCache.size > 1000) { + pronounParseCache.clear(); + } + + pronounParseCache.set(rawName, result); + return result; +} From dcfafa4f5e07ecb0a62d2ab47b5e2c2b5bec7092 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Tue, 17 Mar 2026 21:28:22 -0500 Subject: [PATCH 3/3] Update Message.tsx --- src/app/features/room/message/Message.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index 2602ab26..7ce5adbe 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -995,7 +995,7 @@ function MessageInternal( autoFocus value={nickDraft} onChange={(e) => setNickDraft(e.target.value)} - placeholder={displayName} + placeholder={cleanedDisplayName} onKeyDown={(e) => { if (e.key === 'Enter') { setNickname(senderId, nickDraft || undefined, mx);