From bd46b4cc4f87990f7cdfaf8cf18fc1b5bd39e0db Mon Sep 17 00:00:00 2001 From: 7w1 Date: Mon, 23 Feb 2026 23:45:56 -0600 Subject: [PATCH] Pronoun pills, pronoun caching, and toggle in settings --- src/app/features/room/RoomTimeline.tsx | 40 ++++++++++++++++- src/app/features/room/message/Message.tsx | 45 ++++++++++++++++++- .../features/settings/cosmetics/Cosmetics.tsx | 8 ++++ src/app/state/settings.ts | 2 + src/app/state/userRoomProfile.ts | 3 +- 5 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 88138ec3..315207b5 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -443,6 +443,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli const canSendReaction = permissions.event(MessageEvent.Reaction, mx.getSafeUserId()); const canPinEvent = permissions.stateEvent(StateEvent.RoomPinnedEvents, mx.getSafeUserId()); const [editId, setEditId] = useState(); + const [profileCache, setProfileCache] = useState>({}); const roomToParents = useAtomValue(roomToParentsAtom); const unread = useRoomUnread(room.roomId, roomToUnreadAtom); @@ -901,6 +902,37 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli } }, [scrollToElement, editId]); + // fetch user profiles, specifically pronouns + useEffect(() => { + const visibleIndices = getItems(); + const sendersToFetch = new Set(); + + visibleIndices.forEach((index) => { + const [eventTimeline, baseIndex] = getTimelineAndBaseIndex(timeline.linkedTimelines, index); + const mEvent = getTimelineEvent(eventTimeline!, getTimelineRelativeIndex(index, baseIndex)); + const senderId = mEvent?.getSender(); + + if (senderId && !profileCache[senderId]) { + sendersToFetch.add(senderId); + } + }); + + sendersToFetch.forEach(async (userId) => { + setProfileCache(prev => ({ ...prev, [userId]: { loading: true } })); + + const [err, info] = await to(mx.getProfileInfo(userId)); + if (err || !info) return; + + setProfileCache((prev) => ({ + ...prev, + [userId]: { + pronouns: (info as any)['io.fsky.nyx.pronouns'], + loading: false + }, + })); + }); + }, [timeline.range, timeline.linkedTimelines, mx, profileCache, getItems]); + const handleJumpToLatest = () => { if (eventId) { navigateRoom(room.roomId, undefined, { replace: true }); @@ -938,15 +970,18 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli if (!userId) { throw new Error('Button should have "data-user-id" attribute!'); } + openUserRoomProfile( room.roomId, space?.roomId, userId, - evt.currentTarget.getBoundingClientRect() + evt.currentTarget.getBoundingClientRect(), + profileCache[userId]?.pronouns ); }, - [room, space, openUserRoomProfile] + [room, space, openUserRoomProfile, profileCache] ); + const handleUsernameClick: MouseEventHandler = useCallback( (evt) => { evt.preventDefault(); @@ -1077,6 +1112,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli onUsernameClick={handleUsernameClick} onReplyClick={handleReplyClick} onReactionToggle={handleReactionToggle} + senderPronouns={profileCache[senderId]?.pronouns} onEditId={handleEdit} reply={ replyEventId && ( diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index f78d415e..a9e5909e 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -61,7 +61,7 @@ import { isRoomAlias, mxcUrlToHttp, } from '../../../utils/matrix'; -import { MessageLayout, MessageSpacing } from '../../../state/settings'; +import { MessageLayout, MessageSpacing, settingsAtom } from '../../../state/settings'; import { nicknamesAtom, setNicknameAtom } from '../../../state/nicknames'; import { useMatrixClient } from '../../../hooks/useMatrixClient'; import { useRecentEmoji } from '../../../hooks/useRecentEmoji'; @@ -85,6 +85,8 @@ import { getPowerTagIconSrc } from '../../../hooks/useMemberPowerTag'; import { useSableCosmetics } from '../../../hooks/useSableCosmetics'; import { SwipeableMessageWrapper } from '../../../components/SwipeableMessageWrapper'; import { mobileOrTablet } from '../../../utils/user-agent'; +import { useUserProfile } from '../../../hooks/useUserProfile'; +import { useSetting } from '../../../state/hooks/settings'; export type ReactionHandler = (keyOrMxc: string, shortcode: string) => void; @@ -688,6 +690,7 @@ export type MessageProps = { memberPowerTag?: MemberPowerTag; hour24Clock: boolean; dateFormatString: string; + senderPronouns?: any[]; }; function useMobileLongPress(callback: (e: React.PointerEvent) => void, delay = 700) { @@ -723,6 +726,38 @@ function useMobileLongPress(callback: (e: React.PointerEvent) => vo }; } +function PronounTag({ pronouns, tagColor }: { pronouns?: any[]; tagColor: string }) { + if (!pronouns || pronouns.length === 0) return null; + + const display = pronouns.slice(0, 2).map((p) => p.summary).join('/'); + const hasMore = pronouns.length > 2; + + return ( + + + {display}{hasMore ? '...' : ''} + + + ); +} + export const Message = as<'div', MessageProps>( ( { @@ -752,6 +787,7 @@ export const Message = as<'div', MessageProps>( hour24Clock, dateFormatString, children, + senderPronouns, ...props }, ref @@ -788,6 +824,8 @@ export const Message = as<'div', MessageProps>( const [mobileOptionsOpen, setMobileOptionsOpen] = useState(false); const optionsRef = useRef(null); + const [showPronouns] = useSetting(settingsAtom, 'showPronouns'); + useEffect(() => { if (!mobileOptionsOpen) return undefined; const handleClickOutside = (e: globalThis.Event) => { @@ -807,7 +845,7 @@ export const Message = as<'div', MessageProps>( alignItems="Baseline" grow="Yes" > - + ( {senderDisplayName} + {showPronouns && ( + + )} {tagIconSrc && } diff --git a/src/app/features/settings/cosmetics/Cosmetics.tsx b/src/app/features/settings/cosmetics/Cosmetics.tsx index 0a8a2fe2..489b2e00 100644 --- a/src/app/features/settings/cosmetics/Cosmetics.tsx +++ b/src/app/features/settings/cosmetics/Cosmetics.tsx @@ -152,6 +152,7 @@ function Privacy() { function IdentityCosmetics() { const [legacyUsernameColor, setLegacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor'); + const [showPronouns, setShowPronouns] = useSetting(settingsAtom, 'showPronouns'); return ( @@ -163,6 +164,13 @@ function IdentityCosmetics() { after={} /> + + } + /> + ); } diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index ef3a8563..987b23b7 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -54,6 +54,7 @@ export interface Settings { privacyBlur: boolean; privacyBlurAvatars: boolean; privacyBlurEmotes: boolean; + showPronouns: boolean, // Sable features! mobileGestures: boolean; @@ -98,6 +99,7 @@ const defaultSettings: Settings = { privacyBlur: false, privacyBlurAvatars: false, privacyBlurEmotes: false, + showPronouns: true, // Sable features! mobileGestures: true, diff --git a/src/app/state/userRoomProfile.ts b/src/app/state/userRoomProfile.ts index cf4e403a..47d49cba 100644 --- a/src/app/state/userRoomProfile.ts +++ b/src/app/state/userRoomProfile.ts @@ -7,6 +7,7 @@ export type UserRoomProfileState = { spaceId?: string; cords: RectCords; position?: Position; + pronouns?: any[]; }; -export const userRoomProfileAtom = atom(undefined); +export const userRoomProfileAtom = atom(undefined); \ No newline at end of file