Fallback text for Matrix poll end events

Right now this doesn't seem to show up on any clients because extensible
events is a total mess, but if you did want to code a client that shows
this fallback without bothering to code real support for polls, you are
easily able to do that. Just pretend the poll end event is a
m.room.message and render it like usual.
This commit is contained in:
Cadence Ember
2026-02-05 01:00:06 +13:00
parent 564d564490
commit b463e1173b
3 changed files with 30 additions and 5 deletions

View File

@@ -113,7 +113,8 @@ async function endPoll(closeMessage) {
return {
username: "Total results including Matrix votes",
avatar_url: `${reg.ooye.bridge_origin}/discord/poll-star-avatar.png`,
content: messageString
content: messageString,
flags: DiscordTypes.MessageFlags.SuppressEmbeds
}
}
}

View File

@@ -16,8 +16,12 @@ function eventCanBeEdited(ev) {
if (ev.old.event_type === "m.room.message" && ev.old.event_subtype !== "m.text" && ev.old.event_subtype !== "m.emote" && ev.old.event_subtype !== "m.notice") {
return false
}
// Discord does not allow stickers to be edited. Poll closures are sent as "edits", but not in a way we care about.
if (ev.old.event_type === "m.sticker" || ev.old.event_type === "org.matrix.msc3381.poll.start") {
// Discord does not allow stickers to be edited.
if (ev.old.event_type === "m.sticker") {
return false
}
// Discord does not allow the data of polls to be edited, they may only be responded to.
if (ev.old.event_type === "org.matrix.msc3381.poll.start" || ev.old.event_type === "org.matrix.msc3381.poll.end") {
return false
}
// Anything else is fair game.

View File

@@ -20,6 +20,8 @@ const mxUtils = sync.require("../../matrix/utils")
const dUtils = sync.require("../../discord/utils")
/** @type {import("./find-mentions")} */
const findMentions = sync.require("./find-mentions")
/** @type {import("../../discord/interactions/poll-responses")} */
const pollResponses = sync.require("../../discord/interactions/poll-responses")
const {reg} = require("../../matrix/read-registration")
/**
@@ -269,7 +271,21 @@ async function messageToEvent(message, guild, options = {}, di) {
}
if (message.type === DiscordTypes.MessageType.PollResult) {
const event_id = select("event_message", "event_id", {message_id: message.message_reference?.message_id}).pluck().get()
const pollMessageID = message.message_reference?.message_id
if (!pollMessageID) return []
const event_id = select("event_message", "event_id", {message_id: pollMessageID}).pluck().get()
const roomID = select("channel_room", "room_id", {channel_id: message.channel_id}).pluck().get()
const pollQuestionText = select("poll", "question_text", {message_id: pollMessageID}).pluck().get()
if (!event_id || !roomID || !pollQuestionText) return [] // drop it if the corresponding poll start was not bridged
const rep = new mxUtils.MatrixStringBuilder()
rep.addLine(`The poll ${pollQuestionText} has closed.`, tag`The poll <a href="https://matrix.to/#/${roomID}/${event_id}">${pollQuestionText}</a> has closed.`)
const {messageString} = pollResponses.getCombinedResults(pollMessageID, true) // poll results have already been double-checked before this point, so these totals will be accurate
rep.addLine(markdown.toHTML(messageString, {discordOnly: true, escapeHTML: false}), markdown.toHTML(messageString, {}))
const {body, formatted_body} = rep.get()
return [{
$type: "org.matrix.msc3381.poll.end",
"m.relates_to": {
@@ -277,7 +293,11 @@ async function messageToEvent(message, guild, options = {}, di) {
event_id
},
"org.matrix.msc3381.poll.end": {},
body: "This poll has ended.",
"org.matrix.msc1767.text": body,
"org.matrix.msc1767.html": formatted_body,
body: body,
format: "org.matrix.custom.html",
formatted_body: formatted_body,
msgtype: "m.text"
}]
}