forked from cadence/out-of-your-element
Compare commits
No commits in common. "b542a81ee14f894090e6632ce4dddc4f78b80253" and "7afcbfaa06c7e7ada0cdb2fde0b8780354a353e2" have entirely different histories.
b542a81ee1
...
7afcbfaa06
2 changed files with 3 additions and 12 deletions
|
|
@ -25,7 +25,7 @@ async function threadToAnnouncement(parentRoomID, threadRoomID, creatorMxid, thr
|
||||||
if (branchedFromEventID) {
|
if (branchedFromEventID) {
|
||||||
// Need to figure out who sent that event...
|
// Need to figure out who sent that event...
|
||||||
const event = await di.api.getEvent(parentRoomID, branchedFromEventID)
|
const event = await di.api.getEvent(parentRoomID, branchedFromEventID)
|
||||||
suffix = "\n\n[Note: You should talk there, rather than in this newly-created Matrix thread. Any messages sent here will be bridged as replies, which is probably not what you want.]";
|
suffix = "\n\n*[Note: You should talk there, rather than in this newly-created Matrix thread. Any messages sent here will be bridged as replies, which is probably not what you want.]*";
|
||||||
context["m.relates_to"] = {"m.in_reply_to": {event_id: event.event_id}, is_falling_back:false, event_id: event.event_id, rel_type: "m.thread"}
|
context["m.relates_to"] = {"m.in_reply_to": {event_id: event.event_id}, is_falling_back:false, event_id: event.event_id, rel_type: "m.thread"}
|
||||||
if (event.sender && !userRegex.some(rx => event.sender.match(rx))) context["m.mentions"] = {user_ids: [event.sender]}
|
if (event.sender && !userRegex.some(rx => event.sender.match(rx))) context["m.mentions"] = {user_ids: [event.sender]}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -255,20 +255,11 @@ const commands = [{
|
||||||
return api.sendEvent(event.room_id, "m.room.message", {
|
return api.sendEvent(event.room_id, "m.room.message", {
|
||||||
...ctx,
|
...ctx,
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
body: "This command creates a thread on Discord. But you aren't allowed to do this, because if you were a Discord user, you wouldn't have the Create Public Threads permission." // NOTE: Currently, this assumes that all Matrix users have no Discord roles, and makes that „If you were a Discord user...” claim based on that assumption. If Discord permission emulation is gonna happen in the future, this is certainly one among many places that will need to be changed.
|
body: "This command creates a thread on Discord. But you aren't allowed to do this, because if you were a Discord user, you wouldn't have the Create Public Threads permission."
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const relation = event.content["m.relates_to"]
|
await discord.snow.channel.createThreadWithoutMessage(channelID, {type: 11, name: words.slice(1).join(" ")})
|
||||||
let attachedToEvent = relation?.["m.in_reply_to"]?.event_id // By default, attempt to attach the thread to the message to which /thread was replying.
|
|
||||||
if (relation?.rel_type === "m.thread" && relation.is_falling_back) attachedToEvent = event.content["m.relates_to"]?.event_id // If /thread was sent inside a Matrix thread, attempt to attach the Discord thread to the message around which that Matrix thread was based on. But only if we're falling back, ie. the message sent in that thread was a „normal” one, not a reply to some other message inside the thread. If it WAS reply, we preserve the original behavior (attach the thread to the message to which /thread was replying). One slight caveat is that is_falling_back will also be false if it's the 1st message of that thread. In such case, however, m.in_reply_to should (if sent from a spec-compliant client) point towards the message around which that Matrix thread was based on, so the intended behavior is preserved.
|
|
||||||
if (!attachedToEvent) attachedToEvent = event.event_id // If /thread wasn't replying to anything (ie. attachedToEvent was undefined at initial assignment), or if the event was somehow malformed (in such a way that that - one way or another - attachedToEvent ended up being undefined, even if according to the spec it shouldn't), attach the thread to the /thread command-message that created it.
|
|
||||||
|
|
||||||
assert(attachedToEvent)
|
|
||||||
const attachedToMessage = select("event_message", "message_id", {event_id: attachedToEvent}).pluck().get()
|
|
||||||
|
|
||||||
if (attachedToMessage) await discord.snow.channel.createThreadWithMessage(channelID, attachedToMessage, {name: words.slice(1).join(" ")})
|
|
||||||
else await discord.snow.channel.createThreadWithoutMessage(channelID, {type: 11, name: words.slice(1).join(" ")})
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}]
|
}]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue