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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<string, unknown> | undefined;
|
||||
const source = newContent ?? content;
|
||||
|
||||
function renderContent(source: Record<string, unknown>): 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 <Linkify options={LINKIFY_OPTS}>{text}</Linkify>;
|
||||
}
|
||||
|
||||
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<string, unknown> }).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<string, unknown> | 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user