Skip to content

Commit 86ad4f6

Browse files
authored
Merge pull request #1939 from nextcloud/feat/noid/poll-drafts
feat(polls): Poll drafts
2 parents 3928435 + 703d3bf commit 86ad4f6

13 files changed

+399
-53
lines changed

NextcloudTalk.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@
481481
2C7A12422017872600864818 /* AddParticipantsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C7A12402017872600864818 /* AddParticipantsTableViewController.m */; };
482482
2C7A12432017872600864818 /* AddParticipantsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C7A12412017872600864818 /* AddParticipantsTableViewController.xib */; };
483483
2C7F47AA20289B9600081CC7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2C7F47AC20289B9600081CC7 /* Localizable.strings */; };
484+
2C8001D92D3529AF00DDBADC /* PollDraftsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8001D82D3529AF00DDBADC /* PollDraftsViewController.swift */; };
484485
2C84BCCC29EEB9C6001BA6DA /* CallReactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C84BCCB29EEB9C6001BA6DA /* CallReactionView.swift */; };
485486
2C84BCCE29EEDCE8001BA6DA /* CallReactionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C84BCCD29EEDCE8001BA6DA /* CallReactionView.xib */; };
486487
2C8A2BC9221F094F00DE6D2C /* DirectoryTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C8A2BC8221F094F00DE6D2C /* DirectoryTableViewController.m */; };
@@ -1009,6 +1010,7 @@
10091010
2C7A12402017872600864818 /* AddParticipantsTableViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AddParticipantsTableViewController.m; sourceTree = "<group>"; };
10101011
2C7A12412017872600864818 /* AddParticipantsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AddParticipantsTableViewController.xib; sourceTree = "<group>"; };
10111012
2C7F47AB20289B9600081CC7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
1013+
2C8001D82D3529AF00DDBADC /* PollDraftsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollDraftsViewController.swift; sourceTree = "<group>"; };
10121014
2C84BCCB29EEB9C6001BA6DA /* CallReactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallReactionView.swift; sourceTree = "<group>"; };
10131015
2C84BCCD29EEDCE8001BA6DA /* CallReactionView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CallReactionView.xib; sourceTree = "<group>"; };
10141016
2C8A2BC7221F094F00DE6D2C /* DirectoryTableViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DirectoryTableViewController.h; sourceTree = "<group>"; };
@@ -1408,6 +1410,7 @@
14081410
2C5BFBF92891598900E75118 /* PollResultTableViewCell.swift */,
14091411
2C5BFBFA2891598900E75118 /* PollResultTableViewCell.xib */,
14101412
2C5BFBEE288A947800E75118 /* PollVotingView.swift */,
1413+
2C8001D82D3529AF00DDBADC /* PollDraftsViewController.swift */,
14111414
);
14121415
name = Polls;
14131416
sourceTree = "<group>";
@@ -2904,6 +2907,7 @@
29042907
2CB6ACCA26401D5200D3D641 /* GeoLocationRichObject.m in Sources */,
29052908
2C78EF9C1F826B22008AFA74 /* NCCallController.m in Sources */,
29062909
1F1B50442B9095D100B0F2F4 /* FederatedCapabilities.m in Sources */,
2910+
2C8001D92D3529AF00DDBADC /* PollDraftsViewController.swift in Sources */,
29072911
2C5BFBF628902E0300E75118 /* PollFooterView.swift in Sources */,
29082912
2C4D7D761F30F7B600FF4A0D /* ARDUtilities.m in Sources */,
29092913
1FF4DA7E2C0237D000C1B952 /* DirectoryTableViewCell.swift in Sources */,

NextcloudTalk/BaseChatViewController.swift

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import SwiftUI
1717
UIImagePickerControllerDelegate,
1818
PHPickerViewControllerDelegate,
1919
UINavigationControllerDelegate,
20-
PollCreationViewControllerDelegate,
2120
ShareLocationViewControllerDelegate,
2221
CNContactPickerDelegate,
2322
UIDocumentPickerDelegate,
@@ -884,8 +883,7 @@ import SwiftUI
884883
}
885884

