diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js index cf51d86..ec84e07 100644 --- a/m2d/converters/event-to-message.js +++ b/m2d/converters/event-to-message.js @@ -390,10 +390,19 @@ async function eventToMessage(event, guild, di) { // Handling mentions of Discord users input = input.replace(/("https:\/\/matrix.to\/#\/(@[^"]+)")>/g, (whole, attributeValue, mxid) => { - if (!utils.eventSenderIsFromDiscord(mxid)) return whole - const userID = select("sim", "user_id", {mxid: mxid}).pluck().get() - if (!userID) return whole - return `${attributeValue} data-user-id="${userID}">` + if (utils.eventSenderIsFromDiscord(mxid)) { + // Handle mention of an OOYE sim user by their mxid + const userID = select("sim", "user_id", {mxid: mxid}).pluck().get() + if (!userID) return whole + return `${attributeValue} data-user-id="${userID}">` + } else { + // Handle mention of a Matrix user by their mxid + // Check if this Matrix user is actually the sim user from another old bridge in the room? + const match = mxid.match(/[^:]*discord[^:]*_([0-9]{6,}):/) // try to match @_discord_123456, @_discordpuppet_123456, etc. + if (match) return `${attributeValue} data-user-id="${match[1]}">` + // Nope, just a real Matrix user. + return whole + } }) // Handling mentions of Discord rooms diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index 40eb83e..6dbe112 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -2211,6 +2211,33 @@ test("event2message: guessed @mentions may join members to mention", async t => t.equal(called, 1, "searchGuildMembers should be called once") }) +test("event2message: guessed @mentions work with other matrix bridge old users", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "extremity#0: zenosia#0717: back me up on this sentiment, if not necessarily the phrasing", + format: "org.matrix.custom.html", + formatted_body: "extremity#0: zenosia#0717: back me up on this sentiment, if not necessarily the phrasing" + }, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + event_id: "$SiXetU9h9Dg-M9Frcw_C6ahnoXZ3QPZe3MVJR5tcB9A" + }), + { + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "<@114147806469554185> <@176943908762006200> back me up on this sentiment, if not necessarily the phrasing", + avatar_url: undefined + }], + ensureJoined: [] // we already think it worked on Matrix side due to the pill, so no need for the OOYE sim user to join the room to indicate success. + } + ) +}) + slow()("event2message: unknown emoji in the end is reuploaded as a sprite sheet", async t => { const messages = await eventToMessage({ type: "m.room.message",