diff --git a/src/d2m/converters/message-to-event.js b/src/d2m/converters/message-to-event.js
index cf8d4c2d..195bdddb 100644
--- a/src/d2m/converters/message-to-event.js
+++ b/src/d2m/converters/message-to-event.js
@@ -428,6 +428,12 @@ async function messageToEvent(message, guild, options = {}, di) {
return {body, html}
}
+ /**
+ * After converting Discord content to Matrix plaintext and HTML content, post-process the bodies and push the resulting text event
+ * @param {string} body matrix event plaintext body
+ * @param {string} html matrix event HTML body
+ * @param {string} msgtype matrix event msgtype (maybe m.text or m.notice)
+ */
async function addTextEvent(body, html, msgtype) {
// Star * prefix for fallback edits
if (options.includeEditFallbackStar) {
@@ -436,7 +442,7 @@ async function messageToEvent(message, guild, options = {}, di) {
}
const flags = message.flags || 0
- if (flags & 2) {
+ if (flags & DiscordTypes.MessageFlags.IsCrosspost) {
body = `[๐ ${message.author.username}]\n` + body
html = `๐ ${message.author.username}
` + html
}
@@ -508,7 +514,57 @@ async function messageToEvent(message, guild, options = {}, di) {
message.content = "changed the channel name to **" + message.content + "**"
}
+ // Forwarded content appears first
+ if (message.message_reference?.type === DiscordTypes.MessageReferenceType.Forward && message.message_snapshots?.length) {
+ // Forwarded notice
+ const eventID = select("event_message", "event_id", {message_id: message.message_reference.message_id}).pluck().get()
+ const room = select("channel_room", ["room_id", "name", "nick"], {channel_id: message.message_reference.channel_id}).get()
+ const forwardedNotice = new mxUtils.MatrixStringBuilder()
+ if (eventID && room) {
+ const via = await getViaServersMemo(room.room_id)
+ forwardedNotice.addLine(
+ `[๐ Forwarded from #${room.nick || room.name}]`,
+ tag`๐ Forwarded from ${room.nick || room.name}`
+ )
+ } else if (room) {
+ const via = await getViaServersMemo(room.room_id)
+ forwardedNotice.addLine(
+ `[๐ Forwarded from #${room.nick || room.name}]`,
+ tag`๐ Forwarded from ${room.nick || room.name}`
+ )
+ } else {
+ forwardedNotice.addLine(
+ `[๐ Forwarded message]`,
+ tag`๐ Forwarded message`
+ )
+ }
+ // Forwarded content
+ // @ts-ignore
+ const forwardedEvents = await messageToEvent(message.message_snapshots[0].message, guild, {includeReplyFallback: false, includeEditFallbackStar: false}, di)
+
+ // Indent
+ for (const event of forwardedEvents) {
+ if (["m.text", "m.notice"].includes(event.msgtype)) {
+ event.msgtype = "m.notice"
+ event.body = event.body.split("\n").map(l => "ยป " + l).join("\n")
+ event.formatted_body = `
${event.formatted_body}` + } + } + + // Try to merge the forwarded content with the forwarded notice + let {body, formatted_body} = forwardedNotice.get() + if (forwardedEvents.length >= 1 && ["m.text", "m.notice"].includes(forwardedEvents[0].msgtype)) { // Try to merge the forwarded content and the forwarded notice + forwardedNotice.add("\n", "