886885
func presentPollCreation() {
887-
let pollCreationVC = PollCreationViewController(style: .insetGrouped)
888-
pollCreationVC.pollCreationDelegate = self
886+
let pollCreationVC = PollCreationViewController(room: room)
889887
self.presentWithNavigation(pollCreationVC, animated: true)
890888
}
891889

@@ -3551,8 +3549,7 @@ import SwiftUI
35513549
// MARK: - ObjectShareMessageTableViewCell
35523550

35533551
public func cellWants(toOpenPoll poll: NCMessageParameter) {
3554-
let pollVC = PollVotingView(style: .insetGrouped)
3555-
pollVC.room = self.room
3552+
let pollVC = PollVotingView(room: room)
35563553
self.presentWithNavigation(pollVC, animated: true)
35573554

35583555
guard let pollId = Int(poll.parameterId) else { return }
@@ -3564,18 +3561,6 @@ import SwiftUI
35643561
}
35653562
}
35663563

3567-
// MARK: - PollCreationViewControllerDelegate
3568-
3569-
func pollCreationViewControllerWantsToCreatePoll(pollCreationViewController: PollCreationViewController, question: String, options: [String], resultMode: NCPollResultMode, maxVotes: Int) {
3570-
NCAPIController.sharedInstance().createPoll(withQuestion: question, options: options, resultMode: resultMode, maxVotes: maxVotes, inRoom: self.room.token, for: self.account) { _, error, _ in
3571-
if error != nil {
3572-
pollCreationViewController.showCreationError()
3573-
} else {
3574-
pollCreationViewController.close()
3575-
}
3576-
}
3577-
}
3578-
35793564
// MARK: - SystemMessageTableViewCellDelegate
35803565

