Skip to content

Commit 834bfa1

Browse files
author
Ferass El Hafidi
committed
src/bridge/MatrixHandler.ts: handle replying to self
When someone sent a message: <f_[mtrx]> Hello? And then replied to their own message: <f_[mtrx]> > <@Funderscore:nova.astraltech.org> Hello? Hi? What would be sent on IRC would either be this: <f_[mtrx]> Hello? <f_[mtrx]> f_[mtrx]: Hi? Or: <f_[mtrx]> Hello? -- a while later -- <f_[mtrx]> 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: <f_[mtrx]> <f_[mtrx]> Hello? -- a while later -- <f_[mtrx]> Hi? Or: <f_[mtrx]> Hi? Which is a bit more natural. Signed-off-by: Ferass El Hafidi <[email protected]>
1 parent 917f2c9 commit 834bfa1

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

config.sample.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ ircService:
602602
shortReplyTemplate: "$NICK: $REPLY"
603603
# format of replies sent a while after the original message
604604
longReplyTemplate: "$NICK: \"$ORIGINAL\" <- $REPLY"
605+
# format of replies where the sender of the original message is the same as the sender of the reply
606+
selfReplyTemplate: "<$NICK> $ORIGINAL\n$REPLY"
605607
# how much time needs to pass between the reply and the original message to switch to the long format
606608
shortReplyTresholdSeconds: 300
607609
# Ignore users mentioned in a io.element.functional_members state event when checking admin room membership

config.schema.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ properties:
171171
type: "string"
172172
shortReplyTresholdSeconds:
173173
type: "integer"
174+
selfReplyTemplate:
175+
type: "string"
174176
ignoreFunctionalMembersInAdminRooms:
175177
type: "boolean"
176178
ircHandler:

src/bridge/MatrixHandler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface MatrixHandlerConfig {
5555
shortReplyTemplate: string;
5656
// Format of replies sent a while after the original message
5757
longReplyTemplate: string;
58+
// format of replies where the sender of the original message is the same as the sender of the reply
59+
selfReplyTemplate: string;
5860
// Format of the text explaining why a message is truncated and pastebinned
5961
truncatedMessageTemplate: string;
6062
// Ignore io.element.functional_members members joining admin rooms.
@@ -68,6 +70,7 @@ export const DEFAULTS: MatrixHandlerConfig = {
6870
shortReplyTresholdSeconds: 5 * 60,
6971
shortReplyTemplate: "$NICK: $REPLY",
7072
longReplyTemplate: "$NICK: \"$ORIGINAL\" <- $REPLY",
73+
selfReplyTemplate: "<$NICK> $ORIGINAL\n$REPLY",
7174
truncatedMessageTemplate: "(full message at <$URL>)",
7275
ignoreFunctionalMembersInAdminRooms: false,
7376
};
@@ -1469,10 +1472,19 @@ export class MatrixHandler {
14691472
let replyTemplate: string;
14701473
const thresholdMs = (this.config.shortReplyTresholdSeconds) * 1000;
14711474
if (rplSource && event.origin_server_ts - cachedEvent.timestamp > thresholdMs) {
1472-
replyTemplate = this.config.longReplyTemplate;
1475+
if (cachedEvent.sender === event.sender) {
1476+
// They're replying to their own message.
1477+
replyTemplate = this.config.selfReplyTemplate;
1478+
}
1479+
else {
1480+
replyTemplate = this.config.longReplyTemplate;
1481+
}
14731482
}
14741483
else {
1475-
replyTemplate = this.config.shortReplyTemplate;
1484+
if (cachedEvent.sender !== event.sender) {
1485+
// Someone[m] pinging themself is weird
1486+
replyTemplate = this.config.shortReplyTemplate;
1487+
}
14761488
}
14771489

14781490
const formattedReply = renderTemplate(replyTemplate, {

0 commit comments

Comments
 (0)