d->m: Better text for links to unbridged channels

This commit is contained in:
Cadence Ember 2024-02-14 11:57:01 +13:00
parent 553a9441d7
commit e0d96cde19
4 changed files with 63 additions and 3 deletions

View file

@ -41,8 +41,13 @@ function getDiscordParseCallbacks(message, guild, useHTML) {
},
/** @param {{id: string, type: "discordChannel", row: {room_id: string, name: string, nick: string?}?, via: string}} node */
channel: node => {
if (!node.row) {
return `#[channel-from-an-unknown-server]` // fallback for when this channel is not bridged
if (!node.row) { // fallback for when this channel is not bridged
const channel = discord.channels.get(node.id)
if (channel) {
return `#${channel.name} [channel not bridged]`
} else {
return `#unknown-channel [channel from an unbridged server]`
}
} else if (useHTML) {
return `<a href="https://matrix.to/#/${node.row.room_id}?${node.via}">#${node.row.nick || node.row.name}</a>`
} else {

View file

@ -105,7 +105,17 @@ test("message2event: unknown room mention", async t => {
$type: "m.room.message",
"m.mentions": {},
msgtype: "m.text",
body: "#[channel-from-an-unknown-server]"
body: "#unknown-channel [channel from an unbridged server]"
}])
})
test("message2event: unbridged room mention", async t => {
const events = await messageToEvent(data.message.unbridged_room_mention, data.guild.general, {})
t.deepEqual(events, [{
$type: "m.room.message",
"m.mentions": {},
msgtype: "m.text",
body: "#bad-boots-prison [channel not bridged]"
}])
})

View file

@ -536,6 +536,47 @@ module.exports = {
attachments: [],
guild_id: "112760669178241024"
},
unbridged_room_mention: {
type: 0,
tts: false,
timestamp: "2023-07-10T20:04:25.939000+00:00",
referenced_message: null,
pinned: false,
nonce: "1128054139385806848",
mentions: [],
mention_roles: [],
mention_everyone: false,
member: {
roles: [],
premium_since: null,
pending: false,
nick: null,
mute: false,
joined_at: "2015-11-11T09:55:40.321000+00:00",
flags: 0,
deaf: false,
communication_disabled_until: null,
avatar: null
},
id: "1128054143064494233",
flags: 0,
embeds: [],
edited_timestamp: null,
content: "<#498323546729086986>",
components: [],
channel_id: "266767590641238027",
author: {
username: "kumaccino",
public_flags: 128,
id: "113340068197859328",
global_name: "kumaccino",
discriminator: "0",
avatar_decoration: null,
avatar: "b48302623a12bc7c59a71328f72ccb39"
},
attachments: [],
guild_id: "112760669178241024"
},
simple_role_mentions: {
id: "1162374402785153106",
type: 0,

View file

@ -29,6 +29,10 @@ const discord = {
channels: new Map([
["497161350934560778", {
guild_id: "497159726455455754"
}],
["498323546729086986", {
guild_id: "497159726455455754",
name: "bad-boots-prison"
}]
])
}