Fix m->d m.mentions for webhooks
This commit is contained in:
@@ -1051,11 +1051,11 @@ async function eventToMessage(event, guild, channel, di) {
|
|||||||
// Combine requested mentions with detected written mentions to get the full list
|
// Combine requested mentions with detected written mentions to get the full list
|
||||||
if (Array.isArray(event.content["m.mentions"].user_ids)) {
|
if (Array.isArray(event.content["m.mentions"].user_ids)) {
|
||||||
for (const mxid of event.content["m.mentions"].user_ids) {
|
for (const mxid of event.content["m.mentions"].user_ids) {
|
||||||
const user_id = select("sim", "user_id", {mxid}).pluck().get()
|
let user_id = select("sim", "user_id", {mxid}).pluck().get()
|
||||||
if (!user_id) continue
|
if (!user_id) continue // only for discord users
|
||||||
allowedMentionsUsers.push(
|
user_id = select("sim_proxy", "proxy_owner_id", {user_id}).pluck().get() || user_id // convert to sim proxy owner's ID
|
||||||
select("sim_proxy", "proxy_owner_id", {user_id}).pluck().get() || user_id
|
if (!user_id.match(/^[0-9]+$/)) continue // mentioned sim does not have a real discord user ID (i.e. it's a webhook)
|
||||||
)
|
allowedMentionsUsers.push(user_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Specific mentions were requested, so do not parse users
|
// Specific mentions were requested, so do not parse users
|
||||||
|
|||||||
@@ -1711,6 +1711,63 @@ test("event2message: rich reply to a sim user, explicitly disabling mentions in
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("event2message: rich reply to a webhook with m.mentions", async t => {
|
||||||
|
t.deepEqual(
|
||||||
|
await eventToMessage({
|
||||||
|
"type": "m.room.message",
|
||||||
|
"sender": "@cadence:cadence.moe",
|
||||||
|
"content": {
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "> <@_ooye_webhook_spidey_bot:cadence.moe:cadence.moe> Slow news day.\n\nTesting this reply, ignore",
|
||||||
|
"format": "org.matrix.custom.html",
|
||||||
|
"formatted_body": "<mx-reply><blockquote><a href=\"https://matrix.to/#/!fGgIymcYWOqjbSRUdV:cadence.moe/$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04?via=cadence.moe&via=feather.onl\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_webhook_spidey_bot:cadence.moe:cadence.moe\">@_ooye_webhook_spidey_bot:cadence.moe:cadence.moe</a><br>Slow news day.</blockquote></mx-reply>Testing this reply, ignore",
|
||||||
|
"m.relates_to": {
|
||||||
|
"m.in_reply_to": {
|
||||||
|
"event_id": "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"m.mentions": {
|
||||||
|
user_ids: ["@_ooye_webhook_spidey_bot:cadence.moe"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"origin_server_ts": 1693029683016,
|
||||||
|
"unsigned": {
|
||||||
|
"age": 91,
|
||||||
|
"transaction_id": "m1693029682894.510"
|
||||||
|
},
|
||||||
|
"event_id": "$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8",
|
||||||
|
"room_id": "!fGgIymcYWOqjbSRUdV:cadence.moe"
|
||||||
|
}, data.guild.general, data.channel.general, {
|
||||||
|
api: {
|
||||||
|
getEvent: mockGetEvent(t, "!fGgIymcYWOqjbSRUdV:cadence.moe", "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04", {
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "Slow news day."
|
||||||
|
},
|
||||||
|
sender: "@_ooye_webhook_spidey_bot:cadence.moe"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
ensureJoined: [],
|
||||||
|
messagesToDelete: [],
|
||||||
|
messagesToEdit: [],
|
||||||
|
messagesToSend: [{
|
||||||
|
username: "cadence [they]",
|
||||||
|
content: "-# > <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 **@Spidey Bot**:"
|
||||||
|
+ " Slow news day."
|
||||||
|
+ "\nTesting this reply, ignore",
|
||||||
|
avatar_url: "https://bridge.example.org/download/matrix/cadence.moe/azCAhThKTojXSZJRoWwZmhvU?preset=avatar",
|
||||||
|
allowed_mentions: {
|
||||||
|
parse: ["roles"],
|
||||||
|
users: []
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test("event2message: rich reply to a rich reply to a multi-line message should correctly strip reply fallback", async t => {
|
test("event2message: rich reply to a rich reply to a multi-line message should correctly strip reply fallback", async t => {
|
||||||
t.deepEqual(
|
t.deepEqual(
|
||||||
await eventToMessage({
|
await eventToMessage({
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ INSERT INTO sim (user_id, username, sim_name, mxid) VALUES
|
|||||||
('772659086046658620', 'cadence.worm', 'cadence', '@_ooye_cadence:cadence.moe'),
|
('772659086046658620', 'cadence.worm', 'cadence', '@_ooye_cadence:cadence.moe'),
|
||||||
('196188877885538304', 'ampflower', 'ampflower', '@_ooye_ampflower:cadence.moe'),
|
('196188877885538304', 'ampflower', 'ampflower', '@_ooye_ampflower:cadence.moe'),
|
||||||
('1458668878107381800', 'Evil Lillith (she/her)', 'evil_lillith_sheher', '@_ooye_evil_lillith_sheher:cadence.moe'),
|
('1458668878107381800', 'Evil Lillith (she/her)', 'evil_lillith_sheher', '@_ooye_evil_lillith_sheher:cadence.moe'),
|
||||||
('197126718400626689', 'infinidoge1337', 'infinidoge1337', '@_ooye_infinidoge1337:cadence.moe');
|
('197126718400626689', 'infinidoge1337', 'infinidoge1337', '@_ooye_infinidoge1337:cadence.moe'),
|
||||||
|
('webhook_spidey_bot', 'Spidey Bot', 'webhook_spidey_bot', '@_ooye_webhook_spidey_bot:cadence.moe');
|
||||||
|
|
||||||
INSERT INTO sim_member (mxid, room_id, hashed_profile_content) VALUES
|
INSERT INTO sim_member (mxid, room_id, hashed_profile_content) VALUES
|
||||||
('@_ooye_bojack_horseman:cadence.moe', '!hYnGGlPHlbujVVfktC:cadence.moe', NULL),
|
('@_ooye_bojack_horseman:cadence.moe', '!hYnGGlPHlbujVVfktC:cadence.moe', NULL),
|
||||||
|
|||||||
Reference in New Issue
Block a user