Skip to content

Commit

Permalink
Don't decrement the length count of a thread when root redacted (#2314)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Apr 21, 2022
1 parent c0cb662 commit e133005
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,42 @@ describe("Room", function() {
expect(thread.replyToEvent.getId()).toBe(threadResponse2.getId());
});

it("should not decrement the length when the thread root is redacted", async () => {
room.client.supportsExperimentalThreads = () => true;

const threadRoot = mkMessage();
const threadResponse1 = mkThreadResponse(threadRoot);
threadResponse1.localTimestamp += 1000;
const threadResponse2 = mkThreadResponse(threadRoot);
threadResponse2.localTimestamp += 2000;
const threadResponse2Reaction = mkReaction(threadResponse2);

room.client.fetchRoomEvent = (eventId: string) => Promise.resolve({
...threadRoot.event,
unsigned: {
"age": 123,
"m.relations": {
"m.thread": {
latest_event: threadResponse2.event,
count: 2,
current_user_participated: true,
},
},
},
});

room.addLiveEvents([threadRoot, threadResponse1, threadResponse2, threadResponse2Reaction]);
const thread = await emitPromise(room, ThreadEvent.New);

expect(thread).toHaveLength(2);
expect(thread.replyToEvent.getId()).toBe(threadResponse2.getId());

const threadRootRedaction = mkRedaction(threadRoot);
room.addLiveEvents([threadRootRedaction]);
await emitPromise(thread, ThreadEvent.Update);
expect(thread).toHaveLength(2);
});

it("Redacting the lastEvent finds a new lastEvent", async () => {
room.client.supportsExperimentalThreads = () => true;

Expand Down
1 change: 1 addition & 0 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
private onBeforeRedaction = (event: MatrixEvent, redaction: MatrixEvent) => {
if (event?.isRelation(THREAD_RELATION_TYPE.name) &&
this.room.eventShouldLiveIn(event).threadId === this.id &&
event.getId() !== this.id && // the root event isn't counted in the length so ignore this redaction
!redaction.status // only respect it when it succeeds
) {
this.replyCount--;
Expand Down

0 comments on commit e133005

Please sign in to comment.