Support multiple versions of rooms

This commit is contained in:
Cadence Ember
2025-11-26 15:43:48 +13:00
parent e6c30f80b5
commit a441c476f8
29 changed files with 520 additions and 349 deletions
+12 -7
View File
@@ -1,7 +1,8 @@
// @ts-check
const DiscordTypes = require("discord-api-types/v10")
const {discord, sync, from} = require("../../passthrough")
const {discord, sync, select, from} = require("../../passthrough")
const assert = require("assert").strict
/** @type {import("../../matrix/api")} */
const api = sync.require("../../matrix/api")
@@ -11,9 +12,9 @@ const api = sync.require("../../matrix/api")
* @param {{api: typeof api}} di
* @returns {Promise<DiscordTypes.APIInteractionResponse>}
*/
async function _interact({guild_id, data}, {api}) {
const message = from("event_message").join("message_channel", "message_id").join("channel_room", "channel_id")
.select("name", "nick", "source", "channel_id", "room_id", "event_id").where({message_id: data.target_id, part: 0}).get()
async function _interact({guild_id, channel, data}, {api}) {
const message = from("event_message").join("message_room", "message_id").join("historical_channel_room", "historical_room_index")
.select("source", "reference_channel_id", "room_id", "event_id").where({message_id: data.target_id, part: 0}).get()
if (!message) {
return {
@@ -25,15 +26,19 @@ async function _interact({guild_id, data}, {api}) {
}
}
const channel_id = message.reference_channel_id
const room = select("channel_room", ["name", "nick"], {channel_id}).get()
assert(room)
const idInfo = `\n-# Room ID: \`${message.room_id}\`\n-# Event ID: \`${message.event_id}\``
const roomName = message.nick || message.name
const roomName = room.nick || room.name
if (message.source === 1) { // from Discord
const userID = data.resolved.messages[data.target_id].author.id
return {
type: DiscordTypes.InteractionResponseType.ChannelMessageWithSource,
data: {
content: `Bridged <@${userID}> https://discord.com/channels/${guild_id}/${message.channel_id}/${data.target_id} on Discord to [${roomName}](<https://matrix.to/#/${message.room_id}/${message.event_id}>) on Matrix.`
content: `Bridged <@${userID}> https://discord.com/channels/${guild_id}/${channel_id}/${data.target_id} on Discord to [${roomName}](<https://matrix.to/#/${message.room_id}/${message.event_id}>) on Matrix.`
+ idInfo,
flags: DiscordTypes.MessageFlags.Ephemeral
}
@@ -45,7 +50,7 @@ async function _interact({guild_id, data}, {api}) {
return {
type: DiscordTypes.InteractionResponseType.ChannelMessageWithSource,
data: {
content: `Bridged [${event.sender}](<https://matrix.to/#/${event.sender}>)'s message in [${roomName}](<https://matrix.to/#/${message.room_id}/${message.event_id}>) on Matrix to https://discord.com/channels/${guild_id}/${message.channel_id}/${data.target_id} on Discord.`
content: `Bridged [${event.sender}](<https://matrix.to/#/${event.sender}>)'s message in [${roomName}](<https://matrix.to/#/${message.room_id}/${message.event_id}>) on Matrix to https://discord.com/channels/${guild_id}/${channel_id}/${data.target_id} on Discord.`
+ idInfo,
flags: DiscordTypes.MessageFlags.Ephemeral
}
+4 -5
View File
@@ -18,8 +18,8 @@ const api = sync.require("../../matrix/api")
async function* _interact({data, guild_id}, {api}) {
// Get message info
const row = from("event_message")
.join("message_channel", "message_id")
.select("event_id", "source", "channel_id")
.join("message_room", "message_id").join("historical_channel_room", "historical_room_index")
.select("event_id", "source", "room_id", "reference_channel_id")
.where({message_id: data.target_id})
.get()
@@ -35,10 +35,9 @@ async function* _interact({data, guild_id}, {api}) {
}
// Get the message sender, the person that will be inspected/edited
const eventID = row.event_id
const roomID = select("channel_room", "room_id", {channel_id: row.channel_id}).pluck().get()
const roomID = select("channel_room", "room_id", {channel_id: row.reference_channel_id}).pluck().get()
assert(roomID)
const event = await api.getEvent(roomID, eventID)
const event = await api.getEvent(row.room_id, row.event_id)
const sender = event.sender
// Get the space, where the power levels will be inspected/edited
+1 -1
View File
@@ -16,7 +16,7 @@ const utils = sync.require("../../m2d/converters/utils")
* @returns {AsyncGenerator<{[k in keyof InteractionMethods]?: Parameters<InteractionMethods[k]>[2]}>}
*/
async function* _interact({data}, {api}) {
const row = from("event_message").join("message_channel", "message_id").join("channel_room", "channel_id")
const row = from("event_message").join("message_room", "message_id").join("historical_channel_room", "historical_room_index")
.select("event_id", "room_id").where({message_id: data.target_id}).get()
if (!row) {
return yield {createInteractionResponse: {