Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional variable to reply into a thread #295

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} resolves to the event ID which was sent
*/
@timedMatrixClientFunctionCall()
public replyText(roomId: string, event: any, text: string, html: string = null): Promise<string> {
public replyText(roomId: string, event: any, text: string, thread = false, html: string = null): Promise<string> {
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);
}

Expand All @@ -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<string>} resolves to the event ID which was sent
*/
@timedMatrixClientFunctionCall()
public replyHtmlText(roomId: string, event: any, html: string): Promise<string> {
public replyHtmlText(roomId: string, event: any, html: string, thread = false): Promise<string> {
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);
}

Expand All @@ -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<string>} resolves to the event ID which was sent
*/
@timedMatrixClientFunctionCall()
public replyNotice(roomId: string, event: any, text: string, html: string = null): Promise<string> {
public replyNotice(roomId: string, event: any, text: string, thread = false, html: string = null): Promise<string> {
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);
}

Expand All @@ -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<string>} resolves to the event ID which was sent
*/
@timedMatrixClientFunctionCall()
public replyHtmlNotice(roomId: string, event: any, html: string): Promise<string> {
public replyHtmlNotice(roomId: string, event: any, html: string, thread = false): Promise<string> {
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);
}

Expand Down