From c30270f435d0eb3f2e2cd89abdfcd9233b9b7180 Mon Sep 17 00:00:00 2001 From: emerson Date: Wed, 2 Feb 2022 14:01:02 -0500 Subject: [PATCH] Add ability to highlight matrix users --- README.md | 8 +++++++- src/Client.ts | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 91003e5..fbb3a9a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ That said, it is usable for basic chatting. See the support matrix (pun intended - Built-in bouncer: Multiple IRC clients can be authenticated to a Matrix user - Multi-user: Log in to multiple Matrix users at the same time +## Notes for IRC users + +There's a few things "different" from a standard IRC network: +- You can't PM users like normal. Direct messages are notated by the `&` channel prefix. Once joining channels is implemented, you can join the `&` channel and it will auto-invite the user. +- In order to highlight users, you need to prefix their nick with an `@`, so `@emerson: hi`. Reflection automatically expands this to the user's MXID, so even though it's annoying, it's needed to stop inadvertent highlights for now. + ## FAQs ### Who is this for? @@ -41,7 +47,7 @@ Note that there are no PMs, because Matrix doesn't differentiate between DMs and | Name | M->I | I->M | Notes | | ---- | :--: | :--: | ----- | -| text, notice, emote messages | ✅ | ✅ | Highlighting users with their IRC nick doesn't translate into highlighting their Matrix user [#23](https://todo.sr.ht/~emerson/reflectionircd/23) | +| text, notice, emote messages | ✅ | ✅ || | image, file, audio, video messages | 🟨 | ❌ | Show up as links on IRC | | Channel joins | ✅ | ❌ | [#1](https://todo.sr.ht/~emerson/reflectionircd/1) | | Channel parts | ✅ | ✅ || diff --git a/src/Client.ts b/src/Client.ts index 30f8df7..1e85813 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -340,9 +340,17 @@ export class Client { msgtype = 'm.emote'; msgbody = msgbody.replace(/\x01(ACTION\s)?/gi, ''); } - const roomId = targetChannel.roomId; + const highlightFilteredMsg = msgbody.split(" ").map(w => { + if (!w.startsWith('@')) return w; + const endingCharMatch = w.match(/[,:]$/); + const endingChar = (endingCharMatch) ? endingCharMatch[0] : ""; + const endingCharIndex = (endingCharMatch) ? endingCharMatch.index : 0; + const nickToSearch = (endingCharIndex === 0) ? w.substring(1) : w.substring(1, endingCharIndex); + const maybeHighlight = targetChannel.matrixUsers.get(nickToSearch); + return (maybeHighlight) ? `${maybeHighlight.mxid}${endingChar}` : w; + }) const content = { - "body": msgbody, + "body": highlightFilteredMsg.join(" "), "msgtype": msgtype, "m.relates_to": {} }