Merge pull request #7206 from vector-im/alfogrillo/poll_decryption_message

Handle decryption errors in polls (PSG-1023)
This commit is contained in:
Alfonso Grillo
2023-01-09 17:20:28 +01:00
committed by GitHub
10 changed files with 52 additions and 5 deletions
@@ -132,7 +132,8 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel
totalAnswerCount: poll.totalAnswerCount,
type: pollKindToTimelinePollType(poll.kind),
maxAllowedSelections: poll.maxAllowedSelections,
hasBeenEdited: poll.hasBeenEdited)
hasBeenEdited: poll.hasBeenEdited,
hasDecryptionError: poll.hasDecryptionError)
}
private func pollKindToTimelinePollType(_ kind: PollKind) -> TimelinePollType {
@@ -35,7 +35,8 @@ class TimelinePollViewModelTests: XCTestCase {
totalAnswerCount: 3,
type: .disclosed,
maxAllowedSelections: 1,
hasBeenEdited: false)
hasBeenEdited: false,
hasDecryptionError: false)
viewModel = TimelinePollViewModel(timelinePollDetails: timelinePoll)
context = viewModel.context
@@ -64,13 +64,15 @@ struct TimelinePollDetails {
var type: TimelinePollType
var maxAllowedSelections: UInt
var hasBeenEdited = true
var hasDecryptionError: Bool
init(question: String, answerOptions: [TimelinePollAnswerOption],
closed: Bool,
totalAnswerCount: UInt,
type: TimelinePollType,
maxAllowedSelections: UInt,
hasBeenEdited: Bool) {
hasBeenEdited: Bool,
hasDecryptionError: Bool) {
self.question = question
self.answerOptions = answerOptions
self.closed = closed
@@ -78,6 +80,7 @@ struct TimelinePollDetails {
self.type = type
self.maxAllowedSelections = maxAllowedSelections
self.hasBeenEdited = hasBeenEdited
self.hasDecryptionError = hasDecryptionError
}
var hasCurrentUserVoted: Bool {
@@ -38,7 +38,8 @@ enum MockTimelinePollScreenState: MockScreenState, CaseIterable {
totalAnswerCount: 20,
type: self == .closedDisclosed || self == .openDisclosed ? .disclosed : .undisclosed,
maxAllowedSelections: 1,
hasBeenEdited: false)
hasBeenEdited: false,
hasDecryptionError: false)
let viewModel = TimelinePollViewModel(timelinePollDetails: poll)
@@ -152,7 +152,8 @@ struct TimelinePollAnswerOptionButton_Previews: PreviewProvider {
totalAnswerCount: 100,
type: type,
maxAllowedSelections: 1,
hasBeenEdited: false)
hasBeenEdited: false,
hasDecryptionError: false)
}
static func buildAnswerOption(text: String = "Test", selected: Bool, winner: Bool = false) -> TimelinePollAnswerOption {
@@ -49,6 +49,7 @@ struct TimelinePollView: View {
.fixedSize(horizontal: false, vertical: true)
Text(totalVotesString)
.lineLimit(2)
.font(theme.fonts.footnote)
.foregroundColor(theme.colors.tertiaryContent)
}
@@ -62,6 +63,10 @@ struct TimelinePollView: View {
private var totalVotesString: String {
let poll = viewModel.viewState.poll
if poll.hasDecryptionError, poll.totalAnswerCount > 0 {
return VectorL10n.pollTimelineDecryptionError
}
if poll.closed {
if poll.totalAnswerCount == 1 {
return VectorL10n.pollTimelineTotalFinalResultsOneVote