Skip to content

Commit 156fcff

Browse files
committed
Iterate
1 parent 660627f commit 156fcff

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/models/event.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,8 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
579579
const relatesTo = this.getWireContent()?.["m.relates_to"];
580580
if (relatesTo?.rel_type === THREAD_RELATION_TYPE.name) {
581581
return relatesTo.event_id;
582-
}
583-
if (this.thread) {
584-
return this.thread.id;
585-
}
586-
if (this.threadId) {
587-
return this.threadId;
588-
}
589-
const unsigned = this.getUnsigned();
590-
if (typeof unsigned[UNSIGNED_THREAD_ID_FIELD.name] === "string") {
591-
return unsigned[UNSIGNED_THREAD_ID_FIELD.name];
582+
} else {
583+
return this.getThread()?.id || this.threadId;
592584
}
593585
}
594586

src/models/room.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
UNSTABLE_ELEMENT_FUNCTIONAL_USERS,
4040
EVENT_VISIBILITY_CHANGE_TYPE,
4141
RelationType,
42+
UNSIGNED_THREAD_ID_FIELD,
4243
} from "../@types/event";
4344
import { IRoomVersionsCapability, MatrixClient, PendingEventOrdering, RoomVersionStability } from "../client";
4445
import { GuestAccess, HistoryVisibility, JoinRule, ResizeMethod } from "../@types/partials";
@@ -2113,12 +2114,11 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
21132114
}
21142115

21152116
// A thread relation is always only shown in a thread
2116-
const threadRootId = event.threadRootId;
2117-
if (threadRootId != undefined) {
2117+
if (event.isRelation(THREAD_RELATION_TYPE.name)) {
21182118
return {
21192119
shouldLiveInRoom: false,
21202120
shouldLiveInThread: true,
2121-
threadId: threadRootId,
2121+
threadId: event.threadRootId,
21222122
};
21232123
}
21242124

@@ -2149,6 +2149,15 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
21492149
};
21502150
}
21512151

2152+
const unsigned = event.getUnsigned();
2153+
if (typeof unsigned[UNSIGNED_THREAD_ID_FIELD.name] === "string") {
2154+
return {
2155+
shouldLiveInRoom: false,
2156+
shouldLiveInThread: true,
2157+
threadId: unsigned[UNSIGNED_THREAD_ID_FIELD.name],
2158+
};
2159+
}
2160+
21522161
// We've exhausted all scenarios,
21532162
// we cannot assume that it lives in the main timeline as this may be a relation for an unknown thread
21542163
// adding the event in the wrong timeline causes stuck notifications and can break ability to send read receipts
@@ -2804,7 +2813,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
28042813
if (parentEvent.threadRootId) {
28052814
threadRoots.add(parentEvent.threadRootId);
28062815
const unsigned = event.getUnsigned();
2807-
unsigned["org.matrix.msc4023.thread_id"] = parentEvent.threadRootId;
2816+
unsigned[UNSIGNED_THREAD_ID_FIELD.name] = parentEvent.threadRootId;
28082817
event.setUnsigned(unsigned);
28092818
}
28102819

@@ -2881,9 +2890,12 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
28812890
private findThreadRoots(events: MatrixEvent[]): Set<string> {
28822891
const threadRoots = new Set<string>();
28832892
for (const event of events) {
2884-
const threadRootId = event.threadRootId;
2885-
if (threadRootId != undefined) {
2886-
threadRoots.add(threadRootId);
2893+
if (event.isRelation(THREAD_RELATION_TYPE.name)) {
2894+
threadRoots.add(event.relationEventId ?? "");
2895+
}
2896+
const unsigned = event.getUnsigned();
2897+
if (typeof unsigned[UNSIGNED_THREAD_ID_FIELD.name] === "string") {
2898+
threadRoots.add(unsigned[UNSIGNED_THREAD_ID_FIELD.name]!);
28872899
}
28882900
}
28892901
return threadRoots;

0 commit comments

Comments
 (0)