From 1e8066ca0ab9908eb5c5d1509375684e4d276729 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 6 Mar 2024 09:34:46 +1300 Subject: [PATCH] Embed URL should only appear when embed has title --- .../message-to-event.embeds.test.js | 52 +++- d2m/converters/message-to-event.js | 4 +- test/data.js | 240 ++++++++++++++++++ 3 files changed, 290 insertions(+), 6 deletions(-) diff --git a/d2m/converters/message-to-event.embeds.test.js b/d2m/converters/message-to-event.embeds.test.js index dfc5679c..0ac50180 100644 --- a/d2m/converters/message-to-event.embeds.test.js +++ b/d2m/converters/message-to-event.embeds.test.js @@ -27,7 +27,6 @@ test("message2event embeds: reply with just an embed", async t => { msgtype: "m.notice", "m.mentions": {}, body: "| ## ⏺️ dynastic (@dynastic) https://twitter.com/i/user/719631291747078145" - + "\n| \n| ## https://twitter.com/i/status/1707484191963648161" + "\n| \n| does anyone know where to find that one video of the really mysterious yam-like object being held up to a bunch of random objects, like clocks, and they have unexplained impossible reactions to it?" + "\n| \n| ### Retweets" + "\n| 119" @@ -35,8 +34,7 @@ test("message2event embeds: reply with just an embed", async t => { + "\n| 5581" + "\n| — Twitter", format: "org.matrix.custom.html", - formatted_body: '

⏺️ dynastic (@dynastic)

' - + '

https://twitter.com/i/status/1707484191963648161' + formatted_body: '

⏺️ dynastic (@dynastic)' + '

does anyone know where to find that one video of the really mysterious yam-like object being held up to a bunch of random objects, like clocks, and they have unexplained impossible reactions to it?' + '

Retweets
119

Likes
5581

— Twitter
' }]) @@ -141,3 +139,51 @@ test("message2event embeds: crazy html is all escaped", async t => { "m.mentions": {} }]) }) + +test("message2event embeds: title without url", async t => { + const events = await messageToEvent(data.message_with_embeds.title_without_url, data.guild.general) + t.deepEqual(events, [{ + $type: "m.room.message", + msgtype: "m.notice", + body: "| ## Hi, I'm Amanda!\n| \n| I condone pirating music!", + format: "org.matrix.custom.html", + formatted_body: `

Hi, I'm Amanda!

I condone pirating music!

`, + "m.mentions": {} + }]) +}) + +test("message2event embeds: url without title", async t => { + const events = await messageToEvent(data.message_with_embeds.url_without_title, data.guild.general) + t.deepEqual(events, [{ + $type: "m.room.message", + msgtype: "m.notice", + body: "| I condone pirating music!", + format: "org.matrix.custom.html", + formatted_body: `

I condone pirating music!

`, + "m.mentions": {} + }]) +}) + +test("message2event embeds: author without url", async t => { + const events = await messageToEvent(data.message_with_embeds.author_without_url, data.guild.general) + t.deepEqual(events, [{ + $type: "m.room.message", + msgtype: "m.notice", + body: "| ## Amanda\n| \n| I condone pirating music!", + format: "org.matrix.custom.html", + formatted_body: `

Amanda

I condone pirating music!

`, + "m.mentions": {} + }]) +}) + +test("message2event embeds: author url without name", async t => { + const events = await messageToEvent(data.message_with_embeds.author_url_without_name, data.guild.general) + t.deepEqual(events, [{ + $type: "m.room.message", + msgtype: "m.notice", + body: "| I condone pirating music!", + format: "org.matrix.custom.html", + formatted_body: `

I condone pirating music!

`, + "m.mentions": {} + }]) +}) diff --git a/d2m/converters/message-to-event.js b/d2m/converters/message-to-event.js index 89edacca..69a4808a 100644 --- a/d2m/converters/message-to-event.js +++ b/d2m/converters/message-to-event.js @@ -517,7 +517,7 @@ async function messageToEvent(message, guild, options = {}, di) { // Author and URL into a paragraph let authorNameText = embed.author?.name || "" if (authorNameText && embed.author?.icon_url) authorNameText = `⏺️ ${authorNameText}` // using the emoji instead of an image - if (authorNameText || embed.author?.url) { + if (authorNameText) { if (embed.author?.url) { const authorURL = await transformContentMessageLinks(embed.author.url) rep.addParagraph(`## ${authorNameText} ${authorURL}`, tag`${authorNameText}`) @@ -534,8 +534,6 @@ async function messageToEvent(message, guild, options = {}, di) { } else { rep.addParagraph(`## ${body}`, `${html}`) } - } else if (embed.url) { - rep.addParagraph(`## ${embed.url}`, tag`${embed.url}`) } if (embed.description) { diff --git a/test/data.js b/test/data.js index 2d0f7954..49b84e65 100644 --- a/test/data.js +++ b/test/data.js @@ -2282,6 +2282,246 @@ module.exports = { edited_timestamp: null, flags: 0, components: [] + }, + title_without_url: { + guild_id: "497159726455455754", + mentions: [], + id: "1141934888862351440", + type: 20, + content: "", + channel_id: "497161350934560778", + author: { + id: "1109360903096369153", + username: "Amanda 🎵", + avatar: "d56cd1b26e043ae512edae2214962faa", + discriminator: "2192", + public_flags: 524288, + flags: 524288, + bot: true, + banner: null, + accent_color: null, + global_name: null, + avatar_decoration_data: null, + banner_color: null + }, + attachments: [], + embeds: [ + { + type: "rich", + color: 3092790, + title: "Hi, I'm Amanda!", + description: "I condone pirating music!" + } + ], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "2023-08-18T03:21:33.629000+00:00", + edited_timestamp: null, + flags: 0, + components: [], + application_id: "1109360903096369153", + interaction: { + id: "1141934887608254475", + type: 2, + name: "stats", + user: { + id: "320067006521147393", + username: "papiophidian", + avatar: "47a19b0445069b826e136da4df4259bb", + discriminator: "0", + public_flags: 4194880, + flags: 4194880, + banner: null, + accent_color: null, + global_name: "PapiOphidian", + avatar_decoration_data: null, + banner_color: null + } + }, + webhook_id: "1109360903096369153" + }, + url_without_title: { + guild_id: "497159726455455754", + mentions: [], + id: "1141934888862351440", + type: 20, + content: "", + channel_id: "497161350934560778", + author: { + id: "1109360903096369153", + username: "Amanda 🎵", + avatar: "d56cd1b26e043ae512edae2214962faa", + discriminator: "2192", + public_flags: 524288, + flags: 524288, + bot: true, + banner: null, + accent_color: null, + global_name: null, + avatar_decoration_data: null, + banner_color: null + }, + attachments: [], + embeds: [ + { + type: "rich", + color: 3092790, + url: "https://amanda.moe", + description: "I condone pirating music!" + } + ], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "2023-08-18T03:21:33.629000+00:00", + edited_timestamp: null, + flags: 0, + components: [], + application_id: "1109360903096369153", + interaction: { + id: "1141934887608254475", + type: 2, + name: "stats", + user: { + id: "320067006521147393", + username: "papiophidian", + avatar: "47a19b0445069b826e136da4df4259bb", + discriminator: "0", + public_flags: 4194880, + flags: 4194880, + banner: null, + accent_color: null, + global_name: "PapiOphidian", + avatar_decoration_data: null, + banner_color: null + } + }, + webhook_id: "1109360903096369153" + }, + author_without_url: { + guild_id: "497159726455455754", + mentions: [], + id: "1141934888862351440", + type: 20, + content: "", + channel_id: "497161350934560778", + author: { + id: "1109360903096369153", + username: "Amanda 🎵", + avatar: "d56cd1b26e043ae512edae2214962faa", + discriminator: "2192", + public_flags: 524288, + flags: 524288, + bot: true, + banner: null, + accent_color: null, + global_name: null, + avatar_decoration_data: null, + banner_color: null + }, + attachments: [], + embeds: [ + { + type: "rich", + color: 3092790, + author: { + name: "Amanda" + }, + description: "I condone pirating music!" + } + ], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "2023-08-18T03:21:33.629000+00:00", + edited_timestamp: null, + flags: 0, + components: [], + application_id: "1109360903096369153", + interaction: { + id: "1141934887608254475", + type: 2, + name: "stats", + user: { + id: "320067006521147393", + username: "papiophidian", + avatar: "47a19b0445069b826e136da4df4259bb", + discriminator: "0", + public_flags: 4194880, + flags: 4194880, + banner: null, + accent_color: null, + global_name: "PapiOphidian", + avatar_decoration_data: null, + banner_color: null + } + }, + webhook_id: "1109360903096369153" + }, + author_url_without_name: { + guild_id: "497159726455455754", + mentions: [], + id: "1141934888862351440", + type: 20, + content: "", + channel_id: "497161350934560778", + author: { + id: "1109360903096369153", + username: "Amanda 🎵", + avatar: "d56cd1b26e043ae512edae2214962faa", + discriminator: "2192", + public_flags: 524288, + flags: 524288, + bot: true, + banner: null, + accent_color: null, + global_name: null, + avatar_decoration_data: null, + banner_color: null + }, + attachments: [], + embeds: [ + { + type: "rich", + color: 3092790, + author: { + url: "https://amanda.moe" + }, + description: "I condone pirating music!" + } + ], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "2023-08-18T03:21:33.629000+00:00", + edited_timestamp: null, + flags: 0, + components: [], + application_id: "1109360903096369153", + interaction: { + id: "1141934887608254475", + type: 2, + name: "stats", + user: { + id: "320067006521147393", + username: "papiophidian", + avatar: "47a19b0445069b826e136da4df4259bb", + discriminator: "0", + public_flags: 4194880, + flags: 4194880, + banner: null, + accent_color: null, + global_name: "PapiOphidian", + avatar_decoration_data: null, + banner_color: null + } + }, + webhook_id: "1109360903096369153" } }, message_update: {