Skip to content

Commit 35f3816

Browse files
authored
Handle thread fallbacks correctly (#1697)
* Handle thread fallbacks correctly We were incorrectly handling these as regular messages because they didn't look like our idea of what a reply looks like on Matrix. * Changelog --------- Co-authored-by: Tadeusz Sośnierz <[email protected]>
1 parent 6a60eff commit 35f3816

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

changelog.d/1697.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix not handling thread fallbacks as replies.

src/bridge/MatrixHandler.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ export class MatrixHandler {
10331033

10341034
let cacheBody = ircAction.text;
10351035

1036-
// special handling for replies
1036+
// special handling for replies (and threads)
10371037
if (event.content["m.relates_to"] && event.content["m.relates_to"]["m.in_reply_to"]) {
10381038
const eventId = event.content["m.relates_to"]["m.in_reply_to"].event_id;
10391039
const reply = await this.textForReplyEvent(event, eventId, ircRoom);
@@ -1255,20 +1255,25 @@ export class MatrixHandler {
12551255

12561256
private async textForReplyEvent(event: MatrixMessageEvent, replyEventId: string, ircRoom: IrcRoom):
12571257
Promise<{formatted: string; reply: string}|null> {
1258-
const REPLY_REGEX = /> <(.*?)>(.*?)\n\n([\s\S]*)/;
1258+
// strips out the quotation of the original message, if needed
1259+
const replyText = (body: string): string => {
1260+
const REPLY_REGEX = /> <(.*?)>(.*?)\n\n([\s\S]*)/;
1261+
const match = REPLY_REGEX.exec(body);
1262+
if (match === null || match.length !== 4) {
1263+
return body;
1264+
}
1265+
return match[3];
1266+
};
1267+
12591268
const REPLY_NAME_MAX_LENGTH = 12;
12601269
const eventId = replyEventId;
12611270
if (!event.content.body) {
12621271
return null;
12631272
}
1264-
const match = REPLY_REGEX.exec(event.content.body);
1265-
if (match === null || match.length !== 4) {
1266-
return null;
1267-
}
12681273

1274+
const rplText = replyText(event.content.body);
12691275
let rplName: string;
12701276
let rplSource: string;
1271-
const rplText = match[3];
12721277
let cachedEvent = this.getCachedEvent(eventId);
12731278
if (!cachedEvent) {
12741279
// Fallback to fetching from the homeserver.
@@ -1283,8 +1288,7 @@ export class MatrixHandler {
12831288
const isReply = eventContent.content["m.relates_to"] &&
12841289
eventContent.content["m.relates_to"]["m.in_reply_to"];
12851290
if (isReply) {
1286-
const sourceMatch = REPLY_REGEX.exec(eventContent.content.body);
1287-
rplSource = sourceMatch && sourceMatch.length === 4 ? sourceMatch[3] : event.content.body;
1291+
rplSource = replyText(eventContent.content.body);
12881292
}
12891293
else {
12901294
rplSource = eventContent.content.body;

0 commit comments

Comments
 (0)