Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 36f2824

Browse files
authored
Update thread summary when latest event gets decrypted (#8564)
1 parent f9c85ac commit 36f2824

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/components/views/rooms/ThreadSummary.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { useContext } from "react";
17+
import React, { useContext, useState } from "react";
1818
import { Thread, ThreadEvent } from "matrix-js-sdk/src/models/thread";
19-
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
19+
import { IContent, MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
2020

2121
import { _t } from "../../../languageHandler";
2222
import { CardContext } from "../right_panel/context";
2323
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
2424
import { showThread } from "../../../dispatcher/dispatch-actions/threads";
2525
import PosthogTrackers from "../../../PosthogTrackers";
26-
import { useTypedEventEmitterState } from "../../../hooks/useEventEmitter";
26+
import { useTypedEventEmitter, useTypedEventEmitterState } from "../../../hooks/useEventEmitter";
2727
import RoomContext from "../../../contexts/RoomContext";
2828
import { MessagePreviewStore } from "../../../stores/room-list/MessagePreviewStore";
2929
import MemberAvatar from "../avatars/MemberAvatar";
@@ -76,18 +76,21 @@ export const ThreadMessagePreview = ({ thread, showDisplayname = false }: IPrevi
7676
const cli = useContext(MatrixClientContext);
7777

7878
const lastReply = useTypedEventEmitterState(thread, ThreadEvent.Update, () => thread.replyToEvent);
79-
// track the replacing event id as a means to regenerate the thread message preview
80-
const replacingEventId = useTypedEventEmitterState(
81-
lastReply,
82-
MatrixEventEvent.Replaced,
83-
() => lastReply?.replacingEventId(),
84-
);
79+
// track the content as a means to regenerate the thread message preview upon edits & decryption
80+
const [content, setContent] = useState<IContent>(lastReply?.getContent());
81+
useTypedEventEmitter(lastReply, MatrixEventEvent.Replaced, () => {
82+
setContent(lastReply.getContent());
83+
});
84+
const awaitDecryption = lastReply?.shouldAttemptDecryption() || lastReply?.isBeingDecrypted();
85+
useTypedEventEmitter(awaitDecryption ? lastReply : null, MatrixEventEvent.Decrypted, () => {
86+
setContent(lastReply.getContent());
87+
});
8588

8689
const preview = useAsyncMemo(async () => {
8790
if (!lastReply) return;
8891
await cli.decryptEventIfNeeded(lastReply);
8992
return MessagePreviewStore.instance.generatePreviewForEvent(lastReply);
90-
}, [lastReply, replacingEventId]);
93+
}, [lastReply, content]);
9194
if (!preview) return null;
9295

9396
return <>

0 commit comments

Comments
 (0)