From a6b5e03fe5cca82e7542d806702a192839e6706f Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Tue, 2 Jun 2026 10:51:21 -0400 Subject: [PATCH] fix: edit history original shows pre-edit content mEvent.getContent() returns post-edit content because matrix-js-sdk applies the latest replace event in-memory. Reading mEvent.event.content gives the raw server content (the true original before any edits). Edit entries from the relations API correctly use m.new_content per Matrix spec. Co-Authored-By: Claude Sonnet 4.6 --- .../room/message/EditHistoryModal.tsx | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/app/features/room/message/EditHistoryModal.tsx b/src/app/features/room/message/EditHistoryModal.tsx index e5ccb5f94..53daeb892 100644 --- a/src/app/features/room/message/EditHistoryModal.tsx +++ b/src/app/features/room/message/EditHistoryModal.tsx @@ -56,11 +56,7 @@ function isRawEditEvent(raw: unknown): raw is RawEditEvent { return typeof r.event_id === 'string' && typeof r.origin_server_ts === 'number'; } -function getVersionContent(evt: MatrixEvent): ReactNode { - const content = evt.getContent(); - const newContent = content['m.new_content'] as Record | undefined; - const source = newContent ?? content; - +function renderContent(source: Record): ReactNode { const format = source.format; const formattedBody = source.formatted_body; if ( @@ -70,12 +66,25 @@ function getVersionContent(evt: MatrixEvent): ReactNode { ) { return parse(sanitizeCustomHtml(formattedBody)); } - const body = source.body; const text = typeof body === 'string' ? body : '(no text)'; return {text}; } +function getOriginalContent(evt: MatrixEvent): ReactNode { + // mEvent.getContent() returns the SDK-applied post-edit content. + // Read the raw server event to get the actual original pre-edit text. + const raw = (evt.event as { content?: Record }).content ?? {}; + return renderContent(raw); +} + +function getVersionContent(evt: MatrixEvent): ReactNode { + // Edit events carry the new text in m.new_content per Matrix spec. + const content = evt.getContent(); + const newContent = content['m.new_content'] as Record | undefined; + return renderContent(newContent ?? content); +} + export function EditHistoryModal({ room, mEvent, onClose }: EditHistoryModalProps) { const mx = useMatrixClient(); const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock'); @@ -126,7 +135,7 @@ export function EditHistoryModal({ room, mEvent, onClose }: EditHistoryModalProp return `${date} at ${time}`; }; - const originalContent = getVersionContent(mEvent); + const originalContent = getOriginalContent(mEvent); const originalTs = mEvent.getTs();