WIP: feature: threads'n'forums #74

Draft
Guzio wants to merge 109 commits from Guzio/out-of-your-element:mergable-fr-fr into main
Showing only changes of commit 5aa13a2a92 - Show all commits

View file

@ -57,7 +57,7 @@ async function bridgeThread(event) {
return true;
}
catch (e){
if (e.message?.includes("50024")){ // see: https://docs.discord.com/developers/topics/opcodes-and-status-codes
if (e.message?.includes("50024")){ //see: https://docs.discord.com/developers/topics/opcodes-and-status-codes
api.sendEvent(event.room_id, "m.room.message", {
body: "Hey, please don't do that! This room is already a thread on Discord - trying to embed threads inside it will not work. The user will just see a regular reply.",
"m.mentions": { "user_ids": [event.sender]},
@ -78,7 +78,7 @@ async function bridgeThread(event) {
/**
* @param {Ty.Event.Outer_M_Room_Message | Ty.Event.Outer_M_Room_Message_File} event
* @returns {Promise<boolean>} true if a forum-thread-room was created
* @returns {Promise<boolean>} whether a forum-thread-room was created
*/
async function handleForums(event) {
if (event.content.body === "/thread") return false; //Let the help be shown normally
@ -91,14 +91,25 @@ async function handleForums(event) {
const name = computeName(event)
let resetNeeded = false
if(channel.flags && channel.flags & DiscordTypes.ChannelFlags.RequireTag){
await discord.snow.channel.updateChannel(channelID, {flags:(channel.flags^DiscordTypes.ChannelFlags.RequireTag)}, "Temporary flag reset, to override tagging requirements for Matrix threads that can't be tagged.")
resetNeeded = true
try {
if(channel.flags && channel.flags & DiscordTypes.ChannelFlags.RequireTag){
await discord.snow.channel.updateChannel(channelID, {flags:(channel.flags^DiscordTypes.ChannelFlags.RequireTag)}, "Temporary override of tagging requirements because Matrix threads that can't be tagged yet.")
resetNeeded = true
}
//@ts-ignore the presence of message:{} and the absence of type:11 - that's intended for threads in Forum channels (*and no, createThreadWithMessage wouldn't work here, either - that one takes an ALREADY EXISTING message ID, whereas this needs a new message)
await discord.snow.channel.createThreadWithoutMessage(channelID, {name: name.name, message:{content:"heyy~"}})
if (!name.truncated) api.redactEvent(event.room_id, event.event_id) //Don't destroy people's texts - only remove if no truncation is guaranteed.
if (resetNeeded) discord.snow.channel.updateChannel(channelID, {flags:channel.flags}, "Restoring flags to their original state.")
}
catch (e){
if (e.message?.includes("50013")){
api.sendEvent(event.room_id, "m.room.message", {
body: "You can't create threads in this forum right now! This forum is configured to require tags on post (Matrix users can't yet use tags yet), and OOYE doesn't have the permission to edit this channel on Discord (needed to bypass the requirement of tags). Unless this is intentional (see room description - the admins may have left a note), please ask someone on the Discord side to either grant OOYE the necessary permissions, or to remove tagging requirements.",
msgtype: "m.text"
})
}
else throw e
}
//@ts-ignore the presence of message:{} and the absence of type:11 - that's intended for threads in Forum channels (*and no, createThreadWithMessage wouldn't work here, either - that one takes an ALREADY EXISTING message ID, whereas this needs a new message)
await discord.snow.channel.createThreadWithoutMessage(channelID, {name: name.name, message:{content:"heyy~"}})
if (!name.truncated) api.redactEvent(event.room_id, event.event_id) //Don't destroy people's texts - only remove if no truncation is guaranteed.
if (resetNeeded) discord.snow.channel.updateChannel(channelID, channel, "Restoring flags to their original state.")
return true
}