From f86cc74afc198e32f89032eef8668de6744846f0 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 24 Mar 2022 12:24:18 +0000 Subject: [PATCH] Fix issues with edited events not affecting threads (#8125) --- src/components/views/rooms/ThreadSummary.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/ThreadSummary.tsx b/src/components/views/rooms/ThreadSummary.tsx index 47a38ff17e..9adec2e1ac 100644 --- a/src/components/views/rooms/ThreadSummary.tsx +++ b/src/components/views/rooms/ThreadSummary.tsx @@ -16,7 +16,7 @@ limitations under the License. import React, { useContext } from "react"; import { Thread, ThreadEvent } from "matrix-js-sdk/src/models/thread"; -import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event"; import { _t } from "../../../languageHandler"; import { CardContext } from "../right_panel/BaseCard"; @@ -74,12 +74,20 @@ interface IPreviewProps { export const ThreadMessagePreview = ({ thread, showDisplayname = false }: IPreviewProps) => { const cli = useContext(MatrixClientContext); + const lastReply = useTypedEventEmitterState(thread, ThreadEvent.Update, () => thread.replyToEvent); + // track the replacing event id as a means to regenerate the thread message preview + const replacingEventId = useTypedEventEmitterState( + lastReply, + MatrixEventEvent.Replaced, + () => lastReply?.replacingEventId(), + ); + const preview = useAsyncMemo(async () => { if (!lastReply) return; await cli.decryptEventIfNeeded(lastReply); return MessagePreviewStore.instance.generatePreviewForEvent(lastReply); - }, [lastReply]); + }, [lastReply, replacingEventId]); if (!preview) return null; const sender = thread.roomState.getSentinelMember(lastReply.getSender());