m->d: Use Matrix displayname in m/m reply preview

This commit is contained in:
Cadence Ember 2023-10-13 23:05:07 +13:00
parent 67305bb636
commit 480c7a6bd9
2 changed files with 4 additions and 3 deletions

View file

@ -324,11 +324,12 @@ async function eventToMessage(event, guild, di) {
replyLine += `https://discord.com/channels/${guild.id}/${row.channel_id}/${row.message_id} `
}
const sender = repliedToEvent.sender
const senderName = sender.match(/@([^:]*)/)?.[1] || sender
const authorID = select("sim", "user_id", {mxid: repliedToEvent.sender}).pluck().get()
if (authorID) {
replyLine += `<@${authorID}>`
} else {
let senderName = select("member_cache", "displayname", {mxid: repliedToEvent.sender}).pluck().get()
if (!senderName) senderName = sender.match(/@([^:]*)/)?.[1] || sender
replyLine += `Ⓜ️**${senderName}**`
}
// If the event has been edited, the homeserver will include the relation in `unsigned`.

View file

@ -1151,7 +1151,7 @@ test("event2message: rich reply to a matrix user's long message with formatting"
messagesToEdit: [],
messagesToSend: [{
username: "cadence [they]",
content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence**:"
content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence [they]**:"
+ "\n> i should have a little happy test list bold em..."
+ "\n**no you can't!!!**",
avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
@ -1312,7 +1312,7 @@ test("event2message: with layered rich replies, the preview should only be the r
messagesToEdit: [],
messagesToSend: [{
username: "cadence [they]",
content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence**:"
content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence [they]**:"
+ "\n> two"
+ "\nthree",
avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"