Add PMP User Profile

This commit is contained in:
Null authored and Josie committed 2026-08-09 15:54:21 +01:00
1 parent 62fe517b1d
commit 31fa6c42e8
27 files changed
+160 -25

No files matched your search

@@ -0,0 +1,5 @@
---
default: minor
---
# PMP User Heroes, Fix+Refactor Persona Picker
@@ -9,7 +9,7 @@ import { UserRoomProfile } from './user-profile';
import { ResponsiveMenu } from './ResponsiveMenu';
function UserRoomProfileContextMenu({ state }: { state: UserRoomProfileState }) {
const { roomId, spaceId, userId, cords, position, initialProfile } = state;
const { roomId, spaceId, userId, pmp, cords, position, initialProfile } = state;
const allJoinedRooms = useAllJoinedRoomsSet();
const getRoom = useGetRoom(allJoinedRooms);
const room = getRoom(roomId);
@@ -37,6 +37,7 @@ function UserRoomProfileContextMenu({ state }: { state: UserRoomProfileState })
userId={userId}
initialProfile={initialProfile}
onSurfaceColorChange={setSurfaceColor}
pmp={pmp}
/>
</RoomProvider>
</SpaceProvider>
@@ -253,6 +253,7 @@ export const EventHistory = as<'div', EventHistoryProps>(
room.roomId,
space?.roomId,
readerId,
undefined,
getMouseEventCords(event.nativeEvent),
'Bottom'
);
@@ -93,6 +93,7 @@ export const EventReaders = as<'div', EventReadersProps>(
room.roomId,
space?.roomId,
readerId,
undefined,
getMouseEventCords(event.nativeEvent),
'Bottom'
);
@@ -451,10 +451,11 @@ export function MessagePreview({
room.roomId,
undefined,
sender,
perMessageProfile,
evt.currentTarget.getBoundingClientRect()
);
},
[openUserRoomProfile, room.roomId, sender]
[openUserRoomProfile, room.roomId, perMessageProfile, sender]
);
return (
@@ -31,7 +31,7 @@ export function OverlayStackProvider({ children }: { children: ReactNode }) {
setClaims((prev) =>
prev.some((claim) => claim.id === id)
? prev
: [...prev, { id, seq }].sort((a, b) => a.seq - b.seq)
: [...prev, { id, seq }].toSorted((a, b) => a.seq - b.seq)
),
release: (id) => setClaims((prev) => prev.filter((claim) => claim.id !== id)),
}),
+48 -3
View File
@@ -43,6 +43,9 @@ import { useTimeoutToggle } from '$hooks/useTimeoutToggle';
import { CopyIcon, CrossIcon } from '@phosphor-icons/react';
import { useOpenSettings } from '$features/settings';
import { ModalOverlay } from '$components/modal-overlay/ModalOverlay';
import type { Persona } from '$app/persona';
import { useProfileCosmetics } from '$features/room/persona-picker/PersonaPicker';
import type { MatrixClient } from 'matrix-js-sdk';
type UserHeroProps = {
userId: string;
@@ -258,10 +261,13 @@ export function UserHero({
}
type UserHeroNameProps = {
mx?: MatrixClient;
displayName?: string;
userId: string;
server?: string;
customHeroCards?: boolean;
pmp?: Persona;
clearPmp?: () => void;
};
type UserHeroNameInnerProps = {
@@ -272,6 +278,8 @@ type UserHeroNameInnerProps = {
color?: string;
font?: string;
customHeroCards?: boolean;
isPmp?: boolean;
clearPmp?: () => void;
};
function UserHeroNameInner({
@@ -281,6 +289,8 @@ function UserHeroNameInner({
server,
color,
font,
isPmp,
clearPmp,
}: UserHeroNameInnerProps) {
const [copied, setCopied] = useTimeoutToggle();
const [isHovered, setIsHovered] = useState(false);
@@ -332,26 +342,61 @@ function UserHeroNameInner({
)
}
/>
{isPmp && (
<>
{' - '}
<Chip
onClick={(evt) => {
evt.stopPropagation();
clearPmp?.();
}}
style={{ backgroundColor: 'transparent', color: 'inherit', padding: '0' }}
before={
<Text
size="T200"
className={classNames(BreakWord, LineClamp3, css.LinkUnderline)}
truncate
>
View account profile
</Text>
}
/>
</>
)}
</Box>
</Box>
);
}
export function UserHeroName({ displayName, userId, server, customHeroCards }: UserHeroNameProps) {
export function UserHeroName({
mx,
displayName,
userId,
server,
customHeroCards,
pmp,
clearPmp,
}: UserHeroNameProps) {
const username = getMxIdLocalPart(userId);
const nick = useNickname(userId);
// personas
const { nameColor: getPmpNameColor } = useProfileCosmetics(mx);
const pmpNameColor = pmp?.['eu.she-a.color'] ? getPmpNameColor?.(pmp) : null;
// Sable username color and fonts
const { color, font } = useSableCosmetics(userId, useRoom(), customHeroCards);
const shownName = nick ?? displayName ?? username ?? userId;
const shownName = pmp?.displayname ?? nick ?? displayName ?? username ?? userId;
return (
<UserHeroNameInner
username={username}
isPmp={!!pmp}
server={server}
shownName={shownName}
color={color}
color={pmpNameColor ?? color}
font={font}
clearPmp={clearPmp}
/>
);
}
@@ -62,6 +62,8 @@ import { KnownMembership } from '$types/matrix-sdk';
import { useRoomMemberHydration } from '$hooks/useRoomMemberHydration';
import * as css from './styles.css';
import * as prefix from '$unstable/prefixes';
import type { Persona } from '$app/persona';
import { useProfileCosmetics } from '$features/room/persona-picker/PersonaPicker';
const KNOWN_KEYS = new Set([
prefix.MATRIX_SABLE_UNSTABLE_PROFILE_BIOGRAPHY_PROPERTY_NAME,
@@ -80,6 +82,7 @@ const KNOWN_KEYS = new Set([
type UserExtendedSectionProps = {
profile: UserProfile;
pmp?: Persona;
htmlReactParserOptions: HTMLReactParserOptions;
linkifyOpts: LinkifyOpts;
innerColor?: string;
@@ -96,6 +99,7 @@ const renderValue = (val: unknown) => {
function UserExtendedSection({
profile,
pmp,
htmlReactParserOptions,
linkifyOpts,
innerColor,
@@ -127,7 +131,7 @@ function UserExtendedSection({
const languagesToFilterFor = getSettings().filterPronounsLanguages ?? ['en'];
const pronouns = filterPronounsByLanguage(
profile.pronouns,
pmp?.['io.fsky.nyx.pronouns'] ?? profile.pronouns,
languageFilterEnabled,
languagesToFilterFor
)
@@ -403,11 +407,13 @@ function UserExtendedSection({
type UserRoomProfileProps = {
userId: string;
pmp?: Persona;
initialProfile?: Partial<UserProfile>;
onSurfaceColorChange?: (color: string) => void;
};
export function UserRoomProfile({
userId,
pmp: initialPmp,
initialProfile,
onSurfaceColorChange,
}: Readonly<UserRoomProfileProps>) {
@@ -456,8 +462,17 @@ export function UserRoomProfile({
useRoomMemberHydration(room, userId);
const [pmp, setPmp] = useState(initialPmp);
const { avatarUrl: getPmpAvatarUrl } = useProfileCosmetics(mx);
const pmpAvatarUrl = pmp?.avatar_url ? getPmpAvatarUrl?.(pmp) : null;
const handleClearPmp = () => {
setPmp(undefined);
};
const avatarMxc = getMemberAvatarMxc(room, userId) ?? extendedProfile.avatarUrl;
const avatarUrl = (avatarMxc && mxcUrlToHttp(mx, avatarMxc, useAuthentication)) ?? undefined;
const avatarUrl =
pmpAvatarUrl ?? (avatarMxc && mxcUrlToHttp(mx, avatarMxc, useAuthentication)) ?? undefined;
const parsedBanner =
typeof extendedProfile.bannerUrl === 'string'
@@ -607,10 +622,13 @@ export function UserRoomProfile({
>
<Box gap="200" alignItems="Center" wrap="Wrap" style={{ color: textColor }}>
<UserHeroName
displayName={displayName}
mx={mx}
displayName={pmp?.displayname ?? displayName}
userId={userId}
customHeroCards={showCustomHeroCard}
server={server}
pmp={pmp}
clearPmp={handleClearPmp}
/>
{userId !== myUserId && (
<Button
@@ -633,6 +651,7 @@ export function UserRoomProfile({
</Box>
<UserExtendedSection
profile={extendedProfile}
pmp={pmp}
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
innerColor={innerColor}
@@ -131,3 +131,11 @@ export const UserHeroMenuItem = style({
},
},
});
export const LinkUnderline = style({
cursor: 'pointer',
textDecoration: 'underline',
':hover': {
textDecoration: 'none',
},
});
@@ -65,6 +65,7 @@ export function LiveChip({ count, room, members }: LiveChipProps) {
room.roomId,
undefined,
userId,
undefined,
getMouseEventCords(evt.nativeEvent),
'Right'
)
@@ -51,6 +51,7 @@ export function MemberGlance({ room, members, speakers, max = 6 }: MemberGlanceP
room.roomId,
undefined,
userId,
undefined,
getMouseEventCords(evt.nativeEvent),
'Top'
)
+1
View File
@@ -59,6 +59,7 @@ function CallMemberCard({ member }: CallMemberCardProps) {
room.roomId,
undefined,
userId,
undefined,
getMouseEventCords(evt.nativeEvent),
'Right'
)
@@ -142,7 +142,13 @@ export function Members({ requestBack, requestClose }: MembersProps) {
const btn = evt.currentTarget as HTMLButtonElement;
const userId = btn.getAttribute('data-user-id');
if (userId) {
openProfile(room.roomId, space?.roomId, userId, getMouseEventCords(evt.nativeEvent));
openProfile(
room.roomId,
space?.roomId,
userId,
undefined,
getMouseEventCords(evt.nativeEvent)
);
}
};
+7 -1
View File
@@ -37,7 +37,13 @@ export function RoomNavUser({ room, callMembership, hideText }: RoomNavUserProps
const isCallParticipant = isActiveCall && userId !== mx.getUserId();
const handleNavUserClick: MouseEventHandler<HTMLButtonElement> = (evt) => {
openProfile(room.roomId, space?.roomId, userId, evt.currentTarget.getBoundingClientRect());
openProfile(
room.roomId,
space?.roomId,
userId,
undefined,
evt.currentTarget.getBoundingClientRect()
);
};
const ariaLabel = isCallParticipant ? `Call Participant: ${name}` : name;
+1 -1
View File
@@ -311,7 +311,7 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) {
// BODGE, dependent on menuItem height staying at toRem(40)
cords.y = Math.min(cords.y, window.innerHeight - 42);
openUserRoomProfile(room.roomId, space?.roomId, userId, cords, 'Left');
openUserRoomProfile(room.roomId, space?.roomId, userId, undefined, cords, 'Left');
};
const [memberSidebarWidth, setMemberSidebarWidth] = useSetting(
+2
View File
@@ -78,6 +78,7 @@ import type { IImageContent } from '$types/matrix/common';
import { useTimelineRendererContext } from '$hooks/timeline/useTimelineRendererContext';
import { TimelineScrollingProvider, useScrollActivity } from '$hooks/useTimelineScrollActivity';
import * as css from './RoomTimeline.css';
import type { Persona } from '$app/persona';
const MAX_VIEWPORT_FILL_PAGINATIONS = 5;
@@ -926,6 +927,7 @@ export function RoomTimeline({
roomId: string,
spaceId: string | undefined,
userId: string,
pmp: Persona | undefined,
rect: DOMRect,
undefinedArg?: undefined,
options?: unknown
+2
View File
@@ -46,6 +46,7 @@ import { RoomViewFollowing, RoomViewFollowingPlaceholder } from './RoomViewFollo
import * as css from './ThreadDrawer.css';
import { SidebarResizer } from '$pages/client/sidebar/SidebarResizer';
import { isMobileOrTablet } from '$utils/platform';
import type { Persona } from '$app/persona';
type ThreadDrawerProps = {
room: Room;
@@ -150,6 +151,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
roomId: string,
spaceId: string | undefined,
userId: string,
pmp: Persona | undefined,
rect: DOMRect,
undefinedArg?: undefined,
options?: unknown
@@ -665,6 +665,7 @@ function MessageInternal(
as="button"
size="300"
data-user-id={senderId}
data-parent-message-id={mEvent.getId() ?? ':3'}
onClick={onUserClick}
>
<UserAvatar
@@ -78,7 +78,7 @@ type TemporaryPersonaPickerProps = {
anchor?: RectCords;
};
function useProfileCosmetics(mx: MatrixClient) {
export function useProfileCosmetics(mx: MatrixClient | undefined) {
const useAuthentication = useMediaAuthentication();
const activeTheme = useActiveTheme();
@@ -93,7 +93,9 @@ function useProfileCosmetics(mx: MatrixClient) {
const avatarUrl = useCallback(
(profile: PerMessageProfileMsc4461) => {
if (profile.avatar_url !== undefined) {
return mxcUrlToHttp(mx, profile.avatar_url, useAuthentication, 96, 96, 'crop') ?? undefined;
return (
mxcUrlToHttp(mx!, profile.avatar_url, useAuthentication, 96, 96, 'crop') ?? undefined
);
} else {
return undefined;
}
@@ -101,6 +103,7 @@ function useProfileCosmetics(mx: MatrixClient) {
[mx, useAuthentication]
);
if (!mx) return { avatarUrl: undefined, nameColor: undefined };
return { nameColor, avatarUrl };
}
function useProfiles(
@@ -403,7 +406,7 @@ export function PersonaPicker({
>
<UserAvatar
userId={profile.id}
src={avatarUrl(profile)}
src={avatarUrl?.(profile)}
fallbackColor={profile['eu.she-a.color']?.on_light ?? undefined}
renderFallback={() => (
<Text as="span" size="H4" aria-label="Avatar fallback">
@@ -418,7 +421,7 @@ export function PersonaPicker({
<Box direction="Column">
<Text
truncate
style={{ color: nameColor(profile) ?? undefined, maxWidth: toRem(150) }}
style={{ color: nameColor?.(profile) ?? undefined, maxWidth: toRem(150) }}
>
{profile.displayname}
</Text>
@@ -483,7 +486,7 @@ export function PersonaPicker({
<UserAvatar
className={css.PersonaPickerButtonAvatarImage}
userId={defactoPersona()!.id}
src={avatarUrl(defactoPersona()!)}
src={avatarUrl?.(defactoPersona()!)}
renderFallback={() => (
<Text as="span" size="H6" aria-label="Avatar fallback">
{nameInitials(defactoPersona()!.displayname)}
@@ -584,7 +587,7 @@ export function TemporaryPersonaPicker({
>
<UserAvatar
userId={profile.id}
src={avatarUrl(profile)}
src={avatarUrl?.(profile)}
fallbackColor={profile['eu.she-a.color']?.on_light ?? undefined}
renderFallback={() => (
<Text as="span" size="H4" aria-label="Avatar fallback">
@@ -599,7 +602,7 @@ export function TemporaryPersonaPicker({
<Box direction="Column">
<Text
truncate
style={{ color: nameColor(profile) ?? undefined, maxWidth: toRem(150) }}
style={{ color: nameColor?.(profile) ?? undefined, maxWidth: toRem(150) }}
>
{profile.displayname}
</Text>
@@ -131,6 +131,7 @@ export const PollResponsesViewer = as<'div', PollResponsesViewerProps>(
room.roomId,
space?.roomId,
senderId,
undefined,
getMouseEventCords(event.nativeEvent),
'Bottom'
);
@@ -116,6 +116,7 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
room.roomId,
space?.roomId,
senderId,
undefined,
getMouseEventCords(event.nativeEvent),
'Bottom'
);
+16 -1
View File
@@ -11,6 +11,8 @@ import { getMemberDisplayName } from '$utils/room/display';
import { extractReplyDraftBody, resolveReplyDraftTarget } from '$utils/room/relations';
import { createMentionElement, moveCursor } from '$components/editor';
import * as prefix from '$unstable/prefixes';
import type { Persona } from '$hooks/usePerMessageProfile';
import { convertBeeperFormatToOurPerMessageProfile } from '$hooks/usePerMessageProfile';
/**
* The profile popup reads name, avatar and the identity fields off the room
@@ -55,6 +57,7 @@ export interface UseTimelineActionsOptions {
roomId: string,
spaceId: string | undefined,
userId: string,
pmp: Persona | undefined,
rect: DOMRect,
undefinedArg?: undefined,
options?: unknown
@@ -104,16 +107,28 @@ export function useTimelineActions({
const userId = evt.currentTarget.getAttribute('data-user-id');
if (!userId) return;
const messageId = evt.currentTarget.getAttribute('data-parent-message-id');
let perMessageProfile;
if (messageId) {
const pmp = room.findEventById(messageId)?.getContent()[
prefix.MATRIX_UNSTABLE_PER_MESSAGE_PROFILE_PROPERTY_NAME
];
if (pmp) {
perMessageProfile = convertBeeperFormatToOurPerMessageProfile(pmp);
}
}
openUserRoomProfile(
room.roomId,
spaceId,
userId,
perMessageProfile,
evt.currentTarget.getBoundingClientRect(),
undefined,
buildCachedProfilePayload(getGlobalProfile(userId))
);
},
[room.roomId, spaceId, openUserRoomProfile, getGlobalProfile]
[room, spaceId, openUserRoomProfile, getGlobalProfile]
);
const handleUsernameClick: MouseEventHandler<HTMLButtonElement> = useCallback(
@@ -91,8 +91,9 @@ import { EncryptedContent, Message, Reactions } from '$features/room/message';
import { useSableCosmetics } from '$hooks/useSableCosmetics';
import { useRoomMemberHydration } from '$hooks/useRoomMemberHydration';
import { M_POLL_START } from 'matrix-js-sdk';
import type { Persona } from '$app/persona';
function DecoratedUser({ room, userId, userName }: DecoratedUserProps) {
function DecoratedUser({ room, userId, userName, pmp }: DecoratedUserProps) {
const { color, font } = useSableCosmetics(userId, room ?? ({} as Room));
const openUserRoomProfile = useOpenUserRoomProfile();
@@ -104,10 +105,11 @@ function DecoratedUser({ room, userId, userName }: DecoratedUserProps) {
room.roomId,
undefined,
userId,
pmp,
evt.currentTarget.getBoundingClientRect()
);
},
[room, userId, openUserRoomProfile]
[room, userId, openUserRoomProfile, pmp]
);
return (
@@ -121,6 +123,7 @@ type DecoratedUserProps = {
room: Room;
userId: string;
userName?: string;
pmp?: Persona;
};
type ThreadReplyChipProps = {
+7 -1
View File
@@ -39,7 +39,13 @@ function DecoratedUser({ roomId, userId, userName }: DecoratedUserProps) {
(evt) => {
evt.preventDefault();
evt.stopPropagation();
openUserRoomProfile(roomId, undefined, userId, evt.currentTarget.getBoundingClientRect());
openUserRoomProfile(
roomId,
undefined,
userId,
undefined,
evt.currentTarget.getBoundingClientRect()
);
},
[roomId, userId, openUserRoomProfile]
);
+1 -1
View File
@@ -38,7 +38,7 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
if (typeof mentionId !== 'string') return;
if (isUserId(mentionId)) {
openProfile(roomId, space?.roomId, mentionId, target.getBoundingClientRect());
openProfile(roomId, space?.roomId, mentionId, undefined, target.getBoundingClientRect());
return;
}
+4 -1
View File
@@ -4,6 +4,7 @@ import type { Position, RectCords } from 'folds';
import type { UserProfile } from '$hooks/useUserProfile';
import type { UserRoomProfileState } from '$state/userRoomProfile';
import { userRoomProfileAtom } from '$state/userRoomProfile';
import type { Persona } from '$app/persona';
export const useUserRoomProfileState = (): UserRoomProfileState | undefined => {
const data = useAtomValue(userRoomProfileAtom);
@@ -25,6 +26,7 @@ type OpenCallback = (
roomId: string,
spaceId: string | undefined,
userId: string,
pmp: Persona | undefined,
cords: RectCords,
position?: Position,
initialProfile?: Partial<UserProfile>
@@ -34,11 +36,12 @@ export const useOpenUserRoomProfile = (): OpenCallback => {
const setUserRoomProfile = useSetAtom(userRoomProfileAtom);
const open: OpenCallback = useCallback(
(roomId, spaceId, userId, cords, position, initialProfile) => {
(roomId, spaceId, userId, pmp, cords, position, initialProfile) => {
setUserRoomProfile({
roomId,
spaceId,
userId,
pmp,
cords,
position,
initialProfile,
+2
View File
@@ -1,11 +1,13 @@
import type { Position, RectCords } from 'folds';
import { atom } from 'jotai';
import type { UserProfile } from '$hooks/useUserProfile';
import type { Persona } from '$app/persona';
export type UserRoomProfileState = {
userId: string;
roomId: string;
spaceId?: string;
pmp?: Persona;
cords: RectCords;
position?: Position;
initialProfile?: Partial<UserProfile>;