forwarder: implement reply on IRC side

master
Peter Cai 2 years ago
parent 086792e281
commit a82d33f7a8
  1. 29
      forwarder.js
  2. 4
      index.js

@ -102,7 +102,7 @@ module.exports = class Forwarder {
}
}
onMatrixMessage(event, room, toStartOfTimeline) {
async onMatrixMessage(event, room, toStartOfTimeline) {
this.clientMatrix.sendReadReceipt(event);
if (toStartOfTimeline) {
return; // Ignore pagniation
@ -124,6 +124,28 @@ module.exports = class Forwarder {
}
}
let replyUsername = null;
if (content['m.relates_to'] && content['m.relates_to']['m.in_reply_to']) {
let replyEvId = content['m.relates_to']['m.in_reply_to']['event_id'];
try {
let tl = await this.clientMatrix.getEventTimeline(room.getUnfilteredTimelineSet(), replyEvId);
let replyEv = tl.getEvents().filter((v) => v.getId() == replyEvId);
if (replyEv.length > 0) {
replyUsername = replyEv[0].sender.name;
if (replyEv[0].getContent()['net.typeblog.i2m.irc_nick']) {
replyUsername = replyEv[0].getContent()['net.typeblog.i2m.irc_nick'];
}
}
} catch (err) {
console.log(err);
}
}
let replyTxt = "";
if (replyUsername) {
replyTxt = replyUsername + ": "
}
let msgTxt = null;
switch (event.getType()) {
case "m.sticker":
@ -138,7 +160,8 @@ module.exports = class Forwarder {
msgTxt = `${content.body} ${this.clientMatrix.mxcUrlToHttp(content.url)}`;
break;
default:
msgTxt = content.body;
// Get rid of the reply quote generated by Element client
msgTxt = content.body.replace(/> <@(.*):(.*)> (.*)\n\n/, "");
break;
}
break;
@ -154,7 +177,7 @@ module.exports = class Forwarder {
// Special format for emote
this.clientIRC.say(this.mappingM2I[room.roomId], `* ${name} ${msgTxt}`);
} else {
this.clientIRC.say(this.mappingM2I[room.roomId], `[${name}] ${msgTxt}`);
this.clientIRC.say(this.mappingM2I[room.roomId], `[${name}] ${replyTxt}${msgTxt}`);
}
}
}

@ -33,7 +33,9 @@ function connectIrc(config, callback) {
}
function connectMatrix(config, callback) {
let client = matrix.createClient(config.matrix);
let client = matrix.createClient(Object.assign(config.matrix, {
timelineSupport: true
}));
let myCallback = (state) => {
switch (state) {
case "PREPARED":

Loading…
Cancel
Save