Skip to content

Commit 55566a7

Browse files
committed
Switch to using UnstableValue
1 parent a920630 commit 55566a7

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

src/@types/event.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ export const LOCAL_NOTIFICATION_SETTINGS_PREFIX = new UnstableValue(
235235
"org.matrix.msc3890.local_notification_settings",
236236
);
237237

238+
/**
239+
* https://github.com/matrix-org/matrix-doc/pull/4023
240+
*
241+
* @experimental
242+
*/
243+
export const UNSIGNED_THREAD_ID_FIELD = new UnstableValue("thread_id", "org.matrix.msc4023.thread_id");
244+
238245
export interface IEncryptedFile {
239246
url: string;
240247
mimetype?: string;

src/models/event.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ import { ExtensibleEvent, ExtensibleEvents, Optional } from "matrix-events-sdk";
2424
import type { IEventDecryptionResult } from "../@types/crypto";
2525
import { logger } from "../logger";
2626
import { VerificationRequest } from "../crypto/verification/request/VerificationRequest";
27-
import { EVENT_VISIBILITY_CHANGE_TYPE, EventType, MsgType, RelationType } from "../@types/event";
27+
import {
28+
EVENT_VISIBILITY_CHANGE_TYPE,
29+
EventType,
30+
MsgType,
31+
RelationType,
32+
UNSIGNED_THREAD_ID_FIELD,
33+
} from "../@types/event";
2834
import { Crypto } from "../crypto";
2935
import { deepSortedObjectEntries, internaliseString } from "../utils";
3036
import { RoomMember } from "./room-member";
@@ -63,7 +69,7 @@ export interface IUnsigned {
6369
"transaction_id"?: string;
6470
"invite_room_state"?: StrippedState[];
6571
"m.relations"?: Record<RelationType | string, any>; // No common pattern for aggregated relations
66-
"org.matrix.msc4023.thread_id"?: string;
72+
[UNSIGNED_THREAD_ID_FIELD.name]?: string;
6773
}
6874

6975
export interface IThreadBundledRelationship {
@@ -573,8 +579,16 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
573579
const relatesTo = this.getWireContent()?.["m.relates_to"];
574580
if (relatesTo?.rel_type === THREAD_RELATION_TYPE.name) {
575581
return relatesTo.event_id;
576-
} else {
577-
return this.getThread()?.id || this.threadId;
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];
578592
}
579593
}
580594

src/models/room.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,11 +2113,12 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
21132113
}
21142114

21152115
// A thread relation is always only shown in a thread
2116-
if (event.isRelation(THREAD_RELATION_TYPE.name)) {
2116+
const threadRootId = event.threadRootId;
2117+
if (threadRootId != undefined) {
21172118
return {
21182119
shouldLiveInRoom: false,
21192120
shouldLiveInThread: true,
2120-
threadId: event.threadRootId,
2121+
threadId: threadRootId,
21212122
};
21222123
}
21232124

@@ -2148,15 +2149,6 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
21482149
};
21492150
}
21502151

2151-
const unsigned = event.getUnsigned();
2152-
if (typeof unsigned["org.matrix.msc4023.thread_id"] === "string") {
2153-
return {
2154-
shouldLiveInRoom: false,
2155-
shouldLiveInThread: true,
2156-
threadId: unsigned["org.matrix.msc4023.thread_id"],
2157-
};
2158-
}
2159-
21602152
// We've exhausted all scenarios,
21612153
// we cannot assume that it lives in the main timeline as this may be a relation for an unknown thread
21622154
return {
@@ -2888,12 +2880,9 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
28882880
private findThreadRoots(events: MatrixEvent[]): Set<string> {
28892881
const threadRoots = new Set<string>();
28902882
for (const event of events) {
2891-
if (event.isRelation(THREAD_RELATION_TYPE.name)) {
2892-
threadRoots.add(event.relationEventId ?? "");
2893-
}
2894-
const unsigned = event.getUnsigned();
2895-
if (typeof unsigned["org.matrix.msc4023.thread_id"] === "string") {
2896-
threadRoots.add(unsigned["org.matrix.msc4023.thread_id"]);
2883+
const threadRootId = event.threadRootId;
2884+
if (threadRootId != undefined) {
2885+
threadRoots.add(threadRootId);
28972886
}
28982887
}
28992888
return threadRoots;

0 commit comments

Comments
 (0)