From 95a459722d0079cf8a002a73efac55d31360fb4b Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sat, 25 Jul 2026 20:13:16 +0200 Subject: [PATCH] fix: pass cached profile data and guard failed-send actions in threads --- src/app/features/room/ThreadDrawer.tsx | 16 ++++-- src/app/hooks/timeline/useTimelineActions.ts | 59 +++++++++++--------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/app/features/room/ThreadDrawer.tsx b/src/app/features/room/ThreadDrawer.tsx index ccc11b6fd..eedc147ce 100644 --- a/src/app/features/room/ThreadDrawer.tsx +++ b/src/app/features/room/ThreadDrawer.tsx @@ -5,6 +5,7 @@ import { Chats, composerIcon, X } from '$components/icons/phosphor'; import type { IEvent, Room, CryptoBackend } from '$types/matrix-sdk'; import { Direction, + EventStatus, MatrixEvent, MatrixEventEvent, ReceiptType, @@ -13,6 +14,8 @@ import { ThreadEvent, EventType, } from '$types/matrix-sdk'; +import { useSpaceOptionally } from '$hooks/useSpace'; +import { buildCachedProfilePayload } from '$hooks/timeline/useTimelineActions'; import { useAtomValue, useSetAtom, useStore } from 'jotai'; import { ReactEditor } from 'slate-react'; import type { HTMLReactParserOptions } from 'html-react-parser'; @@ -253,6 +256,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra // User profile popup const openUserRoomProfile = useOpenUserRoomProfile(); + const optionalSpace = useSpaceOptionally(); // Thread timeline data for useProcessedTimeline const thread = room.getThread(threadRootId); @@ -592,12 +596,14 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra if (!userId) return; openUserRoomProfile( room.roomId, - undefined, + optionalSpace?.roomId, userId, - evt.currentTarget.getBoundingClientRect() + evt.currentTarget.getBoundingClientRect(), + undefined, + buildCachedProfilePayload(getGlobalProfile(userId)) ); }, - [room, openUserRoomProfile] + [room, optionalSpace, openUserRoomProfile, getGlobalProfile] ); const handleUsernameClick: MouseEventHandler = useCallback( @@ -701,13 +707,15 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra const handleResend = useCallback( (event: MatrixEvent) => { - mx.resendEvent(event, room); + if (event.getAssociatedStatus() !== EventStatus.NOT_SENT) return; + mx.resendEvent(event, room).catch(() => undefined); }, [mx, room] ); const handleDeleteFailedSend = useCallback( (event: MatrixEvent) => { + if (event.getAssociatedStatus() !== EventStatus.NOT_SENT) return; mx.cancelPendingEvent(event); }, [mx] diff --git a/src/app/hooks/timeline/useTimelineActions.ts b/src/app/hooks/timeline/useTimelineActions.ts index 1200cc82f..b3a3ecff5 100644 --- a/src/app/hooks/timeline/useTimelineActions.ts +++ b/src/app/hooks/timeline/useTimelineActions.ts @@ -11,6 +11,38 @@ import { extractReplyDraftBody, getMemberDisplayName, resolveReplyDraftTarget } import { createMentionElement, moveCursor } from '$components/editor'; import * as prefix from '$unstable/prefixes'; +/** + * The profile popup reads name, avatar and the identity fields off the room + * member, so the cached copies would shadow fresher state event data. + */ +export const buildCachedProfilePayload = (cachedData: UserProfile | undefined) => { + const cleanExtended = cachedData?.extended ? { ...cachedData.extended } : undefined; + + if (cleanExtended) { + delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_PRONOUNS_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_PROFILE_BIOGRAPHY_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_BIO_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_STATUS_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_TIMEZONE_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_STABLE_PROFILE_TIMEZONE_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_BANNER_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_DARK_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME]; + delete cleanExtended.avatar_url; + delete cleanExtended.displayname; + delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_HAS_CAT_PROPERTY_NAME]; + delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_IS_CAT_PROPERTY_NAME]; + } + + return { + pronouns: cachedData?.pronouns, + bio: cachedData?.bio, + timezone: cachedData?.timezone, + extended: cleanExtended, + }; +}; + export interface UseTimelineActionsOptions { room: Room; mx: MatrixClient; @@ -65,38 +97,13 @@ export function useTimelineActions({ const userId = evt.currentTarget.getAttribute('data-user-id'); if (!userId) return; - const cachedData = getGlobalProfile(userId); - const cleanExtended = cachedData?.extended ? { ...cachedData.extended } : undefined; - - if (cleanExtended) { - delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_PRONOUNS_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_PROFILE_BIOGRAPHY_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_BIO_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_COMMET_UNSTABLE_PROFILE_STATUS_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_TIMEZONE_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_STABLE_PROFILE_TIMEZONE_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_UNSTABLE_PROFILE_BANNER_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_DARK_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_NAME_COLOR_LIGHT_PROPERTY_NAME]; - delete cleanExtended.avatar_url; - delete cleanExtended.displayname; - delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_HAS_CAT_PROPERTY_NAME]; - delete cleanExtended[prefix.MATRIX_SABLE_UNSTABLE_ANIMAL_IDENTITY_IS_CAT_PROPERTY_NAME]; - } - openUserRoomProfile( room.roomId, spaceId, userId, evt.currentTarget.getBoundingClientRect(), undefined, - { - pronouns: cachedData?.pronouns, - bio: cachedData?.bio, - timezone: cachedData?.timezone, - extended: cleanExtended, - } + buildCachedProfilePayload(getGlobalProfile(userId)) ); }, [room.roomId, spaceId, openUserRoomProfile, getGlobalProfile]