Merge pull request #262 from trash-pandy/sable/feat/pmp
Add MSC4144 per-message-profile rendering
This commit is contained in:
2 files changed
+27
-5
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
sable: patch
|
||||
---
|
||||
|
||||
Add rendering of per-message-profiles.
|
||||
@@ -349,6 +349,18 @@ function MessageInternal(
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
|
||||
const pmp = useMemo(
|
||||
() =>
|
||||
mEvent.event.content?.['com.beeper.per_message_profile'] as
|
||||
| {
|
||||
avatar_url: string | undefined;
|
||||
displayname: string | undefined;
|
||||
id: string | undefined;
|
||||
}
|
||||
| undefined,
|
||||
[mEvent]
|
||||
);
|
||||
|
||||
// Profiles and Colors
|
||||
const profile = useUserProfile(senderId, room);
|
||||
const { color: usernameColor, font: usernameFont } = useSableCosmetics(senderId, room);
|
||||
@@ -358,9 +370,14 @@ function MessageInternal(
|
||||
// avatar so per-room avatar overrides are respected in the timeline.
|
||||
const avatarUrl = useMemo(() => {
|
||||
if (collapse) return undefined;
|
||||
const mxc = getMemberAvatarMxc(room, senderId) || profile.avatarUrl;
|
||||
const mxc = pmp?.avatar_url || getMemberAvatarMxc(room, senderId) || profile.avatarUrl;
|
||||
return mxc ? mxcUrlToHttp(mx, mxc, useAuthentication, 48, 48, 'crop') : undefined;
|
||||
}, [collapse, profile.avatarUrl, senderId, mx, room, useAuthentication]);
|
||||
}, [pmp, collapse, profile.avatarUrl, senderId, mx, room, useAuthentication]);
|
||||
|
||||
const displayName = useMemo(
|
||||
() => pmp?.displayname || senderDisplayName,
|
||||
[pmp, senderDisplayName]
|
||||
);
|
||||
|
||||
const cachedAvatar = useBlobCache(avatarUrl ?? undefined);
|
||||
|
||||
@@ -424,7 +441,7 @@ function MessageInternal(
|
||||
onClick={onUsernameClick}
|
||||
>
|
||||
<Text as="span" size={messageLayout === MessageLayout.Bubble ? 'T300' : 'T400'} truncate>
|
||||
<UsernameBold>{senderDisplayName}</UsernameBold>
|
||||
<UsernameBold>{displayName}</UsernameBold>
|
||||
</Text>
|
||||
</Username>
|
||||
{showPronouns && (
|
||||
@@ -467,7 +484,7 @@ function MessageInternal(
|
||||
<UserAvatar
|
||||
userId={senderId}
|
||||
src={cachedAvatar}
|
||||
alt={senderDisplayName}
|
||||
alt={displayName}
|
||||
renderFallback={() => <Icon size="200" src={Icons.User} filled />}
|
||||
/>
|
||||
</Avatar>
|
||||
@@ -873,7 +890,7 @@ function MessageInternal(
|
||||
autoFocus
|
||||
value={nickDraft}
|
||||
onChange={(e) => setNickDraft(e.target.value)}
|
||||
placeholder={senderDisplayName}
|
||||
placeholder={displayName}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
setNickname(senderId, nickDraft || undefined, mx);
|
||||
|
||||
Reference in new issue
Block a user