From f6999da731ebb9870a5bbc9fef932cb1ecb22208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferass=20El=C2=A0Hafidi?= Date: Mon, 17 Jun 2024 21:33:14 +0200 Subject: [PATCH] src/bridge/MatrixHandler.ts: handle replying to self MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When someone sent a message: Hello? And then replied to their own message: > <@funderscore:nova.astraltech.org> Hello? Hi? What would be sent on IRC would either be this: Hello? f_[mtrx]: Hi? Or: Hello? -- a while later -- f_[mtrx]: "Hello?" <- Hi? Both of which are confusing because usually nobody pings themself on IRC. This commit treats replies to self differently, and introduces a new `selfReplyTemplate` config option, so that the reply gets bridged as: Hello? -- a while later -- Hi? Or: Hi? Which is a bit more natural. Signed-off-by: Ferass El Hafidi --- config.sample.yaml | 2 ++ config.schema.yml | 2 ++ src/bridge/MatrixHandler.ts | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/config.sample.yaml b/config.sample.yaml index 14c23fdd3..d95bfbca4 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -602,6 +602,8 @@ ircService: shortReplyTemplate: "$NICK: $REPLY" # format of replies sent a while after the original message longReplyTemplate: "$NICK: \"$ORIGINAL\" <- $REPLY" + # format of replies where the sender of the original message is the same as the sender of the reply + selfReplyTemplate: "<$NICK> $ORIGINAL\n$REPLY" # how much time needs to pass between the reply and the original message to switch to the long format shortReplyTresholdSeconds: 300 # Ignore users mentioned in a io.element.functional_members state event when checking admin room membership diff --git a/config.schema.yml b/config.schema.yml index 17d78fe2a..6bedeaf03 100644 --- a/config.schema.yml +++ b/config.schema.yml @@ -171,6 +171,8 @@ properties: type: "string" shortReplyTresholdSeconds: type: "integer" + selfReplyTemplate: + type: "string" ignoreFunctionalMembersInAdminRooms: type: "boolean" ircHandler: diff --git a/src/bridge/MatrixHandler.ts b/src/bridge/MatrixHandler.ts index 22b8e2969..b68e34cea 100644 --- a/src/bridge/MatrixHandler.ts +++ b/src/bridge/MatrixHandler.ts @@ -55,6 +55,8 @@ export interface MatrixHandlerConfig { shortReplyTemplate: string; // Format of replies sent a while after the original message longReplyTemplate: string; + // format of replies where the sender of the original message is the same as the sender of the reply + selfReplyTemplate: string; // Format of the text explaining why a message is truncated and pastebinned truncatedMessageTemplate: string; // Ignore io.element.functional_members members joining admin rooms. @@ -68,6 +70,7 @@ export const DEFAULTS: MatrixHandlerConfig = { shortReplyTresholdSeconds: 5 * 60, shortReplyTemplate: "$NICK: $REPLY", longReplyTemplate: "$NICK: \"$ORIGINAL\" <- $REPLY", + selfReplyTemplate: "<$NICK> $ORIGINAL\n$REPLY", truncatedMessageTemplate: "(full message at <$URL>)", ignoreFunctionalMembersInAdminRooms: false, }; @@ -1469,10 +1472,19 @@ export class MatrixHandler { let replyTemplate: string; const thresholdMs = (this.config.shortReplyTresholdSeconds) * 1000; if (rplSource && event.origin_server_ts - cachedEvent.timestamp > thresholdMs) { - replyTemplate = this.config.longReplyTemplate; + if (cachedEvent.sender === event.sender) { + // They're replying to their own message. + replyTemplate = this.config.selfReplyTemplate; + } + else { + replyTemplate = this.config.longReplyTemplate; + } } else { - replyTemplate = this.config.shortReplyTemplate; + if (cachedEvent.sender !== event.sender) { + // Someone[m] pinging themself is weird + replyTemplate = this.config.shortReplyTemplate; + } } const formattedReply = renderTemplate(replyTemplate, {