diff --git a/src/MatrixClient.ts b/src/MatrixClient.ts index 9058fdea..b37550fe 100644 --- a/src/MatrixClient.ts +++ b/src/MatrixClient.ts @@ -1212,14 +1212,22 @@ export class MatrixClient extends EventEmitter { * @param {string} roomId the room ID to reply in * @param {any} event the event to reply to * @param {string} text the text to reply with + * @param {boolean} thread whether to reply into a thread * @param {string} html the HTML to reply with, or falsey to use the `text` * @returns {Promise} resolves to the event ID which was sent */ @timedMatrixClientFunctionCall() - public replyText(roomId: string, event: any, text: string, html: string = null): Promise { + public replyText(roomId: string, event: any, text: string, thread = false, html: string = null): Promise { if (!html) html = htmlEncode(text); const reply = RichReply.createFor(roomId, event, text, html); + if (thread) { + const threadStartEventId = event['content']['m.relates_to'] ? event['content']['m.relates_to']['event_id'] : event['event_id']; + reply['m.relates_to'] = { + 'rel_type': 'm.thread', + 'event_id': threadStartEventId, + }; + } return this.sendMessage(roomId, reply); } @@ -1229,12 +1237,20 @@ export class MatrixClient extends EventEmitter { * @param {string} roomId the room ID to reply in * @param {any} event the event to reply to * @param {string} html the HTML to reply with. + * @param {boolean} thread whether to reply into a thread * @returns {Promise} resolves to the event ID which was sent */ @timedMatrixClientFunctionCall() - public replyHtmlText(roomId: string, event: any, html: string): Promise { + public replyHtmlText(roomId: string, event: any, html: string, thread = false): Promise { const text = htmlToText(html, { wordwrap: false }); const reply = RichReply.createFor(roomId, event, text, html); + if (thread) { + const threadStartEventId = event['content']['m.relates_to'] ? event['content']['m.relates_to']['event_id'] : event['event_id']; + reply['m.relates_to'] = { + 'rel_type': 'm.thread', + 'event_id': threadStartEventId, + }; + } return this.sendMessage(roomId, reply); } @@ -1244,15 +1260,23 @@ export class MatrixClient extends EventEmitter { * @param {string} roomId the room ID to reply in * @param {any} event the event to reply to * @param {string} text the text to reply with + * @param {boolean} thread whether to reply into a thread * @param {string} html the HTML to reply with, or falsey to use the `text` * @returns {Promise} resolves to the event ID which was sent */ @timedMatrixClientFunctionCall() - public replyNotice(roomId: string, event: any, text: string, html: string = null): Promise { + public replyNotice(roomId: string, event: any, text: string, thread = false, html: string = null): Promise { if (!html) html = htmlEncode(text); const reply = RichReply.createFor(roomId, event, text, html); reply['msgtype'] = 'm.notice'; + if (thread) { + const threadStartEventId = event['content']['m.relates_to'] ? event['content']['m.relates_to']['event_id'] : event['event_id']; + reply['m.relates_to'] = { + 'rel_type': 'm.thread', + 'event_id': threadStartEventId, + }; + } return this.sendMessage(roomId, reply); } @@ -1262,13 +1286,21 @@ export class MatrixClient extends EventEmitter { * @param {string} roomId the room ID to reply in * @param {any} event the event to reply to * @param {string} html the HTML to reply with. + * @param {boolean} thread whether to reply into a thread * @returns {Promise} resolves to the event ID which was sent */ @timedMatrixClientFunctionCall() - public replyHtmlNotice(roomId: string, event: any, html: string): Promise { + public replyHtmlNotice(roomId: string, event: any, html: string, thread = false): Promise { const text = htmlToText(html, { wordwrap: false }); const reply = RichReply.createFor(roomId, event, text, html); reply['msgtype'] = 'm.notice'; + if (thread) { + const threadStartEventId = event['content']['m.relates_to'] ? event['content']['m.relates_to']['event_id'] : event['event_id']; + reply['m.relates_to'] = { + 'rel_type': 'm.thread', + 'event_id': threadStartEventId, + }; + } return this.sendMessage(roomId, reply); }