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

Commit 59b9d1e

Browse files
authored
Don't consider threads for breaking continuation until actually created (#8581)
* Don't consider threads for breaking continuation until they've actually been created * Update tests * Make hasThreadSummary null thread safe * Apply feedback from pr review
1 parent fbbb9c2 commit 59b9d1e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/components/structures/MessagePanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { getEventDisplayInfo } from "../../utils/EventRenderingUtils";
5656
import { IReadReceiptInfo } from "../views/rooms/ReadReceiptMarker";
5757
import { haveRendererForEvent } from "../../events/EventTileFactory";
5858
import { editorRoomKey } from "../../Editing";
59+
import { hasThreadSummary } from "../../utils/EventUtils";
5960

6061
const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes
6162
const continuedTypes = [EventType.Sticker, EventType.RoomMessage];
@@ -96,7 +97,7 @@ export function shouldFormContinuation(
9697

9798
// Thread summaries in the main timeline should break up a continuation on both sides
9899
if (threadsEnabled &&
99-
(mxEvent.isThreadRoot || prevEvent.isThreadRoot) &&
100+
(hasThreadSummary(mxEvent) || hasThreadSummary(prevEvent)) &&
100101
timelineRenderingType !== TimelineRenderingType.Thread
101102
) {
102103
return false;

src/utils/EventUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,7 @@ export function canForward(event: MatrixEvent): boolean {
280280
M_POLL_START.matches(event.getType())
281281
);
282282
}
283+
284+
export function hasThreadSummary(event: MatrixEvent): boolean {
285+
return event.isThreadRoot && event.getThread()?.length && !!event.getThread().replyToEvent;
286+
}

test/components/structures/MessagePanel-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ describe('MessagePanel', function() {
699699
});
700700

701701
describe("shouldFormContinuation", () => {
702-
it("does not form continuations from thread roots", () => {
702+
it("does not form continuations from thread roots which have summaries", () => {
703703
const message1 = TestUtilsMatrix.mkMessage({
704704
event: true,
705705
room: "!room:id",
@@ -730,6 +730,14 @@ describe("shouldFormContinuation", () => {
730730
});
731731

732732
expect(shouldFormContinuation(message1, message2, false, true)).toEqual(true);
733+
expect(shouldFormContinuation(message2, threadRoot, false, true)).toEqual(true);
734+
expect(shouldFormContinuation(threadRoot, message3, false, true)).toEqual(true);
735+
736+
const thread = {
737+
length: 1,
738+
replyToEvent: {},
739+
};
740+
jest.spyOn(threadRoot, "getThread").mockReturnValue(thread);
733741
expect(shouldFormContinuation(message2, threadRoot, false, true)).toEqual(false);
734742
expect(shouldFormContinuation(threadRoot, message3, false, true)).toEqual(false);
735743
});

0 commit comments

Comments
 (0)