Ver Fonte

realized that contactDetailController archvive method was not implemented so I fixed that

nayooti há 5 anos atrás
pai
commit
0468a1c862

+ 58 - 42
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -147,49 +147,22 @@ class ContactDetailViewController: UITableViewController {
 
     private func handleCellAction(for index: Int) {
         if index == 0 {
-            coordinator?.archiveChat()
+            toggleArchiveChat()
         } else if index == 1 {
             toggleBlockContact()
         } else {
             safe_assert(index == 2)
             showDeleteChatConfirmationAlert()
         }
-
     }
-    private func askToChatWith(contactId: Int) {
-        let dcContact = DcContact(id: contactId)
-        let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
-                                      message: nil,
-                                      preferredStyle: .safeActionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
-            self.dismiss(animated: true, completion: nil)
-            let chatId = Int(dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId)))
-            self.coordinator?.showChat(chatId: chatId)
-        }))
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
-            self.dismiss(animated: true, completion: nil)
-        }))
-        present(alert, animated: true, completion: nil)
+
+    private func toggleArchiveChat() {
+        let archived = viewModel.toggleArchiveChat()
+        updateArchiveChatCell(archived: archived)
     }
 
-    private func toggleBlockContact() {
-        if viewModel.contact.isBlocked {
-            let alert = UIAlertController(title: String.localized("ask_unblock_contact"), message: nil, preferredStyle: .safeActionSheet)
-            alert.addAction(UIAlertAction(title: String.localized("menu_unblock_contact"), style: .default, handler: { _ in
-                self.viewModel.contact.unblock()
-                self.updateBlockContactCell()
-            }))
-            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
-            present(alert, animated: true, completion: nil)
-        } else {
-            let alert = UIAlertController(title: String.localized("ask_block_contact"), message: nil, preferredStyle: .safeActionSheet)
-            alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
-                self.viewModel.contact.block()
-                self.updateBlockContactCell()
-            }))
-            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
-            present(alert, animated: true, completion: nil)
-        }
+    private func updateArchiveChatCell(archived: Bool) {
+        archiveChatCell.actionTitle = archived ? String.localized("menu_unarchive_chat") :  String.localized("menu_archive_chat")
     }
 
     private func updateBlockContactCell() {
@@ -197,19 +170,14 @@ class ContactDetailViewController: UITableViewController {
         blockContactCell.actionColor = viewModel.contact.isBlocked ? SystemColor.blue.uiColor : UIColor.red
     }
 
-    private func showNotificationSetup() {
-        let notificationSetupAlert = UIAlertController(title: "Notifications Setup is not implemented yet",
-                                                       message: "But you get an idea where this is going",
-                                                       preferredStyle: .safeActionSheet)
-        let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)
-        notificationSetupAlert.addAction(cancelAction)
-        present(notificationSetupAlert, animated: true, completion: nil)
-    }
 
     @objc private func editButtonPressed() {
         coordinator?.showEditContact(contactId: viewModel.contactId)
     }
+}
 
+// MARK: alerts
+extension ContactDetailViewController {
     private func showDeleteChatConfirmationAlert() {
         let alert = UIAlertController(
             title: nil,
@@ -222,4 +190,52 @@ class ContactDetailViewController: UITableViewController {
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
         self.present(alert, animated: true, completion: nil)
     }
+
+    private func showNotificationSetup() {
+        let notificationSetupAlert = UIAlertController(
+            title: "Notifications Setup is not implemented yet",
+            message: "But you get an idea where this is going",
+            preferredStyle: .safeActionSheet)
+        let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)
+        notificationSetupAlert.addAction(cancelAction)
+        present(notificationSetupAlert, animated: true, completion: nil)
+    }
+
+    private func toggleBlockContact() {
+        if viewModel.contact.isBlocked {
+            let alert = UIAlertController(title: String.localized("ask_unblock_contact"), message: nil, preferredStyle: .safeActionSheet)
+            alert.addAction(UIAlertAction(title: String.localized("menu_unblock_contact"), style: .default, handler: { _ in
+                self.viewModel.contact.unblock()
+                self.updateBlockContactCell()
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+            present(alert, animated: true, completion: nil)
+        } else {
+            let alert = UIAlertController(title: String.localized("ask_block_contact"), message: nil, preferredStyle: .safeActionSheet)
+            alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
+                self.viewModel.contact.block()
+                self.updateBlockContactCell()
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+            present(alert, animated: true, completion: nil)
+        }
+    }
+
+    private func askToChatWith(contactId: Int) {
+        let dcContact = DcContact(id: contactId)
+        let alert = UIAlertController(title: String.localizedStringWithFormat(
+            String.localized("ask_start_chat_with"), dcContact.nameNAddr),
+                                      message: nil,
+                                      preferredStyle: .safeActionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
+            self.dismiss(animated: true, completion: nil)
+            let chatId = Int(dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId)))
+            self.coordinator?.showChat(chatId: chatId)
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
+            self.dismiss(animated: true, completion: nil)
+        }))
+        present(alert, animated: true, completion: nil)
+    }
+
 }

+ 9 - 3
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -129,9 +129,15 @@ class GroupChatDetailViewController: UIViewController {
         coordinator?.showGroupChatEdit(chat: chat)
     }
 
-    func archiveChat() {
 
-    }
+    private func toggleArchiveChat() {
+        let archived = false
+         updateArchiveChatCell(archived: archived)
+     }
+
+     private func updateArchiveChatCell(archived: Bool) {
+         archiveChatCell.actionTitle = archived ? String.localized("menu_unarchive_chat") :  String.localized("menu_archive_chat")
+     }
 
     private func leaveGroup() {
         if let userId = currentUser?.id {
@@ -236,7 +242,7 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
             coordinator?.showContactDetail(of: contact.id)
         case .chatActions:
             if row == 0 {
-                archiveChat()
+                toggleArchiveChat()
             } else if row == 1 {
                 leaveGroup()
             } else if row == 2 {

+ 0 - 6
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -628,11 +628,6 @@ class ContactDetailCoordinator: Coordinator, ContactDetailCoordinatorProtocol {
         self.navigationController.popToRootViewController(animated: true)
         CATransaction.commit()
     }
-
-    func archiveChat() {
-        print("archive chat")
-    }
-
 }
 
 class EditGroupCoordinator: Coordinator {
@@ -689,7 +684,6 @@ protocol ContactDetailCoordinatorProtocol: class {
     func showEditContact(contactId: Int)
     func showChat(chatId: Int)
     func deleteChat()
-    func archiveChat()
 }
 
 protocol EditContactCoordinatorProtocol: class {

+ 12 - 2
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -10,6 +10,7 @@ protocol ContactDetailViewModelProtocol {
     func update(sharedChatCell: ContactCell, row index: Int)
     func getSharedChatIdAt(indexPath: IndexPath) -> Int
     func titleFor(section: Int) -> String?
+    func toggleArchiveChat() -> Bool // returns true if chat is archived after action
 }
 
 class ContactDetailViewModel: ContactDetailViewModelProtocol {
@@ -89,8 +90,17 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
 
     func titleFor(section: Int) -> String? {
         if sections[section] == .sharedChats {
-           return String.localized("profile_shared_chats")
+            return String.localized("profile_shared_chats")
         }
         return nil
-      }
+    }
+
+    func toggleArchiveChat() -> Bool {
+        guard let chatId = chatId else {
+            safe_fatalError("there is now chatId- you are probably are calling this from ContactDetail - this should be only called from ChatDetail")
+            return false
+        }
+        context.archiveChat(chatId: chatId, archive: !chatIsArchived)
+        return chatIsArchived
+    }
 }