diff --git a/src/d2m/converters/edit-to-changes.js b/src/d2m/converters/edit-to-changes.js index c615a3f..fe0e790 100644 --- a/src/d2m/converters/edit-to-changes.js +++ b/src/d2m/converters/edit-to-changes.js @@ -32,17 +32,21 @@ function eventIsText(ev) { * @param {import("../../matrix/api")} api simple-as-nails dependency injection for the matrix API */ async function editToChanges(message, guild, api) { - // If it is a user edit, allow deleting old messages (e.g. they might have removed text from an image). - // If it is the system adding a generated embed to a message, don't delete old messages since the system only sends partial data. - // Since an update in August 2024, the system always provides the full data of message updates. I'll leave in the old code since it won't cause problems. - - const isGeneratedEmbed = !("content" in message) - // Figure out what events we will be replacing const roomID = select("channel_room", "room_id", {channel_id: message.channel_id}).pluck().get() assert(roomID) - const oldEventRows = select("event_message", ["event_id", "event_type", "event_subtype", "part", "reaction_part"], {message_id: message.id}).all() + const oldEventRows = select("event_message", ["event_id", "event_type", "event_subtype", "part", "reaction_part", "source"], {message_id: message.id}).all() + + // If it is a user edit, allow deleting old messages (e.g. they might have removed text from an image). + // If it is the system adding a generated embed to a message, don't delete old messages since the system only sends partial data. + // Since an update in August 2024, the system always provides the full data of message updates. + // Now, this code path is only used by generated embeds for messages that were originally sent from Matrix. + + const originallyFromMatrix = oldEventRows.find(r => r.part === 0)?.source === 0 + const isGeneratedEmbed = !("content" in message) || originallyFromMatrix + + // Figure out who to send as /** @type {string?} Null if we don't have a sender in the room, which will happen if it's a webhook's message. The bridge bot will do the edit instead. */ let senderMxid = null @@ -117,6 +121,8 @@ async function editToChanges(message, guild, api) { if (isGeneratedEmbed) { unchangedEvents.push(...eventsToRedact.filter(e => e.old.event_subtype !== "m.notice")) // Move them from eventsToRedact to unchangedEvents. eventsToRedact = eventsToRedact.filter(e => e.old.event_subtype === "m.notice") + unchangedEvents.push(...eventsToReplace.filter(e => e.old.event_subtype !== "m.notice")) // Move them from eventsToReplace to unchangedEvents. + eventsToReplace = eventsToReplace.filter(e => e.old.event_subtype === "m.notice") } // Now, everything in eventsToSend and eventsToRedact is a real change, but everything in eventsToReplace might not have actually changed! diff --git a/src/d2m/event-dispatcher.js b/src/d2m/event-dispatcher.js index 1698317..49352d7 100644 --- a/src/d2m/event-dispatcher.js +++ b/src/d2m/event-dispatcher.js @@ -272,11 +272,6 @@ module.exports = { // Otherwise, if there are embeds, then the system generated URL preview embeds. if (!(typeof data.content === "string" || "embeds" in data)) return - if (data.webhook_id) { - const row = select("webhook", "webhook_id", {webhook_id: data.webhook_id}).pluck().get() - if (row) return // The message was sent by the bridge's own webhook on discord. We don't want to reflect this back, so just drop it. - } - if (dUtils.isEphemeralMessage(data)) return // Ephemeral messages are for the eyes of the receiver only! // Edits need to go through the speedbump as well. If the message is delayed but the edit isn't, we don't have anything to edit from.