@@ -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