add sticker support

This commit is contained in:
emerson 2022-10-14 10:02:44 -04:00
parent 43ea4a2a54
commit 7cdba2c276
3 changed files with 24 additions and 1 deletions

View file

@ -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

View file

@ -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 | ✅ | ✅ ||

View file

@ -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:\/\/(?<servername>[^\/]+)\/(?<mediaid>.+)/)
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) {