35813566
public func cellWantsToCollapseMessages(with message: NCChatMessage!) {

NextcloudTalk/NCAPIController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef void (^MessageTranslationCompletionBlock)(NSDictionary *translationDict,
5656
typedef void (^MessageReactionCompletionBlock)(NSDictionary *reactionsDict, NSError *error, NSInteger statusCode);
5757

5858
typedef void (^PollCompletionBlock)(NCPoll *poll, NSError *error, NSInteger statusCode);
59+
typedef void (^PollDraftsCompletionBlock)(NSArray *polls, NSError *error, NSInteger statusCode);
5960

6061
typedef void (^SendSignalingMessagesCompletionBlock)(NSError *error);
6162
typedef void (^PullSignalingMessagesCompletionBlock)(NSDictionary *messages, NSError *error);
@@ -204,7 +205,8 @@ extern NSInteger const kReceivedChatMessagesLimit;
204205
- (NSURLSessionDataTask *)getReactions:(NSString *)reaction fromMessage:(NSInteger)messageId inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(MessageReactionCompletionBlock)block;
205206

206207
// Polls Controller
207-
- (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(NSArray *)options resultMode:(NCPollResultMode)resultMode maxVotes:(NSInteger)maxVotes inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
208+
- (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(NSArray *)options resultMode:(NCPollResultMode)resultMode maxVotes:(NSInteger)maxVotes inRoom:(NSString *)token asDraft:(BOOL)asDraft forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
209+
- (NSURLSessionDataTask *)getPollDraftsInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollDraftsCompletionBlock)block;
208210
- (NSURLSessionDataTask *)getPollWithId:(NSInteger)pollId inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
209211
- (NSURLSessionDataTask *)voteOnPollWithId:(NSInteger)pollId inRoom:(NSString *)token withOptions:(NSArray *)options forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
210212
- (NSURLSessionDataTask *)closePollWithId:(NSInteger)pollId inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;

NextcloudTalk/NCAPIController.m

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ - (NSURLSessionDataTask *)getReactions:(NSString *)reaction fromMessage:(NSInteg
15541554

15551555
#pragma mark - Polls Controller
15561556

1557-
- (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(NSArray *)options resultMode:(NCPollResultMode)resultMode maxVotes:(NSInteger)maxVotes inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block
1557+
- (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(NSArray *)options resultMode:(NCPollResultMode)resultMode maxVotes:(NSInteger)maxVotes inRoom:(NSString *)token asDraft:(BOOL)asDraft forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block
15581558
{
15591559
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
15601560
NSString *endpoint = [NSString stringWithFormat:@"poll/%@", encodedToken];
@@ -1563,6 +1563,7 @@ - (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(N
15631563
NSDictionary *parameters = @{@"question" : question,
15641564
@"options" : options,
15651565
@"resultMode" : @(resultMode),
1566+
@"draft" : @(asDraft),
15661567
@"maxVotes" : @(maxVotes)
15671568
};
15681569
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
@@ -1610,6 +1611,31 @@ - (NSURLSessionDataTask *)getPollWithId:(NSInteger)pollId inRoom:(NSString *)tok
16101611
return task;
16111612
}
16121613

1614+
- (NSURLSessionDataTask *)getPollDraftsInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollDraftsCompletionBlock)block
1615+
{
1616+
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
1617+
NSString *endpoint = [NSString stringWithFormat:@"poll/%@/drafts", encodedToken];
1618+
NSInteger pollsAPIVersion = [self pollsAPIVersionForAccount:account];
1619+
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:pollsAPIVersion forAccount:account];
1620+
1621+
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
1622+
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
1623+
NSArray *pollDrafts = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
1624+
if (block) {
1625+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
1626+
block(pollDrafts, nil, httpResponse.statusCode);
1627+
}
1628+
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
1629+
NSInteger statusCode = [self getResponseStatusCode:task.response];
1630+
[self checkResponseStatusCode:statusCode forAccount:account];
1631+
if (block) {
1632+
block(nil, error, statusCode);
1633+
}
1634+
}];
1635+
1636+
return task;
1637+
}
1638+
16131639
- (NSURLSessionDataTask *)voteOnPollWithId:(NSInteger)pollId inRoom:(NSString *)token withOptions:(NSArray *)options forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block
16141640
{
16151641
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];

NextcloudTalk/NCDatabaseManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extern NSString * const kCapabilityChatSummary;
7878
extern NSString * const kCapabilityArchivedConversationsV2;
7979
extern NSString * const kCapabilityCallNotificationState;
8080
extern NSString * const kCapabilityCallForceMute;
81+
extern NSString * const kCapabilityTalkPollsDrafts;
8182

8283
extern NSString * const kNotificationsCapabilityExists;
8384
extern NSString * const kNotificationsCapabilityTestPush;

NextcloudTalk/NCDatabaseManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
NSString * const kCapabilityArchivedConversationsV2 = @"archived-conversations-v2";
8080
NSString * const kCapabilityCallNotificationState = @"call-notification-state-api";
8181
NSString * const kCapabilityForceMute = @"force-mute";
82+
NSString * const kCapabilityTalkPollsDrafts = @"talk-polls-drafts";
8283

8384
NSString * const kNotificationsCapabilityExists = @"exists";
8485
NSString * const kNotificationsCapabilityTestPush = @"test-push";

NextcloudTalk/PlaceholderView.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait" appearance="dark"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -23,7 +23,7 @@
2323
<rect key="frame" x="0.0" y="0.0" width="350" height="350"/>
2424
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2525
<subviews>
26-
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" style="medium" translatesAutoresizingMaskIntoConstraints="NO" id="FB3-Ig-rQB">
26+
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="medium" translatesAutoresizingMaskIntoConstraints="NO" id="FB3-Ig-rQB">
2727
<rect key="frame" x="165" y="175" width="20" height="20"/>
2828
<color key="color" systemColor="placeholderTextColor"/>
2929
</activityIndicatorView>

0 commit comments

Comments
 (0)