support threads
This commit is contained in:
		
							parent
							
								
									213bf0a515
								
							
						
					
					
						commit
						0fc8e68f15
					
				
					 9 changed files with 172 additions and 63 deletions
				
			
		| 
						 | 
				
			
			@ -50,10 +50,11 @@ async function withWebhook(channelID, callback) {
 | 
			
		|||
/**
 | 
			
		||||
 * @param {string} channelID
 | 
			
		||||
 * @param {DiscordTypes.RESTPostAPIWebhookWithTokenJSONBody & {files?: {name: string, file: Buffer}[]}} data
 | 
			
		||||
 * @param {string} [threadID]
 | 
			
		||||
 */
 | 
			
		||||
async function sendMessageWithWebhook(channelID, data) {
 | 
			
		||||
async function sendMessageWithWebhook(channelID, data, threadID) {
 | 
			
		||||
   const result = await withWebhook(channelID, async webhook => {
 | 
			
		||||
      return discord.snow.webhook.executeWebhook(webhook.id, webhook.token, data, {wait: true, disableEveryone: true})
 | 
			
		||||
      return discord.snow.webhook.executeWebhook(webhook.id, webhook.token, data, {wait: true, thread_id: threadID, disableEveryone: true})
 | 
			
		||||
   })
 | 
			
		||||
   return result
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,13 @@ const eventToMessage = sync.require("../converters/event-to-message")
 | 
			
		|||
/** @param {import("../../types").Event.Outer<any>} event */
 | 
			
		||||
async function sendEvent(event) {
 | 
			
		||||
   // TODO: we just assume the bridge has already been created
 | 
			
		||||
	const channelID = db.prepare("SELECT channel_id FROM channel_room WHERE room_id = ?").pluck().get(event.room_id)
 | 
			
		||||
	const row = db.prepare("SELECT channel_id, thread_parent FROM channel_room WHERE room_id = ?").get(event.room_id)
 | 
			
		||||
	let channelID = row.channel_id
 | 
			
		||||
	let threadID = undefined
 | 
			
		||||
	if (row.thread_parent) {
 | 
			
		||||
		threadID = channelID
 | 
			
		||||
		channelID = row.thread_parent // it's the thread's parent... get with the times...
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
   // no need to sync the matrix member to the other side. but if I did need to, this is where I'd do it
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +30,7 @@ async function sendEvent(event) {
 | 
			
		|||
	const messageResponses = []
 | 
			
		||||
	let eventPart = 0 // 0 is primary, 1 is supporting
 | 
			
		||||
	for (const message of messages) {
 | 
			
		||||
      const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message)
 | 
			
		||||
      const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message, threadID)
 | 
			
		||||
		db.prepare("INSERT INTO event_message (event_id, event_type, event_subtype, message_id, channel_id, part, source) VALUES (?, ?, ?, ?, ?, ?, 0)").run(event.event_id, event.type, event.content.msgtype || null, messageResponse.id, channelID, eventPart) // source 0 = matrix
 | 
			
		||||
 | 
			
		||||
		eventPart = 1 // TODO: use more intelligent algorithm to determine whether primary or supporting?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue