Embed URL should only appear when embed has title
This commit is contained in:
parent
15e5ad88af
commit
1e8066ca0a
3 changed files with 290 additions and 6 deletions
|
@ -27,7 +27,6 @@ test("message2event embeds: reply with just an embed", async t => {
|
||||||
msgtype: "m.notice",
|
msgtype: "m.notice",
|
||||||
"m.mentions": {},
|
"m.mentions": {},
|
||||||
body: "| ## ⏺️ dynastic (@dynastic) https://twitter.com/i/user/719631291747078145"
|
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| 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| \n| ### Retweets"
|
||||||
+ "\n| 119"
|
+ "\n| 119"
|
||||||
|
@ -35,8 +34,7 @@ test("message2event embeds: reply with just an embed", async t => {
|
||||||
+ "\n| 5581"
|
+ "\n| 5581"
|
||||||
+ "\n| — Twitter",
|
+ "\n| — Twitter",
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: '<blockquote><p><strong><a href="https://twitter.com/i/user/719631291747078145">⏺️ dynastic (@dynastic)</a></strong></p>'
|
formatted_body: '<blockquote><p><strong><a href="https://twitter.com/i/user/719631291747078145">⏺️ dynastic (@dynastic)</a></strong>'
|
||||||
+ '<p><strong><a href="https://twitter.com/i/status/1707484191963648161">https://twitter.com/i/status/1707484191963648161</a></strong>'
|
|
||||||
+ '</p><p>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?'
|
+ '</p><p>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?'
|
||||||
+ '</p><p><strong>Retweets</strong><br>119</p><p><strong>Likes</strong><br>5581</p>— Twitter</blockquote>'
|
+ '</p><p><strong>Retweets</strong><br>119</p><p><strong>Likes</strong><br>5581</p>— Twitter</blockquote>'
|
||||||
}])
|
}])
|
||||||
|
@ -141,3 +139,51 @@ test("message2event embeds: crazy html is all escaped", async t => {
|
||||||
"m.mentions": {}
|
"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: `<blockquote><p><strong>Hi, I'm Amanda!</strong></p><p>I condone pirating music!</p></blockquote>`,
|
||||||
|
"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: `<blockquote><p>I condone pirating music!</p></blockquote>`,
|
||||||
|
"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: `<blockquote><p><strong>Amanda</strong></p><p>I condone pirating music!</p></blockquote>`,
|
||||||
|
"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: `<blockquote><p>I condone pirating music!</p></blockquote>`,
|
||||||
|
"m.mentions": {}
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
|
@ -517,7 +517,7 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
// Author and URL into a paragraph
|
// Author and URL into a paragraph
|
||||||
let authorNameText = embed.author?.name || ""
|
let authorNameText = embed.author?.name || ""
|
||||||
if (authorNameText && embed.author?.icon_url) authorNameText = `⏺️ ${authorNameText}` // using the emoji instead of an image
|
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) {
|
if (embed.author?.url) {
|
||||||
const authorURL = await transformContentMessageLinks(embed.author.url)
|
const authorURL = await transformContentMessageLinks(embed.author.url)
|
||||||
rep.addParagraph(`## ${authorNameText} ${authorURL}`, tag`<strong><a href="${authorURL}">${authorNameText}</a></strong>`)
|
rep.addParagraph(`## ${authorNameText} ${authorURL}`, tag`<strong><a href="${authorURL}">${authorNameText}</a></strong>`)
|
||||||
|
@ -534,8 +534,6 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
} else {
|
} else {
|
||||||
rep.addParagraph(`## ${body}`, `<strong>${html}</strong>`)
|
rep.addParagraph(`## ${body}`, `<strong>${html}</strong>`)
|
||||||
}
|
}
|
||||||
} else if (embed.url) {
|
|
||||||
rep.addParagraph(`## ${embed.url}`, tag`<strong><a href="${embed.url}">${embed.url}</a></strong>`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (embed.description) {
|
if (embed.description) {
|
||||||
|
|
240
test/data.js
240
test/data.js
|
@ -2282,6 +2282,246 @@ module.exports = {
|
||||||
edited_timestamp: null,
|
edited_timestamp: null,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
components: []
|
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: {
|
message_update: {
|
||||||
|
|
Loading…
Reference in a new issue