Add max selections support for polls (#5726)

This commit is contained in:
svetoslav-sportinno
2026-06-22 14:39:12 +03:00
committed by GitHub
parent 173a927bf8
commit 30e4e6339d
49 changed files with 506 additions and 251 deletions
@@ -494,12 +494,15 @@ final class TimelineProxy: TimelineProxyProtocol {
// MARK: - Polls
func createPoll(question: String, answers: [String],
func createPoll(question: String, answers: [String], maxSelections: Int,
pollKind: Poll.Kind) async -> Result<Void, TimelineProxyError> {
MXLog.info("Creating poll")
do {
try await timeline.createPoll(question: question, answers: answers, maxSelections: 1, pollKind: .init(pollKind: pollKind))
try await timeline.createPoll(question: question,
answers: answers,
maxSelections: UInt8(max(1, min(maxSelections, answers.count))),
pollKind: .init(pollKind: pollKind))
MXLog.info("Finished creating poll")
@@ -513,6 +516,7 @@ final class TimelineProxy: TimelineProxyProtocol {
func editPoll(original eventID: String,
question: String,
answers: [String],
maxSelections: Int,
pollKind: Poll.Kind) async -> Result<Void, TimelineProxyError> {
MXLog.info("Editing poll with eventID: \(eventID)")
@@ -522,7 +526,7 @@ final class TimelineProxy: TimelineProxyProtocol {
try await timeline.edit(eventOrTransactionId: originalEvent.eventOrTransactionId,
newContent: .pollStart(pollData: .init(question: question,
answers: answers,
maxSelections: 1,
maxSelections: UInt8(max(1, min(maxSelections, answers.count))),
pollKind: .init(pollKind: pollKind))))
MXLog.info("Finished editing poll with eventID: \(eventID)")