attempt to support THREAD_CREATE but it explodes
This commit is contained in:
parent
08d3f3d804
commit
d666c0aedb
4 changed files with 38 additions and 5 deletions
|
@ -27,11 +27,13 @@ function getDiscordParseCallbacks(message, useHTML) {
|
|||
},
|
||||
/** @param {{id: string, type: "discordChannel"}} node */
|
||||
channel: node => {
|
||||
const {room_id, name, nick} = db.prepare("SELECT room_id, name, nick FROM channel_room WHERE channel_id = ?").get(node.id)
|
||||
if (room_id && useHTML) {
|
||||
return `<a href="https://matrix.to/#/${room_id}">#${nick || name}</a>`
|
||||
const row = db.prepare("SELECT room_id, name, nick FROM channel_room WHERE channel_id = ?").get(node.id)
|
||||
if (!row) {
|
||||
return `<#${node.id}>` // fallback for when this channel is not bridged
|
||||
} else if (useHTML) {
|
||||
return `<a href="https://matrix.to/#/${row.room_id}">#${row.nick || row.name}</a>`
|
||||
} else {
|
||||
return `#${nick || name}`
|
||||
return `#${row.nick || row.name}`
|
||||
}
|
||||
},
|
||||
/** @param {{animated: boolean, name: string, id: string, type: "discordEmoji"}} node */
|
||||
|
|
|
@ -44,6 +44,10 @@ const utils = {
|
|||
eventDispatcher.checkMissedMessages(client, message.d)
|
||||
|
||||
|
||||
} else if (message.t === "THREAD_CREATE") {
|
||||
client.channels.set(message.d.id, message.d)
|
||||
|
||||
|
||||
} else if (message.t === "CHANNEL_UPDATE" || message.t === "THREAD_UPDATE") {
|
||||
client.channels.set(message.d.id, message.d)
|
||||
|
||||
|
@ -81,13 +85,19 @@ const utils = {
|
|||
if (message.t === "CHANNEL_UPDATE") {
|
||||
await eventDispatcher.onChannelOrThreadUpdate(client, message.d, false)
|
||||
|
||||
} else if (message.t === "THREAD_CREATE") {
|
||||
console.log(message)
|
||||
// await eventDispatcher.onThreadCreate(client, message.d)
|
||||
|
||||
} else if (message.t === "THREAD_UPDATE") {
|
||||
await eventDispatcher.onChannelOrThreadUpdate(client, message.d, true)
|
||||
|
||||
} else if (message.t === "MESSAGE_CREATE") {
|
||||
console.log(message)
|
||||
await eventDispatcher.onMessageCreate(client, message.d)
|
||||
|
||||
} else if (message.t === "MESSAGE_UPDATE") {
|
||||
console.log(message)
|
||||
await eventDispatcher.onMessageUpdate(client, message.d)
|
||||
|
||||
} else if (message.t === "MESSAGE_DELETE") {
|
||||
|
|
|
@ -101,7 +101,18 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param {import("./discord-client")} client
|
||||
* @param {import("discord-api-types/v10").APIChannel} thread
|
||||
*/
|
||||
async onThreadCreate(client, thread) {
|
||||
console.log(thread)
|
||||
const parentRoomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").get(thread.parent_id)
|
||||
if (!parentRoomID) return // Not interested in a thread if we aren't interested in its wider channel
|
||||
await createRoom.syncRoom(thread.id)
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {import("./discord-client")} client
|
||||
* @param {import("discord-api-types/v10").GatewayChannelUpdateDispatchData} channelOrThread
|
||||
* @param {boolean} isThread
|
||||
|
|
10
notes.md
10
notes.md
|
@ -9,6 +9,16 @@ A database will be used to store the discord id to matrix event id mapping. Tabl
|
|||
|
||||
There needs to be a way to easily manually trigger something later. For example, it should be easy to manually retry sending a message, or check all members for changes, etc.
|
||||
|
||||
## Discord's gateway when a new thread is created from an existing message:
|
||||
|
||||
1. Regular MESSAGE_CREATE of the message that it's going to branch off in the future. Example ID -6423
|
||||
2. It MESSAGE_UPDATEd the ID -6423 with this whole data: {id:-6423,flags: 32,channel_id:-2084,guild_id:-1727} (ID is the message ID it's branching off, channel ID is the parent channel containing the message ID it's branching off)
|
||||
3. It THREAD_CREATEd and gave us a channel object with type 11 (public thread) and parent ID -2084 and ID -6423.
|
||||
4. It MESSAGE_CREATEd type 21 with blank content and a message reference pointing towards channel -2084 message -6423. (That's the message it branched from in the parent channel.) This MESSAGE_CREATE got ID -4631 (a new ID). Apart from that it's a regular message object.
|
||||
5. Finally, as the first "real" message in that thread (which a user must send to create that thread!) it sent a regular message object with a new message ID and a channel ID of -6423.
|
||||
|
||||
When viewing this thread, it shows the message branched from at the top, and then the first "real" message right underneath, as separate groups.
|
||||
|
||||
## Current manual process for setting up a server
|
||||
|
||||
1. Call createSpace.createSpace(discord.guilds.get(GUILD_ID))
|
||||
|
|
Loading…
Reference in a new issue