Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(polls): Poll drafts #1939

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions NextcloudTalk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
2C7A12422017872600864818 /* AddParticipantsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C7A12402017872600864818 /* AddParticipantsTableViewController.m */; };
2C7A12432017872600864818 /* AddParticipantsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C7A12412017872600864818 /* AddParticipantsTableViewController.xib */; };
2C7F47AA20289B9600081CC7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2C7F47AC20289B9600081CC7 /* Localizable.strings */; };
2C8001D92D3529AF00DDBADC /* PollDraftsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8001D82D3529AF00DDBADC /* PollDraftsViewController.swift */; };
2C84BCCC29EEB9C6001BA6DA /* CallReactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C84BCCB29EEB9C6001BA6DA /* CallReactionView.swift */; };
2C84BCCE29EEDCE8001BA6DA /* CallReactionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C84BCCD29EEDCE8001BA6DA /* CallReactionView.xib */; };
2C8A2BC9221F094F00DE6D2C /* DirectoryTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C8A2BC8221F094F00DE6D2C /* DirectoryTableViewController.m */; };
Expand Down Expand Up @@ -1009,6 +1010,7 @@
2C7A12402017872600864818 /* AddParticipantsTableViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AddParticipantsTableViewController.m; sourceTree = "<group>"; };
2C7A12412017872600864818 /* AddParticipantsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AddParticipantsTableViewController.xib; sourceTree = "<group>"; };
2C7F47AB20289B9600081CC7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
2C8001D82D3529AF00DDBADC /* PollDraftsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollDraftsViewController.swift; sourceTree = "<group>"; };
2C84BCCB29EEB9C6001BA6DA /* CallReactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallReactionView.swift; sourceTree = "<group>"; };
2C84BCCD29EEDCE8001BA6DA /* CallReactionView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CallReactionView.xib; sourceTree = "<group>"; };
2C8A2BC7221F094F00DE6D2C /* DirectoryTableViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DirectoryTableViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1408,6 +1410,7 @@
2C5BFBF92891598900E75118 /* PollResultTableViewCell.swift */,
2C5BFBFA2891598900E75118 /* PollResultTableViewCell.xib */,
2C5BFBEE288A947800E75118 /* PollVotingView.swift */,
2C8001D82D3529AF00DDBADC /* PollDraftsViewController.swift */,
);
name = Polls;
sourceTree = "<group>";
Expand Down Expand Up @@ -2904,6 +2907,7 @@
2CB6ACCA26401D5200D3D641 /* GeoLocationRichObject.m in Sources */,
2C78EF9C1F826B22008AFA74 /* NCCallController.m in Sources */,
1F1B50442B9095D100B0F2F4 /* FederatedCapabilities.m in Sources */,
2C8001D92D3529AF00DDBADC /* PollDraftsViewController.swift in Sources */,
2C5BFBF628902E0300E75118 /* PollFooterView.swift in Sources */,
2C4D7D761F30F7B600FF4A0D /* ARDUtilities.m in Sources */,
1FF4DA7E2C0237D000C1B952 /* DirectoryTableViewCell.swift in Sources */,
Expand Down
19 changes: 2 additions & 17 deletions NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import SwiftUI
UIImagePickerControllerDelegate,
PHPickerViewControllerDelegate,
UINavigationControllerDelegate,
PollCreationViewControllerDelegate,
ShareLocationViewControllerDelegate,
CNContactPickerDelegate,
UIDocumentPickerDelegate,
Expand Down Expand Up @@ -884,8 +883,7 @@ import SwiftUI
}

func presentPollCreation() {
let pollCreationVC = PollCreationViewController(style: .insetGrouped)
pollCreationVC.pollCreationDelegate = self
let pollCreationVC = PollCreationViewController(room: room)
self.presentWithNavigation(pollCreationVC, animated: true)
}

Expand Down Expand Up @@ -3551,8 +3549,7 @@ import SwiftUI
// MARK: - ObjectShareMessageTableViewCell

public func cellWants(toOpenPoll poll: NCMessageParameter) {
let pollVC = PollVotingView(style: .insetGrouped)
pollVC.room = self.room
let pollVC = PollVotingView(room: room)
self.presentWithNavigation(pollVC, animated: true)

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

// MARK: - PollCreationViewControllerDelegate

func pollCreationViewControllerWantsToCreatePoll(pollCreationViewController: PollCreationViewController, question: String, options: [String], resultMode: NCPollResultMode, maxVotes: Int) {
NCAPIController.sharedInstance().createPoll(withQuestion: question, options: options, resultMode: resultMode, maxVotes: maxVotes, inRoom: self.room.token, for: self.account) { _, error, _ in
if error != nil {
pollCreationViewController.showCreationError()
} else {
pollCreationViewController.close()
}
}
}

// MARK: - SystemMessageTableViewCellDelegate

public func cellWantsToCollapseMessages(with message: NCChatMessage!) {
Expand Down
4 changes: 3 additions & 1 deletion NextcloudTalk/NCAPIController.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ typedef void (^MessageTranslationCompletionBlock)(NSDictionary *translationDict,
typedef void (^MessageReactionCompletionBlock)(NSDictionary *reactionsDict, NSError *error, NSInteger statusCode);

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

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

// Polls Controller
- (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(NSArray *)options resultMode:(NCPollResultMode)resultMode maxVotes:(NSInteger)maxVotes inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
- (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;
- (NSURLSessionDataTask *)getPollDraftsInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollDraftsCompletionBlock)block;
- (NSURLSessionDataTask *)getPollWithId:(NSInteger)pollId inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
- (NSURLSessionDataTask *)voteOnPollWithId:(NSInteger)pollId inRoom:(NSString *)token withOptions:(NSArray *)options forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
- (NSURLSessionDataTask *)closePollWithId:(NSInteger)pollId inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block;
Expand Down
28 changes: 27 additions & 1 deletion NextcloudTalk/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ - (NSURLSessionDataTask *)getReactions:(NSString *)reaction fromMessage:(NSInteg

#pragma mark - Polls Controller

- (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(NSArray *)options resultMode:(NCPollResultMode)resultMode maxVotes:(NSInteger)maxVotes inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block
- (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
{
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *endpoint = [NSString stringWithFormat:@"poll/%@", encodedToken];
Expand All @@ -1563,6 +1563,7 @@ - (NSURLSessionDataTask *)createPollWithQuestion:(NSString *)question options:(N
NSDictionary *parameters = @{@"question" : question,
@"options" : options,
@"resultMode" : @(resultMode),
@"draft" : @(asDraft),
@"maxVotes" : @(maxVotes)
};
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
Expand Down Expand Up @@ -1610,6 +1611,31 @@ - (NSURLSessionDataTask *)getPollWithId:(NSInteger)pollId inRoom:(NSString *)tok
return task;
}

- (NSURLSessionDataTask *)getPollDraftsInRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(PollDraftsCompletionBlock)block
{
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *endpoint = [NSString stringWithFormat:@"poll/%@/drafts", encodedToken];
NSInteger pollsAPIVersion = [self pollsAPIVersionForAccount:account];
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:pollsAPIVersion forAccount:account];

NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *pollDrafts = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
if (block) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
block(pollDrafts, nil, httpResponse.statusCode);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];
[self checkResponseStatusCode:statusCode forAccount:account];
if (block) {
block(nil, error, statusCode);
}
}];

return task;
}

- (NSURLSessionDataTask *)voteOnPollWithId:(NSInteger)pollId inRoom:(NSString *)token withOptions:(NSArray *)options forAccount:(TalkAccount *)account withCompletionBlock:(PollCompletionBlock)block
{
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCDatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ extern NSString * const kCapabilityChatSummary;
extern NSString * const kCapabilityArchivedConversationsV2;
extern NSString * const kCapabilityCallNotificationState;
extern NSString * const kCapabilityCallForceMute;
extern NSString * const kCapabilityTalkPollsDrafts;

extern NSString * const kNotificationsCapabilityExists;
extern NSString * const kNotificationsCapabilityTestPush;
Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
NSString * const kCapabilityArchivedConversationsV2 = @"archived-conversations-v2";
NSString * const kCapabilityCallNotificationState = @"call-notification-state-api";
NSString * const kCapabilityForceMute = @"force-mute";
NSString * const kCapabilityTalkPollsDrafts = @"talk-polls-drafts";

NSString * const kNotificationsCapabilityExists = @"exists";
NSString * const kNotificationsCapabilityTestPush = @"test-push";
Expand Down
6 changes: 3 additions & 3 deletions NextcloudTalk/PlaceholderView.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina4_7" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -23,7 +23,7 @@
<rect key="frame" x="0.0" y="0.0" width="350" height="350"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" style="medium" translatesAutoresizingMaskIntoConstraints="NO" id="FB3-Ig-rQB">
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="medium" translatesAutoresizingMaskIntoConstraints="NO" id="FB3-Ig-rQB">
<rect key="frame" x="165" y="175" width="20" height="20"/>
<color key="color" systemColor="placeholderTextColor"/>
</activityIndicatorView>
Expand Down
Loading
Loading