Fix polls in threads
This commit is contained in:
@@ -60,8 +60,7 @@ async function sendMessage(message, channel, guild, row) {
|
|||||||
const detailedResultsMessage = await pollEnd.endPoll(message)
|
const detailedResultsMessage = await pollEnd.endPoll(message)
|
||||||
if (detailedResultsMessage) {
|
if (detailedResultsMessage) {
|
||||||
const threadParent = select("channel_room", "thread_parent", {channel_id: message.channel_id}).pluck().get()
|
const threadParent = select("channel_room", "thread_parent", {channel_id: message.channel_id}).pluck().get()
|
||||||
const channelID = threadParent ? threadParent : message.channel_id
|
const {channelID, threadID} = dUtils.swapThreadID(message.channel_id, threadParent)
|
||||||
const threadID = threadParent ? message.channel_id : undefined
|
|
||||||
sentResultsMessage = await channelWebhook.sendMessageWithWebhook(channelID, detailedResultsMessage, threadID)
|
sentResultsMessage = await channelWebhook.sendMessageWithWebhook(channelID, detailedResultsMessage, threadID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,18 @@ function filterTo(xs, fn) {
|
|||||||
return filtered
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parameters correspond to the columns of the channel_room table.
|
||||||
|
* @param {string} rowChannelID thread ID, OR channel ID if there is no thread
|
||||||
|
* @param {string | null | undefined} rowThreadParent channel ID if there is a thread
|
||||||
|
*/
|
||||||
|
function swapThreadID(rowChannelID, rowThreadParent) {
|
||||||
|
return {
|
||||||
|
channelID: rowThreadParent ? rowThreadParent : rowChannelID,
|
||||||
|
threadID: rowThreadParent ? rowChannelID : undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const supportedPlaintextPreviewExtensions = new Set([
|
const supportedPlaintextPreviewExtensions = new Set([
|
||||||
"4d",
|
"4d",
|
||||||
"abnf",
|
"abnf",
|
||||||
@@ -582,4 +594,5 @@ module.exports.timestampToSnowflakeInexact = timestampToSnowflakeInexact
|
|||||||
module.exports.getPublicUrlForCdn = getPublicUrlForCdn
|
module.exports.getPublicUrlForCdn = getPublicUrlForCdn
|
||||||
module.exports.howOldUnbridgedMessage = howOldUnbridgedMessage
|
module.exports.howOldUnbridgedMessage = howOldUnbridgedMessage
|
||||||
module.exports.filterTo = filterTo
|
module.exports.filterTo = filterTo
|
||||||
|
module.exports.swapThreadID = swapThreadID
|
||||||
module.exports.supportedPlaintextPreviewExtensions = supportedPlaintextPreviewExtensions
|
module.exports.supportedPlaintextPreviewExtensions = supportedPlaintextPreviewExtensions
|
||||||
|
|||||||
+7
-12
@@ -1,18 +1,12 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const Ty = require("../../types")
|
const Ty = require("../../types")
|
||||||
const DiscordTypes = require("discord-api-types/v10")
|
|
||||||
const {Readable} = require("stream")
|
|
||||||
const assert = require("assert").strict
|
const assert = require("assert").strict
|
||||||
const crypto = require("crypto")
|
|
||||||
const passthrough = require("../../passthrough")
|
const passthrough = require("../../passthrough")
|
||||||
const {sync, discord, db, select} = passthrough
|
const {sync, db, select} = passthrough
|
||||||
|
|
||||||
const {reg} = require("../../matrix/read-registration")
|
/** @type {import("../../discord/utils")} */
|
||||||
/** @type {import("../../matrix/api")} */
|
const dUtils = sync.require("../../discord/utils")
|
||||||
const api = sync.require("../../matrix/api")
|
|
||||||
/** @type {import("../../matrix/utils")} */
|
|
||||||
const utils = sync.require("../../matrix/utils")
|
|
||||||
/** @type {import("../converters/poll-components")} */
|
/** @type {import("../converters/poll-components")} */
|
||||||
const pollComponents = sync.require("../converters/poll-components")
|
const pollComponents = sync.require("../converters/poll-components")
|
||||||
/** @type {import("./channel-webhook")} */
|
/** @type {import("./channel-webhook")} */
|
||||||
@@ -33,9 +27,10 @@ async function updateVote(event) {
|
|||||||
|
|
||||||
// If poll was started on Matrix, the Discord version is using components, so we can update that to the current status
|
// If poll was started on Matrix, the Discord version is using components, so we can update that to the current status
|
||||||
if (messageRow.source === 0) {
|
if (messageRow.source === 0) {
|
||||||
const channelID = select("channel_room", "channel_id", {room_id: event.room_id}).pluck().get()
|
const row = select("channel_room", ["channel_id", "thread_parent"], {room_id: event.room_id}).get()
|
||||||
assert(channelID)
|
assert(row)
|
||||||
await webhook.editMessageWithWebhook(channelID, messageID, pollComponents.getPollComponentsFromDatabase(messageID))
|
const {channelID, threadID} = dUtils.swapThreadID(row.channel_id, row.thread_parent)
|
||||||
|
await webhook.editMessageWithWebhook(channelID, messageID, pollComponents.getPollComponentsFromDatabase(messageID), threadID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user