From 5af7d6bf421995f74b8aff4d62262498167f7410 Mon Sep 17 00:00:00 2001
From: Cadence Ember Matrix - Decentralised and secure communication`
+ + ` You're invited to talk on Matrix. If you don't already have a client this link will help you pick one, and join the conversation. If you already have one, this link will help you join the conversationIn reply to a Discord user
[Replied-to message content wasn't provided by Discord]
`,
+ "m.mentions": {}
+ }])
+ t.deepEqual(promotions, []) // TODO: it would be ideal to promote this to reaction_part = 0. this is OK to do because the main message won't have had any reactions yet.
+ t.equal(senderMxid, "@_ooye_cadence:cadence.moe")
+})
diff --git a/test/data.js b/test/data.js
index 456033a..058a992 100644
--- a/test/data.js
+++ b/test/data.js
@@ -1990,6 +1990,91 @@ module.exports = {
edited_timestamp: null,
flags: 0,
components: []
+ },
+ embed_will_be_generated_on_reply: {
+ type: 19,
+ content: "https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe/$aLVZyiC3HlOu-prCSIaXlQl68I8leUdnPFiCwkgn6qM",
+ mentions: [],
+ mention_roles: [],
+ attachments: [],
+ embeds: [
+ {
+ type: "link",
+ url: "https://matrix.to/",
+ title: "Matrix - Decentralised and secure communication",
+ description: "You're invited to talk on Matrix. If you don't already have a client this link will help you pick one, and join the conversation. If you already have one, this link will help you join the conversation",
+ reference_id: "1278002262400176128",
+ thumbnail: {
+ url: "https://matrix.org/blog/img/matrix-logo.png",
+ proxy_url: "https://images-ext-1.discordapp.net/external/3yPmfN-_U_7Xn8hLSG77nY9IvdtITH0GPrB6OX3JjEI/https/matrix.org/blog/img/matrix-logo.png",
+ width: 800,
+ height: 400,
+ placeholder: "OAgOBIComJeHeId/dXgAAAAAAA==",
+ placeholder_version: 1
+ }
+ }
+ ],
+ timestamp: "2024-08-27T14:44:43.490000+00:00",
+ edited_timestamp: null,
+ flags: 0,
+ components: [],
+ id: "1278002262400176128",
+ channel_id: "1100319550446252084",
+ author: {
+ id: "772659086046658620",
+ username: "cadence.worm",
+ avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
+ discriminator: "0",
+ public_flags: 0,
+ flags: 0,
+ banner: null,
+ accent_color: null,
+ global_name: "cadence",
+ avatar_decoration_data: null,
+ banner_color: null,
+ clan: null
+ },
+ pinned: false,
+ mention_everyone: false,
+ tts: false,
+ message_reference: {
+ type: 0,
+ channel_id: "1100319550446252084",
+ message_id: "1278001833876525057",
+ guild_id: "1100319549670301727"
+ },
+ position: 0,
+ referenced_message: {
+ type: 0,
+ content: "b",
+ mentions: [],
+ mention_roles: [],
+ attachments: [],
+ embeds: [],
+ timestamp: "2024-08-27T14:43:01.322000+00:00",
+ edited_timestamp: "2024-08-27T14:43:06.277000+00:00",
+ flags: 0,
+ components: [],
+ id: "1278001833876525057",
+ channel_id: "1100319550446252084",
+ author: {
+ id: "772659086046658620",
+ username: "cadence.worm",
+ avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
+ discriminator: "0",
+ public_flags: 0,
+ flags: 0,
+ banner: null,
+ accent_color: null,
+ global_name: "cadence",
+ avatar_decoration_data: null,
+ banner_color: null,
+ clan: null
+ },
+ pinned: false,
+ mention_everyone: false,
+ tts: false
+ }
}
},
pk_message: {
@@ -3709,6 +3794,70 @@ module.exports = {
],
guild_id: "112760669178241024",
id: "1210387798297682020"
+ },
+ embed_generated_on_reply: {
+ attachments: [],
+ author: {
+ avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
+ avatar_decoration_data: null,
+ clan: null,
+ discriminator: "0",
+ global_name: "cadence",
+ id: "772659086046658620",
+ public_flags: 0,
+ username: "cadence.worm"
+ },
+ channel_id: "1100319550446252084",
+ components: [],
+ content: "https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe/$aLVZyiC3HlOu-prCSIaXlQl68I8leUdnPFiCwkgn6qM",
+ edited_timestamp: null,
+ embeds: [
+ {
+ description: "You're invited to talk on Matrix. If you don't already have a client this link will help you pick one, and join the conversation. If you already have one, this link will help you join the conversation",
+ reference_id: "1278002262400176128",
+ thumbnail: {
+ height: 400,
+ placeholder: "OAgOBIComJeHeId/dXgAAAAAAA==",
+ placeholder_version: 1,
+ proxy_url: "https://images-ext-1.discordapp.net/external/3yPmfN-_U_7Xn8hLSG77nY9IvdtITH0GPrB6OX3JjEI/https/matrix.org/blog/img/matrix-logo.png",
+ url: "https://matrix.org/blog/img/matrix-logo.png",
+ width: 800
+ },
+ title: "Matrix - Decentralised and secure communication",
+ type: "link",
+ url: "https://matrix.to/"
+ }
+ ],
+ flags: 0,
+ guild_id: "1100319549670301727",
+ id: "1278002262400176128",
+ member: {
+ avatar: null,
+ banner: null,
+ communication_disabled_until: null,
+ deaf: false,
+ flags: 0,
+ joined_at: "2023-04-25T07:17:03.696000+00:00",
+ mute: false,
+ nick: "worm",
+ pending: false,
+ premium_since: null,
+ roles: []
+ },
+ mention_everyone: false,
+ mention_roles: [],
+ mentions: [],
+ message_reference: {
+ channel_id: "1100319550446252084",
+ guild_id: "1100319549670301727",
+ message_id: "1278001833876525057",
+ type: 0
+ },
+ pinned: false,
+ position: 0,
+ timestamp: "2024-08-27T14:44:43.490000+00:00",
+ tts: false,
+ type: 19
}
},
special_message: {
diff --git a/test/ooye-test-data.sql b/test/ooye-test-data.sql
index 4666b4d..07be17f 100644
--- a/test/ooye-test-data.sql
+++ b/test/ooye-test-data.sql
@@ -24,13 +24,15 @@ INSERT INTO sim (user_id, sim_name, localpart, mxid) VALUES
('111604486476181504', 'kyuugryphon', '_ooye_kyuugryphon', '@_ooye_kyuugryphon:cadence.moe'),
('1109360903096369153', 'amanda', '_ooye_amanda', '@_ooye_amanda:cadence.moe'),
('43d378d5-1183-47dc-ab3c-d14e21c3fe58', '_pk_zoego', '_ooye__pk_zoego', '@_ooye__pk_zoego:cadence.moe'),
-('320067006521147393', 'papiophidian', '_ooye_papiophidian', '@_ooye_papiophidian:cadence.moe');
+('320067006521147393', 'papiophidian', '_ooye_papiophidian', '@_ooye_papiophidian:cadence.moe'),
+('772659086046658620', 'cadence', '_ooye_cadence', '@_ooye_cadence:cadence.moe');
INSERT INTO sim_proxy (user_id, proxy_owner_id, displayname) VALUES
('43d378d5-1183-47dc-ab3c-d14e21c3fe58', '196188877885538304', 'Azalea &flwr; 🌺');
INSERT INTO sim_member (mxid, room_id, hashed_profile_content) VALUES
-('@_ooye_bojack_horseman:cadence.moe', '!hYnGGlPHlbujVVfktC:cadence.moe', NULL);
+('@_ooye_bojack_horseman:cadence.moe', '!hYnGGlPHlbujVVfktC:cadence.moe', NULL),
+('@_ooye_cadence:cadence.moe', '!BnKuBPCvyfOkhcUjEu:cadence.moe', NULL);
INSERT INTO message_channel (message_id, channel_id) VALUES
('1106366167788044450', '122155380120748034'),
@@ -57,7 +59,9 @@ INSERT INTO message_channel (message_id, channel_id) VALUES
('1207486471489986620', '1160894080998461480'),
('1210387798297682020', '112760669178241024'),
('1273204543739396116', '687028734322147344'),
-('1273743950028607530', '1100319550446252084');
+('1273743950028607530', '1100319550446252084'),
+('1278002262400176128', '1100319550446252084'),
+('1278001833876525057', '1100319550446252084');
INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, reaction_part, source) VALUES
('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', 0, 0, 1),
@@ -94,7 +98,9 @@ INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part
('$OEEK-Wam2FTh6J-6kVnnJ6KnLA_lLRnLTHatKKL62-Y', 'm.room.message', 'm.image', '1207486471489986620', 0, 0, 0),
('$mPSzglkCu-6cZHbYro0RW2u5mHvbH9aXDjO5FCzosc0', 'm.room.message', 'm.text', '1210387798297682020', 0, 0, 1),
('$qmyjr-ISJtnOM5WTWLI0fT7uSlqRLgpyin2d2NCglCU', 'm.room.message', 'm.text', '1273204543739396116', 0, 0, 0),
-('$W1nsDhNIojWrcQOdnOD9RaEvrz2qyZErQoNhPRs1nK4', 'm.room.message', 'm.text', '1273743950028607530', 0, 0, 0);
+('$W1nsDhNIojWrcQOdnOD9RaEvrz2qyZErQoNhPRs1nK4', 'm.room.message', 'm.text', '1273743950028607530', 0, 0, 0),
+('$UTqiL3Zj3FC4qldxRLggN1fhygpKl8sZ7XGY5f9MNbF', 'm.room.message', 'm.text', '1278002262400176128', 0, 0, 1),
+('$aLVZyiC3HlOu-prCSIaXlQl68I8leUdnPFiCwkgn6qM', 'm.room.message', 'm.text', '1278001833876525057', 0, 0, 1);
INSERT INTO file (discord_url, mxc_url) VALUES
('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'),
From a5518e562fda217dc2f898ff90e0b34999402f0f Mon Sep 17 00:00:00 2001
From: Cadence Ember '
+ },
+ event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
+ room_id: "!CzvdIdUQXgUjDVKxeU:cadence.moe"
+ }),
+ {
+ ensureJoined: [],
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "<:hippo:230201364309868544>",
+ avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU",
+ allowed_mentions: {
+ parse: ["users", "roles"]
+ }
+ }]
+ }
+ )
+})
+
test("event2message: animated emojis work", async t => {
t.deepEqual(
await eventToMessage({
From 9e9f4819c71d1fae3e1f32475ec102b0220d6f45 Mon Sep 17 00:00:00 2001
From: Cadence Ember
node
const replacementCode = doc.createElement("code")
diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js
index a802d28..d6a20cd 100644
--- a/m2d/converters/event-to-message.test.js
+++ b/m2d/converters/event-to-message.test.js
@@ -772,6 +772,38 @@ test("event2message: code blocks are uploaded as attachments instead if they con
)
})
+test("event2message: code blocks are uploaded as attachments instead if they contain incompatible backticks (default to txt file extension)", async t => {
+ t.deepEqual(
+ await eventToMessage({
+ type: "m.room.message",
+ sender: "@cadence:cadence.moe",
+ content: {
+ msgtype: "m.text",
+ body: "wrong body",
+ format: "org.matrix.custom.html",
+ formatted_body: 'So if you run code like this
it should print a markdown formatted code block'
+ },
+ event_id: "$pGkWQuGVmrPNByrFELxhzI6MCBgJecr5I2J3z88Gc2s",
+ room_id: "!BpMdOUkWWhFxmTrENV:cadence.moe"
+ }),
+ {
+ ensureJoined: [],
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "So if you run code like this `[inline_code.txt]` it should print a markdown formatted code block",
+ attachments: [{id: "0", filename: "inline_code.txt"}],
+ pendingFiles: [{name: "inline_code.txt", buffer: Buffer.from('System.out.println("```");')}],
+ avatar_url: undefined,
+ allowed_mentions: {
+ parse: ["users", "roles"]
+ }
+ }]
+ }
+ )
+})
+
test("event2message: characters are encoded properly in code blocks", async t => {
t.deepEqual(
await eventToMessage({
diff --git a/test/data.js b/test/data.js
index 058a992..18aaa1a 100644
--- a/test/data.js
+++ b/test/data.js
@@ -450,6 +450,63 @@ module.exports = {
components: []
},
simple_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: [
+ "112767366235959296", "118924814567211009",
+ "204427286542417920", "199995902742626304",
+ "222168467627835392", "238028326281805825",
+ "259806643414499328", "265239342648131584",
+ "271173313575780353", "287733611912757249",
+ "225744901915148298", "305775031223320577",
+ "318243902521868288", "348651574924541953",
+ "349185088157777920", "378402925128712193",
+ "392141548932038658", "393912152173576203",
+ "482860581670486028", "495384759074160642",
+ "638988388740890635", "373336013109461013",
+ "530220455085473813", "454567553738473472",
+ "790724320824655873", "1123518980456452097",
+ "1040735082610167858", "695946570482450442",
+ "1123460940935991296", "849737964090556488"
+ ],
+ 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: "<#1100319550446252084>",
+ 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"
+ },
+ nicked_room_mention: {
type: 0,
tts: false,
timestamp: "2023-07-10T20:04:25.939000+00:00",
From ee266f844a673f47e6328dd1022e5ee18e107de6 Mon Sep 17 00:00:00 2001
From: Cadence Ember System.out.println("```");
You're invited to talk on Matrix. If you don't already have a client this link will help you pick one, and join the conversation. If you already have one, this link will help you join the conversation
`, "m.mentions": {} }]) - t.deepEqual(promotions, []) // TODO: it would be ideal to promote this to reaction_part = 0. this is OK to do because the main message won't have had any reactions yet. + t.deepEqual(promotions, [{ + "column": "reaction_part", + "eventID": "$UTqiL3Zj3FC4qldxRLggN1fhygpKl8sZ7XGY5f9MNbF", + "value": 1, + }, { + "column": "reaction_part", + "nextEvent": true, + }]) t.equal(senderMxid, "@_ooye_cadence:cadence.moe") }) diff --git a/test/ooye-test-data.sql b/test/ooye-test-data.sql index 07be17f..2c23561 100644 --- a/test/ooye-test-data.sql +++ b/test/ooye-test-data.sql @@ -148,6 +148,9 @@ INSERT INTO member_cache (room_id, mxid, displayname, avatar_url, power_level) V ('!kLRqKKUQXcibIMtOpl:cadence.moe', '@test_auto_invite:example.org', NULL, NULL, 0), ('!BpMdOUkWWhFxmTrENV:cadence.moe', '@test_auto_invite:example.org', NULL, NULL, 100); +INSERT INTO reaction (hashed_event_id, message_id, encoded_emoji) VALUES +(5162930312280790092, '1141501302736695317', '%F0%9F%90%88'); + INSERT INTO member_power (mxid, room_id, power_level) VALUES ('@test_auto_invite:example.org', '*', 100);