mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 20:32:50 +02:00
Resolve Matrix room aliases to Discord channels
This commit is contained in:
parent
6e55061760
commit
ad1aa2c0f6
4 changed files with 155 additions and 2 deletions
|
@ -330,9 +330,9 @@ async function uploadEndOfMessageSpriteSheet(content, attachments, pendingFiles,
|
|||
*/
|
||||
async function handleRoomOrMessageLinks(input, di) {
|
||||
let offset = 0
|
||||
for (const match of [...input.matchAll(/("?https:\/\/matrix.to\/#\/(![^"/, ?)]+)(?:\/(\$[^"/ ?)]+))?(?:\?[^",:!? )]*?)?)(">|[,<\n )]|$)/g)]) {
|
||||
for (const match of [...input.matchAll(/("?https:\/\/matrix.to\/#\/((?:#|%23|!)[^"/, ?)]+)(?:\/(\$[^"/ ?)]+))?(?:\?[^",:!? )]*?)?)(">|[,<\n )]|$)/g)]) {
|
||||
assert(typeof match.index === "number")
|
||||
const [_, attributeValue, roomID, eventID, endMarker] = match
|
||||
let [_, attributeValue, roomID, eventID, endMarker] = match
|
||||
let result
|
||||
|
||||
const resultType = endMarker === '">' ? "html" : "plain"
|
||||
|
@ -350,6 +350,16 @@ async function handleRoomOrMessageLinks(input, di) {
|
|||
// Don't process links that are part of the reply fallback, they'll be removed entirely by turndown
|
||||
if (input.slice(match.index + match[0].length + offset).startsWith("In reply to")) continue
|
||||
|
||||
// Resolve room alias to room ID if needed
|
||||
roomID = decodeURIComponent(roomID)
|
||||
if (roomID[0] === "#") {
|
||||
try {
|
||||
roomID = await di.api.getAlias(roomID)
|
||||
} catch (e) {
|
||||
continue // Room alias is unresolvable, so it can't be converted
|
||||
}
|
||||
}
|
||||
|
||||
const channelID = select("channel_room", "channel_id", {room_id: roomID}).pluck().get()
|
||||
if (!channelID) continue
|
||||
if (!eventID) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue