d->m: Fix conversion of PK replies to Discord user

This commit is contained in:
Cadence Ember 2024-02-13 14:38:41 +13:00
parent d673296619
commit 13d1f86d31
3 changed files with 78 additions and 5 deletions

View file

@ -261,10 +261,14 @@ async function messageToEvent(message, guild, options = {}, di) {
we generate a partial referenced_message based on what PK provided. we don't need everything, since this will only be used for further message-to-event converting. we generate a partial referenced_message based on what PK provided. we don't need everything, since this will only be used for further message-to-event converting.
the following properties are necessary: the following properties are necessary:
- content: used for generating the reply fallback - content: used for generating the reply fallback
- author: used for the top of the reply fallback (only used for discord authors. for matrix authors, repliedToEventSenderMxid is set.)
*/ */
// @ts-ignore
message.referenced_message = { message.referenced_message = {
content: message.embeds[0].description.replace(/^.*?\)\*\*\s*/, "") content: message.embeds[0].description.replace(/^.*?\)\*\*\s*/, ""),
// @ts-ignore
author: {
username: message.embeds[0].author.name.replace(/\s*↩️\s*$/, "")
}
} }
message.embeds.shift() message.embeds.shift()
repliedToEventRow = row repliedToEventRow = row

View file

@ -29,8 +29,8 @@ function mockGetEvent(t, roomID_in, eventID_in, outer) {
} }
} }
test("message2event: pk reply is converted to native matrix reply", async t => { test("message2event: pk reply to matrix is converted to native matrix reply", async t => {
const events = await messageToEvent(data.pk_message.pk_reply, {}, {}, { const events = await messageToEvent(data.pk_message.pk_reply_to_matrix, {}, {}, {
api: { api: {
getEvent: mockGetEvent(t, "!TqlyQmifxGUggEmdBN:cadence.moe", "$NB6nPgO2tfXyIwwDSF0Ga0BUrsgX1S-0Xl-jAvI8ucU", { getEvent: mockGetEvent(t, "!TqlyQmifxGUggEmdBN:cadence.moe", "$NB6nPgO2tfXyIwwDSF0Ga0BUrsgX1S-0Xl-jAvI8ucU", {
type: "m.room.message", type: "m.room.message",
@ -62,3 +62,33 @@ test("message2event: pk reply is converted to native matrix reply", async t => {
} }
}]) }])
}) })
test("message2event: pk reply to discord is converted to native matrix reply", async t => {
const events = await messageToEvent(data.pk_message.pk_reply_to_discord, {}, {}, {
api: {
getEvent: mockGetEvent(t, "!TqlyQmifxGUggEmdBN:cadence.moe", "$NB6nPgO2tfXyIwwDSF0Ga0BUrsgX1S-0Xl-jAvI8ucU", {
type: "m.room.message",
sender: "@_ooye_.wing.:cadence.moe",
content: {
msgtype: "m.text",
body: "some text"
}
})
}
})
t.deepEqual(events, [{
$type: "m.room.message",
msgtype: "m.text",
"m.mentions": {},
body: "> wing: some text\n\nthis is a reply",
format: "org.matrix.custom.html",
formatted_body: '<mx-reply><blockquote><a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$mtR8cJqM4fKno1bVsm8F4wUVqSntt2sq6jav1lyavuA">In reply to</a> wing<br>'
+ "some text</blockquote></mx-reply>"
+ "this is a reply",
"m.relates_to": {
"m.in_reply_to": {
event_id: "$mtR8cJqM4fKno1bVsm8F4wUVqSntt2sq6jav1lyavuA"
}
}
}])
})

View file

@ -1765,7 +1765,7 @@ module.exports = {
} }
}, },
pk_message: { pk_message: {
pk_reply: { pk_reply_to_matrix: {
id: "1202543812644306965", id: "1202543812644306965",
type: 0, type: 0,
content: "this is a reply", content: "this is a reply",
@ -1803,6 +1803,45 @@ module.exports = {
components: [], components: [],
application_id: "466378653216014359", application_id: "466378653216014359",
webhook_id: "1195662438662680720" webhook_id: "1195662438662680720"
},
pk_reply_to_discord: {
id: "1202543812644306965",
type: 0,
content: "this is a reply",
channel_id: "1160894080998461480",
author: {
id: "1195662438662680720",
username: "special name",
avatar: "6b44a106659e78a2550474c61889194d",
discriminator: "0000",
public_flags: 0,
flags: 0,
bot: true,
global_name: null
},
attachments: [],
embeds: [
{
type: "rich",
description: "**[Reply to:](https://discord.com/channels/112760669178241024/112760669178241024/1141501302736695316)** some text",
author: {
name: "wing",
icon_url: "https://cdn.discordapp.com/avatars/112890272819507200/47db1be7ab77e1d812a4573177af0692.png",
proxy_icon_url: "https://images-ext-1.discordapp.net/external/wWslraV-s-bLDwphL64YxeDm30M7PIhQQy0EQa8jpDc/https/cdn.discordapp.com/avatars/112890272819507200/47db1be7ab77e1d812a4573177af0692.png"
}
}
],
mentions: [],
mention_roles: [],
pinned: false,
mention_everyone: false,
tts: false,
timestamp: "2024-02-01T09:19:47.118000+00:00",
edited_timestamp: null,
flags: 0,
components: [],
application_id: "466378653216014359",
webhook_id: "1195662438662680720"
} }
}, },
message_with_embeds: { message_with_embeds: {