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 804a6ecb74 - Show all commits

View file

@ -86,14 +86,19 @@ async function handleForums(event) {
const row = from("channel_room").where({room_id: event.room_id}).select("channel_id").get()
/** @type {string}*/ //@ts-ignore the possibility that it's undefined - get() will return back an undefined if it's fed one (so that's undefined-safe), and createThreadWithoutMessage() won't be reached because "undefined" is neither DiscordTypes.ChannelType.GuildMedia nor DiscordTypes.ChannelType.GuildForum, so the guard clause kicks in.
let channelID = row?.channel_id
const type = discord.channels.get(channelID)?.type
if (type != DiscordTypes.ChannelType.GuildForum && type != DiscordTypes.ChannelType.GuildMedia) return false
const channel = discord.channels.get(channelID)
if (channel?.type != DiscordTypes.ChannelType.GuildForum && channel?.type != DiscordTypes.ChannelType.GuildMedia) return false
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
}
//@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)
console.log(JSON.stringify(discord.channels.get(channelID)))
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
}