Skip to content

Commit

Permalink
src/bridge/MatrixHandler.ts: handle replying to self
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Ferass El Hafidi authored and funderscore1 committed Jul 28, 2024
1 parent 71af6a3 commit f6999da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ properties:
type: "string"
shortReplyTresholdSeconds:
type: "integer"
selfReplyTemplate:
type: "string"
ignoreFunctionalMembersInAdminRooms:
type: "boolean"
ircHandler:
Expand Down
16 changes: 14 additions & 2 deletions src/bridge/MatrixHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
};
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit f6999da

Please sign in to comment.