Skip to content

Commit

Permalink
element-hq/element-ios/issues/5114 - Allow checking whether a poll ha…
Browse files Browse the repository at this point in the history
…s been edited.
  • Loading branch information
stefanceriu committed Jan 18, 2022
1 parent ce0c6d8 commit 18eaa1f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@
B105CDD7261F54C8006EB204 /* MXSpaceChildContent.h in Headers */ = {isa = PBXBuildFile; fileRef = B105CDD4261F54C8006EB204 /* MXSpaceChildContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
B105CDD8261F54C8006EB204 /* MXSpaceChildContent.m in Sources */ = {isa = PBXBuildFile; fileRef = B105CDD5261F54C8006EB204 /* MXSpaceChildContent.m */; };
B105CDD9261F54C8006EB204 /* MXSpaceChildContent.m in Sources */ = {isa = PBXBuildFile; fileRef = B105CDD5261F54C8006EB204 /* MXSpaceChildContent.m */; };
B10AFB4322A970060092E6AF /* MXEventReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = B10AFB4122A970060092E6AF /* MXEventReplace.h */; };
B10AFB4322A970060092E6AF /* MXEventReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = B10AFB4122A970060092E6AF /* MXEventReplace.h */; settings = {ATTRIBUTES = (Public, ); }; };
B10AFB4422A970060092E6AF /* MXEventReplace.m in Sources */ = {isa = PBXBuildFile; fileRef = B10AFB4222A970060092E6AF /* MXEventReplace.m */; };
B10AFB4722AA8A8E0092E6AF /* MXEventEditsListener.h in Headers */ = {isa = PBXBuildFile; fileRef = B10AFB4522AA8A8D0092E6AF /* MXEventEditsListener.h */; };
B10AFB4822AA8A8E0092E6AF /* MXEventEditsListener.m in Sources */ = {isa = PBXBuildFile; fileRef = B10AFB4622AA8A8D0092E6AF /* MXEventEditsListener.m */; };
Expand Down Expand Up @@ -1085,7 +1085,7 @@
B14EF2F72397E90400758AF0 /* MXRoomEventFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 323F3F9220D3F0C700D26D6A /* MXRoomEventFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EF2F82397E90400758AF0 /* MXUIKitBackgroundModeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 32A9E8221EF4026E0081358A /* MXUIKitBackgroundModeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EF2F92397E90400758AF0 /* MXCrypto_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 325D1C251DFECE0D0070B8BF /* MXCrypto_Private.h */; };
B14EF2FA2397E90400758AF0 /* MXEventReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = B10AFB4122A970060092E6AF /* MXEventReplace.h */; };
B14EF2FA2397E90400758AF0 /* MXEventReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = B10AFB4122A970060092E6AF /* MXEventReplace.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EF2FB2397E90400758AF0 /* MXOlmSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 32E402B721C957D2004E87A6 /* MXOlmSession.h */; settings = {ATTRIBUTES = (Public, ); }; };
B14EF2FC2397E90400758AF0 /* MXAggregatedReactionsUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 32792BD22295A86600F4FC9D /* MXAggregatedReactionsUpdater.h */; };
B14EF2FD2397E90400758AF0 /* MXScanRealmInMemoryProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = B146D4C521A5A44E00D8C2C6 /* MXScanRealmInMemoryProvider.h */; };
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MatrixSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ FOUNDATION_EXPORT NSString *MatrixSDKVersion;
#import "MXEventAnnotationChunk.h"
#import "MXEventAnnotation.h"
#import "MXEventReferenceChunk.h"

#import "MXEventReplace.h"

#import "MXReplyEventParser.h"

Expand Down
18 changes: 15 additions & 3 deletions MatrixSDK/Room/Polls/PollAggregator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class PollAggregator {
private var editEventsListener: Any!

private var events: [MXEvent] = []
private var hasBeenEdited = false

public private(set) var poll: PollProtocol! {
didSet {
Expand Down Expand Up @@ -94,7 +95,12 @@ public class PollAggregator {

self.pollStartEventContent = pollStartEventContent

self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, events: self.events, currentUserIdentifier: self.session.myUserId)
self.hasBeenEdited = (event.unsignedData.relations?.replace != nil)

self.poll = self.pollBuilder.build(pollStartEventContent: pollStartEventContent,
events: events,
currentUserIdentifier: session.myUserId,
hasBeenEdited: hasBeenEdited)

self.reloadPollData()
}
Expand Down Expand Up @@ -130,10 +136,16 @@ public class PollAggregator {

self.events.append(event)

self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, events: self.events, currentUserIdentifier: self.session.myUserId)
self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent,
events: self.events,
currentUserIdentifier: self.session.myUserId,
hasBeenEdited: self.hasBeenEdited)
} as Any

self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, events: self.events, currentUserIdentifier: self.session.myUserId)
self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent,
events: self.events,
currentUserIdentifier: self.session.myUserId,
hasBeenEdited: self.hasBeenEdited)

self.delegate?.pollAggregatorDidEndLoading(self)

Expand Down
3 changes: 2 additions & 1 deletion MatrixSDK/Room/Polls/PollBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import Foundation

struct PollBuilder {
func build(pollStartEventContent: MXEventContentPollStart, events: [MXEvent], currentUserIdentifier: String) -> PollProtocol {
func build(pollStartEventContent: MXEventContentPollStart, events: [MXEvent], currentUserIdentifier: String, hasBeenEdited: Bool = false) -> PollProtocol {

let poll = Poll()
poll.hasBeenEdited = hasBeenEdited

poll.text = pollStartEventContent.question
poll.maxAllowedSelections = max(1, pollStartEventContent.maxSelections.uintValue)
Expand Down
2 changes: 2 additions & 0 deletions MatrixSDK/Room/Polls/PollModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public protocol PollProtocol {
var maxAllowedSelections: UInt { get }
var isClosed: Bool { get }
var totalAnswerCount: UInt { get }
var hasBeenEdited: Bool { get }
}

class PollAnswerOption: PollAnswerOptionProtocol {
Expand All @@ -54,6 +55,7 @@ class Poll: PollProtocol {
var kind: PollKind = .disclosed
var maxAllowedSelections: UInt = 1
var isClosed: Bool = false
var hasBeenEdited: Bool = false

var totalAnswerCount: UInt {
return self.answerOptions.reduce(0) { $0 + $1.count}
Expand Down
1 change: 1 addition & 0 deletions MatrixSDKTests/MXPollAggregatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class MXPollAggregatorTest: XCTestCase {

XCTAssertEqual(self.pollAggregator.poll.text, "Some other question")
XCTAssertEqual(self.pollAggregator.poll.answerOptions.count, 0)
XCTAssertTrue(self.pollAggregator.poll.hasBeenEdited)

expectation.fulfill()
self.pollAggregator.delegate = nil
Expand Down

0 comments on commit 18eaa1f

Please sign in to comment.