Pronoun pills, pronoun caching, and toggle in settings

This commit is contained in:
7w1 committed 2026-02-23 23:45:56 -06:00
1 parent 1633758c93
commit bd46b4cc4f
5 files changed
+93 -5

No files matched your search

+38 -2
View File
@@ -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<string>();
const [profileCache, setProfileCache] = useState<Record<string, any>>({});
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<string>();
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<HTMLButtonElement> = 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 && (
+43 -2
View File
@@ -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<HTMLElement>) => void, delay = 700) {
@@ -723,6 +726,38 @@ function useMobileLongPress(callback: (e: React.PointerEvent<HTMLElement>) => 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 (
<Box
alignItems="Center"
style={{
backgroundColor: 'var(--sable-surface-var-container)',
padding: '0 5px',
borderRadius: config.radii.Pill,
height: '16px',
display: 'inline-flex',
}}
>
<Text
style={{
color: tagColor,
fontSize: '0.7rem',
lineHeight: '1',
textTransform: 'lowercase',
opacity: 0.8,
}}
>
{display}{hasMore ? '...' : ''}
</Text>
</Box>
);
}
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<HTMLDivElement>(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"
>
<Box alignItems="Center" gap="200">
<Box alignItems="Center" gap="100">
<Username
as="button"
style={{
@@ -826,6 +864,9 @@ export const Message = as<'div', MessageProps>(
<UsernameBold>{senderDisplayName}</UsernameBold>
</Text>
</Username>
{showPronouns && (
<PronounTag pronouns={senderPronouns} tagColor={usernameColor} />
)}
{tagIconSrc && <PowerIcon size="100" iconSrc={tagIconSrc} />}
</Box>
<Box shrink="No" gap="100">
@@ -152,6 +152,7 @@ function Privacy() {
function IdentityCosmetics() {
const [legacyUsernameColor, setLegacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor');
const [showPronouns, setShowPronouns] = useSetting(settingsAtom, 'showPronouns');
return (
<Box direction="Column" gap="100">
@@ -163,6 +164,13 @@ function IdentityCosmetics() {
after={<Switch variant="Primary" value={legacyUsernameColor} onChange={setLegacyUsernameColor} />}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Show Pronouns"
description="Display user pronouns in the message timeline."
after={<Switch variant="Primary" value={showPronouns} onChange={setShowPronouns} />}
/>
</SequenceCard>
</Box>
);
}
+2
View File
@@ -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,
+2 -1
View File
@@ -7,6 +7,7 @@ export type UserRoomProfileState = {
spaceId?: string;
cords: RectCords;
position?: Position;
pronouns?: any[];
};
export const userRoomProfileAtom = atom<UserRoomProfileState | undefined>(undefined);
export const userRoomProfileAtom = atom<UserRoomProfileState | undefined>(undefined);