Fix issues with edited events not affecting threads (#8125)

This commit is contained in:
Michael Telatynski 2022-03-24 12:24:18 +00:00 committed by GitHub
parent 3b523677fd
commit f86cc74afc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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());