Skip to content

Commit 8212287

Browse files
author
Germain
authored
Add thread relation in sendEvent if it's missing (#2149)
1 parent 9c242a9 commit 8212287

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/client.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,6 +3593,22 @@ export class MatrixClient extends EventEmitter {
35933593
eventType = threadId;
35943594
threadId = null;
35953595
}
3596+
3597+
if (threadId && content["m.relates_to"]?.rel_type !== RelationType.Thread) {
3598+
content["m.relates_to"] = {
3599+
...content["m.relates_to"],
3600+
"rel_type": RelationType.Thread,
3601+
"event_id": threadId,
3602+
};
3603+
3604+
const thread = this.getRoom(roomId)?.threads.get(threadId);
3605+
if (thread) {
3606+
content["m.relates_to"]["m.in_reply_to"] = {
3607+
"event_id": thread.replyToEvent.getId(),
3608+
};
3609+
}
3610+
}
3611+
35963612
return this.sendCompleteEvent(roomId, threadId, { type: eventType, content }, txnId as string, callback);
35973613
}
35983614

@@ -4213,17 +4229,6 @@ export class MatrixClient extends EventEmitter {
42134229
body: text,
42144230
};
42154231

4216-
const thread = this.getRoom(roomId)?.threads.get(threadId);
4217-
if (thread) {
4218-
content["m.relates_to"] = {
4219-
"rel_type": RelationType.Thread,
4220-
"event_id": threadId,
4221-
"m.in_reply_to": {
4222-
"event_id": thread.replyToEvent.getId(),
4223-
},
4224-
};
4225-
}
4226-
42274232
return this.sendEvent(roomId, threadId, EventType.Sticker, content, undefined, callback);
42284233
}
42294234

0 commit comments

Comments
 (0)