forked from cadence/out-of-your-element
PK: Fix mentions/replies using UUID
This commit is contained in:
parent
3d87bd9da5
commit
f48c1f3f31
9 changed files with 81 additions and 7 deletions
|
@ -238,6 +238,16 @@ function splitDisplayName(displayName) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Matrix user ID into a Discord user ID for mentioning, where if the user is a PK proxy, it will mention the proxy owner.
|
||||
* @param {string} mxid
|
||||
*/
|
||||
function getUserOrProxyOwnerID(mxid) {
|
||||
const row = from("sim").join("sim_proxy", "user_id", "left").select("user_id", "proxy_owner_id").where({mxid}).get()
|
||||
if (!row) return null
|
||||
return row.proxy_owner_id || row.user_id
|
||||
}
|
||||
|
||||
/**
|
||||
* At the time of this executing, we know what the end of message emojis are, and we know that at least one of them is unknown.
|
||||
* This function will strip them from the content and generate the correct pending file of the sprite sheet.
|
||||
|
@ -444,11 +454,11 @@ async function eventToMessage(event, guild, di) {
|
|||
replyLine += `https://discord.com/channels/${guild.id}/${row.channel_id}/${row.message_id} `
|
||||
}
|
||||
const sender = repliedToEvent.sender
|
||||
const authorID = select("sim", "user_id", {mxid: repliedToEvent.sender}).pluck().get()
|
||||
const authorID = getUserOrProxyOwnerID(sender)
|
||||
if (authorID) {
|
||||
replyLine += `<@${authorID}>`
|
||||
} else {
|
||||
let senderName = select("member_cache", "displayname", {mxid: repliedToEvent.sender}).pluck().get()
|
||||
let senderName = select("member_cache", "displayname", {mxid: sender}).pluck().get()
|
||||
if (!senderName) {
|
||||
const match = sender.match(/@([^:]*)/)
|
||||
assert(match)
|
||||
|
@ -497,7 +507,7 @@ async function eventToMessage(event, guild, di) {
|
|||
mxid = decodeURIComponent(mxid)
|
||||
if (mxUtils.eventSenderIsFromDiscord(mxid)) {
|
||||
// Handle mention of an OOYE sim user by their mxid
|
||||
const userID = select("sim", "user_id", {mxid: mxid}).pluck().get()
|
||||
const userID = getUserOrProxyOwnerID(mxid)
|
||||
if (!userID) return whole
|
||||
return `${attributeValue} data-user-id="${userID}">`
|
||||
} else {
|
||||
|
|
|
@ -1869,7 +1869,6 @@ test("event2message: mentioning discord users works", async t => {
|
|||
)
|
||||
})
|
||||
|
||||
|
||||
test("event2message: mentioning discord users works when URL encoded", async t => {
|
||||
t.deepEqual(
|
||||
await eventToMessage({
|
||||
|
@ -1901,6 +1900,37 @@ test("event2message: mentioning discord users works when URL encoded", async t =
|
|||
)
|
||||
})
|
||||
|
||||
test("event2message: mentioning PK discord users works", async t => {
|
||||
t.deepEqual(
|
||||
await eventToMessage({
|
||||
content: {
|
||||
msgtype: "m.text",
|
||||
body: "wrong body",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `I'm just <a href="https://matrix.to/#/@_ooye__pk_zoego:cadence.moe">Azalea</a> testing mentions`
|
||||
},
|
||||
event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
|
||||
origin_server_ts: 1688301929913,
|
||||
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
|
||||
sender: "@cadence:cadence.moe",
|
||||
type: "m.room.message",
|
||||
unsigned: {
|
||||
age: 405299
|
||||
}
|
||||
}),
|
||||
{
|
||||
ensureJoined: [],
|
||||
messagesToDelete: [],
|
||||
messagesToEdit: [],
|
||||
messagesToSend: [{
|
||||
username: "cadence [they]",
|
||||
content: "I'm just <@196188877885538304> testing mentions",
|
||||
avatar_url: undefined
|
||||
}]
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
test("event2message: mentioning matrix users works", async t => {
|
||||
t.deepEqual(
|
||||
await eventToMessage({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue