diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js index b3938d1..9ff810b 100644 --- a/m2d/converters/event-to-message.js +++ b/m2d/converters/event-to-message.js @@ -348,7 +348,7 @@ async function eventToMessage(event, guild, di) { const repliedToContent = repliedToEvent.content.formatted_body || repliedToEvent.content.body const contentPreviewChunks = chunk( repliedToContent.replace(/.*<\/mx-reply>/, "") // Remove everything before replies, so just use the actual message body - .replace(/.*?<\/blockquote>/, "") // If the message starts with a blockquote, don't count it and use the message body afterwards + .replace(/
.*?<\/blockquote>/, "") // If the message starts with a blockquote, don't count it and use the message body afterwards .replace(/(?:\n|
)+/g, " ") // Should all be on one line .replace(/]*data-mx-spoiler\b[^>]*>.*?<\/span>/g, "[spoiler]") // Good enough method of removing spoiler content. (I don't want to break out the HTML parser unless I have to.) .replace(/<[^>]+>/g, ""), 50) // Completely strip all other formatting. diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index a65f747..e11cb8b 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -726,6 +726,91 @@ test("event2message: should avoid using blockquote contents as reply preview in ) }) +test("event2message: should include a reply preview when message ends with a blockquote", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "> <@_ooye_cookie:cadence.moe> https://tootsuite.net/Warp-Gate2.gif\n> tanget: @ monster spawner\n> \n> **https://tootsuite.net/Warp-Gate2.gif**\n\naichmophobia", + format: "org.matrix.custom.html", + formatted_body: "
In reply to @_ooye_cookie:cadence.moe
https://tootsuite.net/Warp-Gate2.gif
tanget: @ monster spawner
https://tootsuite.net/Warp-Gate2.gif
aichmophobia", + "m.relates_to": { + "m.in_reply_to": { + event_id: "$uXM2I6w-XMtim14-OSZ_8Z2uQ6MDAZLT37eYIiEU6KQ" + } + } + }, + event_id: "$n6sg1X9rLeMzCYufJTRvaLzFeLQ-oEXjCWkHtRxcem4", + room_id: "!fGgIymcYWOqjbSRUdV:cadence.moe" + }, data.guild.general, { + api: { + getEvent: mockGetEvent(t, "!fGgIymcYWOqjbSRUdV:cadence.moe", "$uXM2I6w-XMtim14-OSZ_8Z2uQ6MDAZLT37eYIiEU6KQ", { + type: 'm.room.message', + sender: '@_ooye_cookie:cadence.moe', + content: { + 'm.mentions': {}, + msgtype: 'm.text', + body: 'https://tootsuite.net/Warp-Gate2.gif\n' + + '\n' + + '**https://tootsuite.net/Warp-Gate2.gif**', + format: 'org.matrix.custom.html', + formatted_body: 'https://tootsuite.net/Warp-Gate2.gif
https://tootsuite.net/Warp-Gate2.gif
' + }, + unsigned: { + 'm.relations': { + 'm.replace': { + type: 'm.room.message', + room_id: '!fGgIymcYWOqjbSRUdV:cadence.moe', + sender: '@_ooye_cookie:cadence.moe', + content: { + 'm.mentions': {}, + msgtype: 'm.text', + body: '* https://tootsuite.net/Warp-Gate2.gif\n' + + 'tanget: @ monster spawner\n' + + '\n' + + '**https://tootsuite.net/Warp-Gate2.gif**', + format: 'org.matrix.custom.html', + formatted_body: '* https://tootsuite.net/Warp-Gate2.gif
tanget: @ monster spawner
https://tootsuite.net/Warp-Gate2.gif
', + 'm.new_content': { + 'm.mentions': {}, + msgtype: 'm.text', + body: 'https://tootsuite.net/Warp-Gate2.gif\n' + + 'tanget: @ monster spawner\n' + + '\n' + + '**https://tootsuite.net/Warp-Gate2.gif**', + format: 'org.matrix.custom.html', + formatted_body: 'https://tootsuite.net/Warp-Gate2.gif
tanget: @ monster spawner
https://tootsuite.net/Warp-Gate2.gif
' + }, + 'm.relates_to': { + rel_type: 'm.replace', + event_id: '$uXM2I6w-XMtim14-OSZ_8Z2uQ6MDAZLT37eYIiEU6KQ' + } + }, + event_id: '$onCj1MucuYz6-dFr30jcnnjSEDq50ouyEbRId1wtAa8', + user_id: '@_ooye_cookie:cadence.moe', + } + } + }, + user_id: '@_ooye_cookie:cadence.moe', + }) + } + }), + { + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "> <:L1:1144820033948762203><:L2:1144820084079087647>Ⓜ️**_ooye_cookie**:" + + "\n> https://tootsuite.net/Warp-Gate2.gif tanget: @..." + + "\naichmophobia", + avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU" + }] + } + ) +}) + test("event2message: editing a rich reply to a sim user", async t => { const eventsFetched = [] t.deepEqual(