[WIP] threads. #74

Draft
Guzio wants to merge 147 commits from Guzio/out-of-your-element:mergable-fr-fr into main
3 changed files with 89 additions and 0 deletions
Showing only changes of commit 648472d305 - Show all commits

Merge remote-tracking branch 'cadence/main' into mergable-fr-fr

Guzio 2026-10-14 09:59:19 +02:00

View file

@ -960,6 +960,10 @@ async function messageToEvent(message, guild, options = {}, di) {
}
// Then components
// Shift component-type URL embeds here too
const componentEmbeds = dUtils.filterTo(message.embeds || [], e => e.type !== "components")
message.components ??= []
message.components.push(...componentEmbeds.map(e => e.components).flat(1))
if (message.components?.length) {
const stack = new mxUtils.MatrixStringBuilderStack()
/** @param {DiscordTypes.APIMessageComponent} component */
@ -1064,6 +1068,16 @@ async function messageToEvent(message, guild, options = {}, di) {
if ((message.flags ?? 0) & DiscordTypes.MessageFlags.IsComponentsV2) {
await addTextEvent(body, formatted_body, "m.text")
}
// Add as m.notice if component URL preview
else if (componentEmbeds.length) {
mergeTextEvents([{
msgtype: "m.notice",
body,
format: "org.matrix.custom.html",
formatted_body,
"m.mentions": mentions
}], events, true, false)
}
// Add to existing message if legacy components https://docs.discord.com/developers/components/reference#legacy-message-component-behavior
else {
mergeTextEvents([{

View file

@ -3,6 +3,29 @@ const {messageToEvent} = require("./message-to-event")
const data = require("../../../test/data")
const {mockGetEffectivePower} = require("../../matrix/utils.test")
test("message2event url preview components: wikipedia", async t => {
const events = await messageToEvent(data.message_with_components.wikipedia_component_url_preview, data.guild.general, {})
t.deepEqual(events, [
{
$type: "m.room.message",
body: "https://en.wikipedia.org/wiki/HTTP/2",
format: "org.matrix.custom.html",
formatted_body: "<a href=\"https://en.wikipedia.org/wiki/HTTP/2\">https://en.wikipedia.org/wiki/HTTP/2</a>",
"m.mentions": {},
msgtype: "m.text"
},
{
body: "| ### [HTTP/2](https://en.wikipedia.org/wiki/HTTP/2?wprov=diim1)"
+ "\n| "
+ "\n| HTTP/2 (originally named HTTP/2.0) is a major revision of the HTTP network protocol used by the World Wide Web. It was derived from the earlier experimental SPDY protocol, originally developed by Google. HTTP/2 was developed by the HTTP Working Group (also called httpbis, where \"bis\" means \"twice\" in Latin) of the Internet Engineering Task Force (…",
format: "org.matrix.custom.html",
formatted_body: "<blockquote><h3><a href=\"https://en.wikipedia.org/wiki/HTTP/2?wprov=diim1\">HTTP/2</a></h3>HTTP/2 (originally named HTTP/2.0) is a major revision of the HTTP network protocol used by the World Wide Web. It was derived from the earlier experimental SPDY protocol, originally developed by Google. HTTP/2 was developed by the HTTP Working Group (also called httpbis, where \"bis\" means \"twice\" in Latin) of the Internet Engineering Task Force (…</blockquote>",
msgtype: "m.notice",
"m.mentions": {}
}
])
})
test("message2event components: pk question mark output", async t => {
const events = await messageToEvent(data.message_with_components.pk_question_mark_response, data.guild.general, {})
t.deepEqual(events, [{

View file

@ -5456,6 +5456,58 @@ module.exports = {
}
},
message_with_components: {
wikipedia_component_url_preview: {
type: 0,
content: "https://en.wikipedia.org/wiki/HTTP/2",
mentions: [],
mention_roles: [],
attachments: [],
embeds: [
{
type: "components",
url: "https://en.wikipedia.org/wiki/HTTP/2",
content_scan_version: 4,
components: [
{
type: 17,
id: 1,
accent_color: null,
components: [
{
type: 10,
id: 2,
content: "### [HTTP/2](https://en.wikipedia.org/wiki/HTTP/2?wprov=diim1)\n\nHTTP/2 (originally named HTTP/2.0) is a major revision of the HTTP network protocol used by the World Wide Web. It was derived from the earlier experimental SPDY protocol, originally developed by Google. HTTP/2 was developed by the HTTP Working Group (also called httpbis, where \"bis\" means \"twice\" in Latin) of the Internet Engineering Task Force (…"
}
],
spoiler: false
}
]
}
],
timestamp: "2026-10-14T02:52:14.399000+00:00",
edited_timestamp: null,
flags: 0,
components: [],
id: "1559760719153602600",
channel_id: "1160893337029586956",
author: {
id: "1506959407827779736",
username: "dollmoder",
avatar: "37f1b0457fc28bccad57bf5baefa0b1b",
discriminator: "0000",
public_flags: 0,
flags: 0,
bot: true,
global_name: null,
clan: null,
primary_guild: null
},
pinned: false,
mention_everyone: false,
tts: false,
application_id: "684280192553844747",
webhook_id: "1506959407827779736"
},
pk_question_mark_response: {
type: 0,
content: '',