Skip to content

Commit fb0a326

Browse files
author
Ferass El Hafidi
committed
Match IRC conventions when bridging file uploads
Usually, IRC users just upload files somewhere and send a bare link, perhaps with a bit of explanation. The bridge originally did something like this for files: * f_[mtrx] uploaded an image: (20KiB) < https://matrix.org/_matrix/media/v3/download/something/some-other-thing/image.png > and something like this for code blocks: * f_[mtrx] sent a code block: https://matrix.org/_matrix/media/v3/download/something/some-other-thing That is quite unusual on IRC. This commit changes it to: <f_[mtrx]> https://matrix.org/_matrix/media/v3/download/something/some-other-thing/image.png (20KiB) <f_[mtrx]> https://matrix.org/_matrix/media/v3/download/something/some-other-thing Which is more natural. Signed-off-by: Ferass El Hafidi <[email protected]>
1 parent bd06139 commit fb0a326

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/bridge/MatrixHandler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,9 @@ export class MatrixHandler {
11751175
// we check event.content.body since ircAction already has the markers stripped
11761176
const codeBlockMatch = event.content.body.match(/^```(\w+)?/);
11771177
if (codeBlockMatch) {
1178-
const type = codeBlockMatch[1] ? ` ${codeBlockMatch[1]}` : '';
11791178
event.content = {
1180-
msgtype: "m.emote",
1181-
body: `sent a${type} code block: ${httpUrl}`
1179+
...event.content,
1180+
body: `${httpUrl}`
11821181
};
11831182
}
11841183
else {
@@ -1209,7 +1208,7 @@ export class MatrixHandler {
12091208
// Modify the event to become a truncated version of the original
12101209
// the truncation limits the number of lines sent to lineLimit.
12111210

1212-
const msg = '\n...(truncated)';
1211+
const msg = '\n(truncated)';
12131212

12141213
const sendingEvent: MatrixMessageEvent = { ...event,
12151214
content: {

src/models/IrcAction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ export class IrcAction {
5454
return new IrcAction(matrixAction.type, matrixAction.text, matrixAction.ts);
5555
case "image":
5656
return new IrcAction(
57-
"emote", "uploaded an image: " + matrixAction.text, matrixAction.ts
57+
"message", "" + matrixAction.text, matrixAction.ts
5858
);
5959
case "video":
6060
return new IrcAction(
61-
"emote", "uploaded a video: " + matrixAction.text, matrixAction.ts
61+
"message", "" + matrixAction.text, matrixAction.ts
6262
);
6363
case "audio":
6464
return new IrcAction(
65-
"emote", "uploaded an audio file: " + matrixAction.text, matrixAction.ts
65+
"message", "" + matrixAction.text, matrixAction.ts
6666
);
6767
case "file":
68-
return new IrcAction("emote", "posted a file: " + matrixAction.text, matrixAction.ts);
68+
return new IrcAction("message", "" + matrixAction.text, matrixAction.ts);
6969
case "topic":
7070
if (matrixAction.text === null) {
7171
break;

src/models/MatrixAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ export class MatrixAction {
220220

221221
if (filename) {
222222
url += `/${encodeURIComponent(filename)}`;
223-
text = `${fileSize} < ${url} >`;
223+
text = `${url} ${fileSize}`;
224224
}
225225
else {
226226
fileSize = fileSize ? ` ${fileSize}` : "";
227227
// If not a filename, print the body
228-
text = `${event.content.body}${fileSize} < ${url} >`;
228+
text = `${url} ${event.content.body}${fileSize}`;
229229
}
230230
}
231231
}

0 commit comments

Comments
 (0)