Skip to content

Commit

Permalink
element-hq/element-ios/issues/5114 - Added poll start even type enum …
Browse files Browse the repository at this point in the history
…value, fixed poll question key path, made aggregator and models public.
  • Loading branch information
stefanceriu committed Nov 19, 2021
1 parent 07db42d commit b8759d6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions MatrixSDK/JSONModels/Event/Content/MXEventContentPollStart.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
NSDictionary *content = JSONDictionary[kMXMessageContentKeyExtensiblePollStart];

NSString *question, *kind;
MXJSONModelSetString(question, content[kMXMessageContentKeyExtensiblePollQuestion]);
MXJSONModelSetString(question, content[kMXMessageContentKeyExtensiblePollQuestion][kMXMessageContentKeyExtensibleText]);
MXJSONModelSetString(kind, content[kMXMessageContentKeyExtensiblePollKind]);

NSNumber *maxSelections;
Expand All @@ -57,7 +57,7 @@ - (NSDictionary *)JSONDictionary
{
NSMutableDictionary *content = [NSMutableDictionary dictionary];

content[kMXMessageContentKeyExtensiblePollQuestion] = self.question;
content[kMXMessageContentKeyExtensiblePollQuestion] = @{kMXMessageContentKeyExtensibleText: self.question};
content[kMXMessageContentKeyExtensiblePollKind] = self.kind;
content[kMXMessageContentKeyExtensiblePollMaxSelections] = self.maxSelections;

Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/JSONModels/MXEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef NS_ENUM(NSInteger, MXEventType)
MXEventTypeSecretStorageDefaultKey,
MXEventTypeTaggedEvents,
MXEventTypeSpaceChild,
MXEventTypePollStart,

// The event is a custom event. Refer to its `MXEventTypeString` version
MXEventTypeCustom = 1000
Expand Down
12 changes: 6 additions & 6 deletions MatrixSDK/Room/Polls/PollAggregator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import Foundation
import Combine

enum PollAggregatorError: Error {
public enum PollAggregatorError: Error {
case invalidPollStartEvent
}

protocol PollAggregatorDelegate: AnyObject {
public protocol PollAggregatorDelegate: AnyObject {
func pollAggregatorDidStartLoading(_ aggregator: PollAggregator)
func pollAggregatorDidEndLoading(_ aggregator: PollAggregator)
func pollAggregator(_ aggregator: PollAggregator, didFailWithError: Error)
Expand All @@ -34,7 +34,7 @@ protocol PollAggregatorDelegate: AnyObject {
I will also listen for `mxRoomDidFlushData` and reload all data to avoid gappy sync problems
*/

class PollAggregator {
public class PollAggregator {

private let session: MXSession
private let room: MXRoom
Expand All @@ -45,19 +45,19 @@ class PollAggregator {
private var eventListener: Any!
private var events: [MXEvent] = []

private(set) var poll: PollProtocol! {
public private(set) var poll: PollProtocol! {
didSet {
delegate?.pollAggregatorDidUpdateData(self)
}
}

var delegate: PollAggregatorDelegate?
public var delegate: PollAggregatorDelegate?

deinit {
room.removeListener(eventListener)
}

init(session: MXSession, room: MXRoom, pollStartEvent: MXEvent) throws {
public init(session: MXSession, room: MXRoom, pollStartEvent: MXEvent) throws {
self.session = session
self.room = room
self.pollStartEvent = pollStartEvent
Expand Down
7 changes: 4 additions & 3 deletions MatrixSDK/Room/Polls/PollModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@

import Foundation

enum PollKind {
public enum PollKind {
case disclosed
case undisclosed
}

protocol PollAnswerOptionProtocol {
public protocol PollAnswerOptionProtocol {
var id: String { get }
var text: String { get }
var count: UInt { get }
var isWinner: Bool { get }
var isCurrentUserSelection: Bool { get }
}

protocol PollProtocol {
public protocol PollProtocol {
var text: String { get }
var answerOptions: [PollAnswerOptionProtocol] { get }
var kind: PollKind { get }
var maxAllowedSelections: UInt { get }
var isClosed: Bool { get }
var totalAnswerCount: UInt { get }
}

class PollAnswerOption: PollAnswerOptionProtocol {
Expand Down
3 changes: 2 additions & 1 deletion MatrixSDK/Utils/MXTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ + (void)initialize
kMXEventTypeStringSecretSend,
kMXEventTypeStringSecretStorageDefaultKey,
kMXEventTypeStringTaggedEvents,
kMXEventTypeStringSpaceChild
kMXEventTypeStringSpaceChild,
kMXEventTypeStringPollStart,
];

NSMutableDictionary *map = [NSMutableDictionary dictionaryWithCapacity:eventTypeMapEnumToString.count];
Expand Down

0 comments on commit b8759d6

Please sign in to comment.