-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
element-hq/element-ios/issues/5114 - Added poll event methods, poll a…
…ggregator and model builder
- Loading branch information
1 parent
8093a86
commit 82136ea
Showing
19 changed files
with
1,358 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
MatrixSDK/JSONModels/Event/Content/MXEventContentPollStart.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Copyright 2021 The Matrix.org Foundation C.I.C | ||
// | ||
// 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. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "MXJSONModel.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface MXEventContentPollStartAnswerOption: MXJSONModel | ||
|
||
@property (nonatomic, readonly) NSString *uuid; | ||
|
||
@property (nonatomic, readonly) NSString *text; | ||
|
||
- (instancetype)initWithUUID:(NSString *)uuid | ||
text:(NSString *)text; | ||
|
||
@end | ||
|
||
@interface MXEventContentPollStart : MXJSONModel | ||
|
||
@property (nonatomic, readonly) NSString *question; | ||
|
||
@property (nonatomic, readonly) NSString *kind; | ||
|
||
@property (nonatomic, readonly) NSNumber *maxSelections; | ||
|
||
@property (nonatomic, readonly) NSArray<MXEventContentPollStartAnswerOption *> *answerOptions; | ||
|
||
- (instancetype)initWithQuestion:(NSString *)question | ||
kind:(NSString *)kind | ||
maxSelections:(NSNumber *)maxSelections | ||
answerOptions:(NSArray<MXEventContentPollStartAnswerOption *> *)answerOptions; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
110 changes: 110 additions & 0 deletions
110
MatrixSDK/JSONModels/Event/Content/MXEventContentPollStart.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// Copyright 2021 The Matrix.org Foundation C.I.C | ||
// | ||
// 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. | ||
// | ||
|
||
#import "MXEventContentPollStart.h" | ||
#import "MXEvent.h" | ||
|
||
@implementation MXEventContentPollStart | ||
|
||
- (instancetype)initWithQuestion:(NSString *)question | ||
kind:(NSString *)kind | ||
maxSelections:(NSNumber *)maxSelections | ||
answerOptions:(NSArray<MXEventContentPollStartAnswerOption *> *)answerOptions | ||
{ | ||
if (self = [super init]) { | ||
_question = question; | ||
_kind = kind; | ||
_maxSelections = maxSelections; | ||
_answerOptions = answerOptions; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
+ (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary | ||
{ | ||
NSDictionary *content = JSONDictionary[kMXMessageContentKeyExtensiblePollStart]; | ||
|
||
NSString *question, *kind; | ||
MXJSONModelSetString(question, content[kMXMessageContentKeyExtensiblePollQuestion]); | ||
MXJSONModelSetString(kind, content[kMXMessageContentKeyExtensiblePollKind]); | ||
|
||
NSNumber *maxSelections; | ||
MXJSONModelSetNumber(maxSelections, content[kMXMessageContentKeyExtensiblePollMaxSelections]); | ||
|
||
NSArray<MXEventContentPollStartAnswerOption *> *answerOptions = [MXEventContentPollStartAnswerOption modelsFromJSON:content[kMXMessageContentKeyExtensiblePollAnswers]]; | ||
|
||
return [[MXEventContentPollStart alloc] initWithQuestion:question | ||
kind:kind | ||
maxSelections:maxSelections | ||
answerOptions:answerOptions]; | ||
} | ||
|
||
- (NSDictionary *)JSONDictionary | ||
{ | ||
NSMutableDictionary *content = [NSMutableDictionary dictionary]; | ||
|
||
content[kMXMessageContentKeyExtensiblePollQuestion] = self.question; | ||
content[kMXMessageContentKeyExtensiblePollKind] = self.kind; | ||
content[kMXMessageContentKeyExtensiblePollMaxSelections] = self.maxSelections; | ||
|
||
NSMutableArray *answerOptions = [NSMutableArray arrayWithCapacity:self.answerOptions.count]; | ||
for (MXEventContentPollStartAnswerOption *answerOption in self.answerOptions) | ||
{ | ||
[answerOptions addObject:answerOption.JSONDictionary]; | ||
} | ||
|
||
content[kMXMessageContentKeyExtensiblePollAnswers] = answerOptions; | ||
|
||
return @{kMXMessageContentKeyExtensiblePollStart: content}; | ||
} | ||
|
||
@end | ||
|
||
|
||
@implementation MXEventContentPollStartAnswerOption | ||
|
||
- (instancetype)initWithUUID:(NSString *)uuid text:(NSString *)text | ||
{ | ||
if (self = [super init]) | ||
{ | ||
_uuid = uuid; | ||
_text = text; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
+ (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary | ||
{ | ||
NSString *uuid, *text; | ||
MXJSONModelSetString(uuid, JSONDictionary[kMXMessageContentKeyExtensiblePollAnswerId]); | ||
MXJSONModelSetString(text, JSONDictionary[kMXMessageContentKeyExtensibleText]); | ||
|
||
return [[MXEventContentPollStartAnswerOption alloc] initWithUUID:uuid text:text]; | ||
} | ||
|
||
- (NSDictionary *)JSONDictionary | ||
{ | ||
NSMutableDictionary *JSONDictionary = [NSMutableDictionary dictionary]; | ||
|
||
JSONDictionary[kMXMessageContentKeyExtensiblePollAnswerId] = self.uuid; | ||
JSONDictionary[kMXMessageContentKeyExtensibleText] = self.text; | ||
|
||
return JSONDictionary; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.