Browse Source

new view share (comments)

marinofaggiana 5 năm trước cách đây
mục cha
commit
d522dfbdd9

+ 2 - 2
iOSClient/Library/OCCommunicationLib/OCCommunication.h

@@ -984,9 +984,9 @@ typedef enum {
 
 - (void)putComments:(NSString*)serverPath fileID:(NSString *)fileID message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
-- (void)updateComments:(NSString*)serverPath fileID:(NSString *)fileID commentID:(NSString *)commentID message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
+- (void)updateComments:(NSString*)serverPath fileID:(NSString *)fileID messageID:(NSString *)messageID message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
-- (void)deleteComments:(NSString*)serverPath fileID:(NSString *)fileID commentID:(NSString *)commentID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest ;
+- (void)deleteComments:(NSString*)serverPath fileID:(NSString *)fileID messageID:(NSString *)messageID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest ;
 
 #pragma mark - Third Parts
 

+ 4 - 4
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -3238,9 +3238,9 @@
     }];
 }
 
-- (void)updateComments:(NSString*)serverPath fileID:(NSString *)fileID commentID:(NSString *)commentID message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
+- (void)updateComments:(NSString*)serverPath fileID:(NSString *)fileID messageID:(NSString *)messageID message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
     
-    serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileID, commentID];
+    serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileID, messageID];
     serverPath = [serverPath encodeString:NSUTF8StringEncoding];
     
     OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
@@ -3256,9 +3256,9 @@
     }];
 }
 
-- (void)deleteComments:(NSString*)serverPath fileID:(NSString *)fileID commentID:(NSString *)commentID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
+- (void)deleteComments:(NSString*)serverPath fileID:(NSString *)fileID messageID:(NSString *)messageID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
     
-    serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileID, commentID];
+    serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileID, messageID];
     serverPath = [serverPath encodeString:NSUTF8StringEncoding];
     
     OCWebDAVClient *request = [[OCWebDAVClient alloc] init];

+ 14 - 2
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -1539,8 +1539,20 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     _requestMethod = @"PROPPATCH";
     
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
-    [request setHTTPBody:[[NSString stringWithFormat: @"{\"actorType\":\"users\",\"verb\":\"comment\",\"message\":\"%@\"}",message] dataUsingEncoding:NSUTF8StringEncoding]];
+
+    NSString *body;
+    body = [NSString stringWithFormat: @""
+            "<?xml version=\"1.0\"?>"
+            "<d:propertyupdate xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
+            "<d:set>"
+            "<d:prop>"
+            "<oc:message>%@</oc:message>"
+            "</d:prop>"
+            "</d:set>"
+            "</d:propertyupdate>", message];
+    
+    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
+    [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
     
     OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
     [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];

+ 2 - 2
iOSClient/Networking/OCNetworking.h

@@ -119,8 +119,8 @@
 
 - (void)getCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion;
 - (void)putCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID message:(NSString *)message  completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
-- (void)updateCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID commentID:(NSString *)commentID message:(NSString *)message  completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
-- (void)deleteCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID commentID:(NSString *)commentID completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
+- (void)updateCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID messageID:(NSString *)messageID message:(NSString *)message  completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
+- (void)deleteCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID messageID:(NSString *)messageID completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 
 #pragma mark ===== Third Parts =====
 

+ 4 - 4
iOSClient/Networking/OCNetworking.m

@@ -2799,7 +2799,7 @@
     }];
 }
 
-- (void)updateCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID commentID:(NSString *)commentID message:(NSString *)message  completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
+- (void)updateCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID messageID:(NSString *)messageID message:(NSString *)message  completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -2815,7 +2815,7 @@
     [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
-    [communication updateComments:[NSString stringWithFormat:@"%@%@", tableAccount.url, k_dav] fileID:[[NCUtility sharedInstance] convertLocalFileID:fileID] commentID:commentID message:message onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+    [communication updateComments:[NSString stringWithFormat:@"%@%@", tableAccount.url, k_dav] fileID:[[NCUtility sharedInstance] convertLocalFileID:fileID] messageID:messageID message:message onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
         
         completion(account, nil, 0);
         
@@ -2844,7 +2844,7 @@
     }];
 }
 
-- (void)deleteCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID commentID:(NSString *)commentID completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
+- (void)deleteCommentsWithAccount:(NSString *)account fileID:(NSString *)fileID messageID:(NSString *)messageID completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -2860,7 +2860,7 @@
     [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
-    [communication deleteComments:[NSString stringWithFormat:@"%@%@", tableAccount.url, k_dav] fileID:[[NCUtility sharedInstance] convertLocalFileID:fileID] commentID:commentID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+    [communication deleteComments:[NSString stringWithFormat:@"%@%@", tableAccount.url, k_dav] fileID:[[NCUtility sharedInstance] convertLocalFileID:fileID] messageID:messageID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
         
         completion(account, nil, 0);
         

+ 45 - 4
iOSClient/Share/NCShareComments.swift

@@ -99,7 +99,7 @@ class NCShareComments: UIViewController, NCShareCommentsCellDelegate {
         tableView.reloadData()
     }
     
-    // MARK: - IBAction
+    // MARK: - IBAction & Tap
     
     @IBAction func newCommentFieldDidEndOnExit(textField: UITextField) {
         
@@ -127,11 +127,52 @@ class NCShareComments: UIViewController, NCShareCommentsCellDelegate {
         itemDelete.customAppearance = appearanceDelete
         items.append(itemDelete)
         items.append(ActionSheetCancelButton(title: NSLocalizedString("_cancel_", comment: "")))
-        
+                
         actionSheet = ActionSheet(items: items) { sheet, item in
             
-            if item.value as? Int == 1 {  }
-            if item.value as? Int == 2 {  }
+            if item.value as? Int == 0 {
+                
+                guard let metadata = self.metadata else { return }
+                guard let tableComments = tableComments else { return }
+                
+                let alert = UIAlertController(title: NSLocalizedString("_edit_comment_", comment: ""), message: nil, preferredStyle: .alert)
+                alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil))
+                
+                alert.addTextField(configurationHandler: { textField in
+                    textField.placeholder = NSLocalizedString("_new_comment_", comment: "")
+                })
+                
+                alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
+                    if let message = alert.textFields?.first?.text {
+                        if message != "" {
+                            OCNetworking.sharedManager()?.updateComments(withAccount: metadata.account, fileID: metadata.fileID, messageID: tableComments.messageID, message: message, completion: { (account, message, errorCode) in
+                                if errorCode == 0 {
+                                    self.reloadData()
+                                } else {
+                                    self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                                }
+                            })
+                        }
+                    }
+                }))
+                
+                self.present(alert, animated: true)
+            }
+            
+            if item.value as? Int == 1 {
+                
+                guard let metadata = self.metadata else { return }
+                guard let tableComments = tableComments else { return }
+
+                OCNetworking.sharedManager()?.deleteComments(withAccount: metadata.account, fileID: metadata.fileID, messageID: tableComments.messageID, completion: { (account, message, errorCode) in
+                    if errorCode == 0 {
+                        self.reloadData()
+                    } else {
+                        self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                    }
+                })
+                
+            }
             if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
         }