Skip to content

Commit

Permalink
element-hq/element-ios/issues/5114 - Added support for unstable poll …
Browse files Browse the repository at this point in the history
…prefixes.
  • Loading branch information
stefanceriu committed Feb 11, 2022
1 parent 30602a2 commit 50a0920
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions MatrixSDK/JSONModels/MXEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,12 @@ FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollAnswers;
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollAnswerId;
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollMaxSelections;
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollKind;

FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollKindDisclosed;
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollKindDisclosedMSC3381;

FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollKindUndisclosed;
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensiblePollKindUndisclosedMSC3381;

// Location
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensibleLocation;
Expand Down
3 changes: 3 additions & 0 deletions MatrixSDK/JSONModels/MXEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@
NSString *const kMXMessageContentKeyExtensiblePollAnswerId = @"id";
NSString *const kMXMessageContentKeyExtensiblePollMaxSelections = @"max_selections";
NSString *const kMXMessageContentKeyExtensiblePollKind = @"kind";

NSString *const kMXMessageContentKeyExtensiblePollKindDisclosedMSC3381 = @"org.matrix.msc3381.poll.disclosed";
NSString *const kMXMessageContentKeyExtensiblePollKindDisclosed = @"m.poll.disclosed";
NSString *const kMXMessageContentKeyExtensiblePollKindUndisclosedMSC3381 = @"org.matrix.msc3381.poll.undisclosed";
NSString *const kMXMessageContentKeyExtensiblePollKindUndisclosed = @"m.poll.undisclosed";

// Location
Expand Down
10 changes: 9 additions & 1 deletion MatrixSDK/Room/Polls/PollBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ struct PollBuilder {

poll.text = pollStartEventContent.question
poll.maxAllowedSelections = max(1, pollStartEventContent.maxSelections.uintValue)
poll.kind = (pollStartEventContent.kind == kMXMessageContentKeyExtensiblePollKindUndisclosed ? .undisclosed : .disclosed)

switch pollStartEventContent.kind {
case kMXMessageContentKeyExtensiblePollKindUndisclosedMSC3381, kMXMessageContentKeyExtensiblePollKindUndisclosed:
poll.kind = .undisclosed
case kMXMessageContentKeyExtensiblePollKindDisclosedMSC3381, kMXMessageContentKeyExtensiblePollKindDisclosed:
poll.kind = .disclosed
default:
poll.kind = .undisclosed
}

var answerOptionIdentifiers = [String]()
poll.answerOptions = pollStartEventContent.answerOptions.prefix(Constants.maxAnswerOptionCount).map { answerOption in
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5114.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for unstable poll prefixes.

0 comments on commit 50a0920

Please sign in to comment.