Skip to content

Commit

Permalink
Merge pull request #7206 from vector-im/alfogrillo/poll_decryption_me…
Browse files Browse the repository at this point in the history
…ssage

Handle decryption errors in polls (PSG-1023)
  • Loading branch information
Alfonso Grillo authored Jan 9, 2023
2 parents b1b2a4b + 6df8c7d commit 7537ecd
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,8 @@ Tap the + to start adding people.";

"poll_timeline_not_closed_subtitle" = "Please try again";

"poll_timeline_decryption_error" = "Due to decryption errors, some votes may not be counted";

// MARK: - Location sharing

"location_sharing_title" = "Location";
Expand Down
28 changes: 28 additions & 0 deletions Riot/Categories/Sequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

extension Sequence {
func group<GroupID: Hashable>(by keyPath: KeyPath<Element, GroupID>) -> [GroupID: [Element]] {
var result: [GroupID: [Element]] = .init()

for item in self {
let groupId = item[keyPath: keyPath]
result[groupId] = (result[groupId] ?? []) + [item]
}

return result
}
}
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4839,6 +4839,10 @@ public class VectorL10n: NSObject {
public static var pollEditFormUpdateFailureTitle: String {
return VectorL10n.tr("Vector", "poll_edit_form_update_failure_title")
}
/// Due to decryption errors, some votes may not be counted
public static var pollTimelineDecryptionError: String {
return VectorL10n.tr("Vector", "poll_timeline_decryption_error")
}
/// Please try again
public static var pollTimelineNotClosedSubtitle: String {
return VectorL10n.tr("Vector", "poll_timeline_not_closed_subtitle")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ 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
self.totalAnswerCount = totalAnswerCount
self.type = type
self.maxAllowedSelections = maxAllowedSelections
self.hasBeenEdited = hasBeenEdited
self.hasDecryptionError = hasDecryptionError
}

var hasCurrentUserVoted: Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct TimelinePollView: View {
.fixedSize(horizontal: false, vertical: true)

Text(totalVotesString)
.lineLimit(2)
.font(theme.fonts.footnote)
.foregroundColor(theme.colors.tertiaryContent)
}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7206.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Polls: show decryption errors in timeline during aggregations.

0 comments on commit 7537ecd

Please sign in to comment.