Skip to content

Commit e133005

Browse files
authored
Don't decrement the length count of a thread when root redacted (matrix-org#2314)
1 parent c0cb662 commit e133005

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

spec/unit/room.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,42 @@ describe("Room", function() {
20462046
expect(thread.replyToEvent.getId()).toBe(threadResponse2.getId());
20472047
});
20482048

2049+
it("should not decrement the length when the thread root is redacted", async () => {
2050+
room.client.supportsExperimentalThreads = () => true;
2051+
2052+
const threadRoot = mkMessage();
2053+
const threadResponse1 = mkThreadResponse(threadRoot);
2054+
threadResponse1.localTimestamp += 1000;
2055+
const threadResponse2 = mkThreadResponse(threadRoot);
2056+
threadResponse2.localTimestamp += 2000;
2057+
const threadResponse2Reaction = mkReaction(threadResponse2);
2058+
2059+
room.client.fetchRoomEvent = (eventId: string) => Promise.resolve({
2060+
...threadRoot.event,
2061+
unsigned: {
2062+
"age": 123,
2063+
"m.relations": {
2064+
"m.thread": {
2065+
latest_event: threadResponse2.event,
2066+
count: 2,
2067+
current_user_participated: true,
2068+
},
2069+
},
2070+
},
2071+
});
2072+
2073+
room.addLiveEvents([threadRoot, threadResponse1, threadResponse2, threadResponse2Reaction]);
2074+
const thread = await emitPromise(room, ThreadEvent.New);
2075+
2076+
expect(thread).toHaveLength(2);
2077+
expect(thread.replyToEvent.getId()).toBe(threadResponse2.getId());
2078+
2079+
const threadRootRedaction = mkRedaction(threadRoot);
2080+
room.addLiveEvents([threadRootRedaction]);
2081+
await emitPromise(thread, ThreadEvent.Update);
2082+
expect(thread).toHaveLength(2);
2083+
});
2084+
20492085
it("Redacting the lastEvent finds a new lastEvent", async () => {
20502086
room.client.supportsExperimentalThreads = () => true;
20512087

src/models/thread.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
119119
private onBeforeRedaction = (event: MatrixEvent, redaction: MatrixEvent) => {
120120
if (event?.isRelation(THREAD_RELATION_TYPE.name) &&
121121
this.room.eventShouldLiveIn(event).threadId === this.id &&
122+
event.getId() !== this.id && // the root event isn't counted in the length so ignore this redaction
122123
!redaction.status // only respect it when it succeeds
123124
) {
124125
this.replyCount--;

0 commit comments

Comments
 (0)