From 7cdba2c276d7a466ddeafe3c8e232bcbd1763b19 Mon Sep 17 00:00:00 2001 From: emerson Date: Fri, 14 Oct 2022 10:02:44 -0400 Subject: [PATCH] add sticker support --- CHANGELOG.md | 1 + README.md | 2 +- src/Server.ts | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42d405a..f0d8d0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added - `AWAY` and `away-notify` - Typing notifications +- Sticker support (M->I only) ## v0.1.1 - 2022-02-09 - Fix `DELETEMSG` being sent to unsupporting clients diff --git a/README.md b/README.md index a740759..701b91e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ On Libera I'm `emerson`, on Matrix I'm `@emersonveenstra:matrix.org`, feel free | Name | M->I | I->M | Notes | | ---- | :--: | :--: | ----- | | text, notice, emote messages | ✅ | ✅ || -| image, file, audio, video messages | 🟨 | ❌ | Show up as links on IRC | +| image, sticker, file, audio, video messages | 🟨 | ❌ | Show up as links on IRC | | Channel joins | ✅ | ❌ | [#1](https://todo.sr.ht/~emerson/reflectionircd/1) | | Channel parts | ✅ | ✅ || | Channel kicks | ✅ | ✅ || diff --git a/src/Server.ts b/src/Server.ts index 757695a..6fea2f8 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -251,6 +251,9 @@ export class Server { case 'm.room.topic': this.handleMatrixTopic(nextEvent, targetChannel); break; + case 'm.sticker': + this.handleMatrixSticker(nextEvent, targetChannel); + break; case 'm.typing': this.handleMatrixTyping(nextEvent, targetChannel); break; @@ -590,6 +593,25 @@ export class Server { }); } + handleMatrixSticker(event: any, targetChannel: Channel) { + const sourceUser = this.getOrCreateMatrixUser(event["sender"]); + this.checkForLazyJoin(event, sourceUser, targetChannel); + const altText = event["content"]?.["body"]; + const imgMxc = event["content"]?.["url"]; + if (!altText || !imgMxc) { + return; + } + const mxcregex = imgMxc.match(/mxc:\/\/(?[^\/]+)\/(?.+)/) + let uri = imgMxc; + if (!mxcregex || !mxcregex.groups) { + console.log(`Failed to parse MXC URI: ${imgMxc}`); + } else { + uri = `${this.homeserver}/_matrix/media/v3/download/${mxcregex.groups.servername}/${mxcregex.groups.mediaid}`; + } + const messageContent = `\x01ACTION sent a sticker: ${altText}: ${uri}\x01`; + this.sendToAll(sourceUser.getMask(), 'PRIVMSG', [targetChannel.name, messageContent]); + } + handleMatrixTyping(event: any, targetChannel: Channel) { const typingUsers = event["content"]?.["user_ids"]; if (!typingUsers) {