diff --git a/src/d2m/converters/message-to-event.js b/src/d2m/converters/message-to-event.js index a8e5a6b..5af7487 100644 --- a/src/d2m/converters/message-to-event.js +++ b/src/d2m/converters/message-to-event.js @@ -34,7 +34,6 @@ function getDiscordParseCallbacks(message, guild, useHTML) { const mxid = select("sim", "mxid", {user_id: node.id}).pluck().get() const interaction = message.interaction_metadata || message.interaction const username = message.mentions.find(ment => ment.id === node.id)?.username - || message.referenced_message?.mentions.find(ment => ment.id === node.id)?.username || (interaction?.user.id === node.id ? interaction.user.username : null) || node.id if (mxid && useHTML) { @@ -492,11 +491,19 @@ async function messageToEvent(message, guild, options = {}, di) { } else { // repliedToUnknownEvent // This reply can't point to the Matrix event because it isn't bridged, we need to indicate this. assert(message.referenced_message) - const dateDisplay = dUtils.howOldUnbridgedMessage(message.referenced_message.timestamp, message.timestamp) - html = `
In reply to ${dateDisplay} from ${repliedToDisplayName}:` + const dateDifference = new Date(message.timestamp).getTime() - new Date(message.referenced_message.timestamp).getTime() + const oneHour = 60 * 60 * 1000 + if (dateDifference < oneHour) { + var dateDisplay = "n" + } else if (dateDifference < 25 * oneHour) { + var dateDisplay = ` ${Math.floor(dateDifference / oneHour)}-hour-old` + } else { + var dateDisplay = ` ${Math.round(dateDifference / (24 * oneHour))}-day-old` + } + html = `
In reply to a${dateDisplay} unbridged message from ${repliedToDisplayName}:` + `
${repliedToHtml}
` + html - body = (`In reply to ${dateDisplay}:\n${repliedToDisplayName}: ` + body = (`In reply to a${dateDisplay} unbridged message:\n${repliedToDisplayName}: ` + repliedToBody).split("\n").map(line => "> " + line).join("\n") + "\n\n" + body } diff --git a/src/d2m/converters/message-to-event.test.js b/src/d2m/converters/message-to-event.test.js index fc933e3..89c881e 100644 --- a/src/d2m/converters/message-to-event.test.js +++ b/src/d2m/converters/message-to-event.test.js @@ -532,43 +532,6 @@ test("message2event: simple reply to matrix user, reply fallbacks disabled", asy }]) }) -test("message2event: reply to matrix user with mention", async t => { - const events = await messageToEvent(data.message.reply_to_matrix_user_mention, data.guild.general, {}, { - api: { - getEvent: mockGetEvent(t, "!kLRqKKUQXcibIMtOpl:cadence.moe", "$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk", { - type: "m.room.message", - content: { - msgtype: "m.text", - body: "@_ooye_extremity:cadence.moe you owe me $30", - format: "org.matrix.custom.html", - formatted_body: "@_ooye_extremity:cadence.moe you owe me $30" - }, - sender: "@cadence:cadence.moe" - }) - } - }) - t.deepEqual(events, [{ - $type: "m.room.message", - "m.relates_to": { - "m.in_reply_to": { - event_id: "$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk" - } - }, - "m.mentions": { - user_ids: [ - "@cadence:cadence.moe" - ] - }, - msgtype: "m.text", - body: "> okay 🤍 yay 🤍: @extremity: you owe me $30\n\nkys", - format: "org.matrix.custom.html", - formatted_body: - '
In reply to okay 🤍 yay 🤍' - + '
@extremity you owe me $30
' - + 'kys' - }]) -}) - test("message2event: reply with a video", async t => { const events = await messageToEvent(data.message.reply_with_video, data.guild.general, { api: { diff --git a/src/discord/utils.js b/src/discord/utils.js index 963f0b8..dea05ae 100644 --- a/src/discord/utils.js +++ b/src/discord/utils.js @@ -136,24 +136,6 @@ function getPublicUrlForCdn(url) { return `${reg.ooye.bridge_origin}/download/discord${match[1]}/${match[2]}/${match[3]}/${match[4]}` } -/** - * @param {string} oldTimestamp - * @param {string} newTimestamp - * @returns {string} "a x-day-old unbridged message" - */ -function howOldUnbridgedMessage(oldTimestamp, newTimestamp) { - const dateDifference = new Date(newTimestamp).getTime() - new Date(oldTimestamp).getTime() - const oneHour = 60 * 60 * 1000 - if (dateDifference < oneHour) { - return "an unbridged message" - } else if (dateDifference < 25 * oneHour) { - var dateDisplay = `a ${Math.floor(dateDifference / oneHour)}-hour-old unbridged message` - } else { - var dateDisplay = `a ${Math.round(dateDifference / (24 * oneHour))}-day-old unbridged message` - } - return dateDisplay -} - module.exports.getPermissions = getPermissions module.exports.hasPermission = hasPermission module.exports.hasSomePermissions = hasSomePermissions @@ -163,4 +145,3 @@ module.exports.isEphemeralMessage = isEphemeralMessage module.exports.snowflakeToTimestampExact = snowflakeToTimestampExact module.exports.timestampToSnowflakeInexact = timestampToSnowflakeInexact module.exports.getPublicUrlForCdn = getPublicUrlForCdn -module.exports.howOldUnbridgedMessage = howOldUnbridgedMessage diff --git a/test/data.js b/test/data.js index f460f88..aba31d3 100644 --- a/test/data.js +++ b/test/data.js @@ -1691,95 +1691,6 @@ module.exports = { attachments: [], guild_id: "112760669178241024" }, - reply_to_matrix_user_mention: { - type: 19, - content: "kys", - mentions: [], - mention_roles: [], - attachments: [], - embeds: [], - timestamp: "2025-08-04T05:31:26.506000+00:00", - edited_timestamp: null, - flags: 0, - components: [], - id: "1401799674192723998", - channel_id: "112760669178241024", - author: { - id: "114147806469554185", - username: "extremity", - avatar: "e0394d500407a8fa93774e1835b8b03a", - discriminator: "0", - public_flags: 0, - flags: 0, - banner: null, - accent_color: null, - global_name: "Extremity", - avatar_decoration_data: null, - collectibles: null, - display_name_styles: null, - banner_color: null, - clan: null, - primary_guild: null - }, - pinned: false, - mention_everyone: false, - tts: false, - message_reference: { - type: 0, - channel_id: "112760669178241024", - message_id: "1401760355339862066", - guild_id: "112760669178241024" - }, - referenced_message: { - type: 0, - content: "<@114147806469554185> you owe me $30", - mentions: [ - { - id: "114147806469554185", - username: "extremity", - avatar: "e0394d500407a8fa93774e1835b8b03a", - discriminator: "0", - public_flags: 0, - flags: 0, - banner: null, - accent_color: null, - global_name: "Extremity", - avatar_decoration_data: null, - collectibles: null, - display_name_styles: null, - banner_color: null, - clan: null, - primary_guild: null - } - ], - mention_roles: [], - attachments: [], - embeds: [], - timestamp: "2025-08-04T02:55:12.161000+00:00", - edited_timestamp: null, - flags: 0, - components: [], - id: "1401760355339862066", - channel_id: "112760669178241024", - author: { - id: "1152700216189911081", - username: "okay 🤍 yay 🤍", - avatar: "90bc1d6912252d4fa9f92a2f5f6d347b", - 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: "1152700216189911081" - } - }, reply_with_video: { id: "1197621094983676007", type: 19, diff --git a/test/ooye-test-data.sql b/test/ooye-test-data.sql index faca448..4acff5e 100644 --- a/test/ooye-test-data.sql +++ b/test/ooye-test-data.sql @@ -72,8 +72,7 @@ INSERT INTO message_channel (message_id, channel_id) VALUES ('1191567971970191490', '176333891320283136'), ('1144874214311067708', '687028734322147344'), ('1339000288144658482', '176333891320283136'), -('1381212840957972480', '112760669178241024'), -('1401760355339862066', '112760669178241024'); +('1381212840957972480', '112760669178241024'); 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), @@ -116,8 +115,7 @@ INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part ('$tBIT8mO7XTTCgIINyiAIy6M2MSoPAdJenRl_RLyYuaE', 'm.room.message', 'm.text', '1191567971970191490', 0, 0, 1), ('$51gH61p_eJc2RylOdE2lAr4-ogP7dS0WJI62lCFzBvk', 'm.room.message', 'm.text', '1339000288144658482', 0, 0, 0), ('$AfrB8hzXkDMvuoWjSZkDdFYomjInWH7jMBPkwQMN8AI', 'm.room.message', 'm.text', '1381212840957972480', 0, 1, 1), -('$43baKEhJfD-RlsFQi0LB16Zxd8yMqp0HSVL00TDQOqM', 'm.room.message', 'm.image', '1381212840957972480', 1, 0, 1), -('$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk', 'm.room.message', 'm.text', '1401760355339862066', 0, 0, 0); +('$43baKEhJfD-RlsFQi0LB16Zxd8yMqp0HSVL00TDQOqM', 'm.room.message', 'm.image', '1381212840957972480', 1, 0, 1); INSERT INTO file (discord_url, mxc_url) VALUES ('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'),