瀏覽代碼

delete chat now works

nayooti 5 年之前
父節點
當前提交
5b5026bb67

+ 0 - 1
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -222,5 +222,4 @@ class ContactDetailViewController: UITableViewController {
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
         self.present(alert, animated: true, completion: nil)
         self.present(alert, animated: true, completion: nil)
     }
     }
-
 }
 }

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

@@ -129,6 +129,10 @@ class GroupChatDetailViewController: UIViewController {
         coordinator?.showGroupChatEdit(chat: chat)
         coordinator?.showGroupChatEdit(chat: chat)
     }
     }
 
 
+    func archiveChat() {
+
+    }
+
     private func leaveGroup() {
     private func leaveGroup() {
         if let userId = currentUser?.id {
         if let userId = currentUser?.id {
             let alert = UIAlertController(title: String.localized("ask_leave_group"), message: nil, preferredStyle: .safeActionSheet)
             let alert = UIAlertController(title: String.localized("ask_leave_group"), message: nil, preferredStyle: .safeActionSheet)
@@ -232,13 +236,12 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
             coordinator?.showContactDetail(of: contact.id)
             coordinator?.showContactDetail(of: contact.id)
         case .chatActions:
         case .chatActions:
             if row == 0 {
             if row == 0 {
-
+                archiveChat()
             } else if row == 1 {
             } else if row == 1 {
                 leaveGroup()
                 leaveGroup()
             } else if row == 2 {
             } else if row == 2 {
-
+                showDeleteChatConfirmationAlert()
             }
             }
-
         }
         }
     }
     }
 
 
@@ -289,3 +292,19 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
     }
     }
 
 
 }
 }
+
+// MARK: -alerts
+extension GroupChatDetailViewController {
+    private func showDeleteChatConfirmationAlert() {
+        let alert = UIAlertController(
+            title: nil,
+            message: String.localized("ask_delete_chat_desktop"),
+            preferredStyle: .safeActionSheet
+        )
+        alert.addAction(UIAlertAction(title: String.localized("menu_delete_chat"), style: .destructive, handler: { _ in
+            self.coordinator?.deleteChat()
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+        self.present(alert, animated: true, completion: nil)
+    }
+}

+ 17 - 2
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -341,11 +341,13 @@ class NewChatCoordinator: Coordinator {
 class GroupChatDetailCoordinator: Coordinator {
 class GroupChatDetailCoordinator: Coordinator {
     var dcContext: DcContext
     var dcContext: DcContext
     let navigationController: UINavigationController
     let navigationController: UINavigationController
+    let chatId: Int
 
 
     private var childCoordinators: [Coordinator] = []
     private var childCoordinators: [Coordinator] = []
 
 
-    init(dcContext: DcContext, navigationController: UINavigationController) {
+    init(dcContext: DcContext, chatId: Int, navigationController: UINavigationController) {
         self.dcContext = dcContext
         self.dcContext = dcContext
+        self.chatId = chatId
         self.navigationController = navigationController
         self.navigationController = navigationController
     }
     }
 
 
@@ -387,6 +389,19 @@ class GroupChatDetailCoordinator: Coordinator {
         navigationController.pushViewController(contactDetailController, animated: true)
         navigationController.pushViewController(contactDetailController, animated: true)
     }
     }
 
 
+    func deleteChat() {
+        func notifyToDeleteChat() {
+            NotificationCenter.default.post(name: dcNotificationChatDeletedInChatDetail, object: nil, userInfo: ["chat_id": chatId])
+        }
+
+        // we want to notify chatList to delete chat AFTER is is visible
+        CATransaction.begin()
+        CATransaction.setAnimationDuration(2)
+        CATransaction.setCompletionBlock(notifyToDeleteChat)
+        self.navigationController.popToRootViewController(animated: true)
+        CATransaction.commit()
+    }
+
 }
 }
 
 
 class ChatViewCoordinator: NSObject, Coordinator {
 class ChatViewCoordinator: NSObject, Coordinator {
@@ -423,7 +438,7 @@ class ChatViewCoordinator: NSObject, Coordinator {
             }
             }
         case .GROUP, .VERYFIEDGROUP:
         case .GROUP, .VERYFIEDGROUP:
             let groupChatDetailViewController = GroupChatDetailViewController(chatId: chatId) // inherits from ChatDetailViewController
             let groupChatDetailViewController = GroupChatDetailViewController(chatId: chatId) // inherits from ChatDetailViewController
-            let coordinator = GroupChatDetailCoordinator(dcContext: dcContext, navigationController: navigationController)
+            let coordinator = GroupChatDetailCoordinator(dcContext: dcContext, chatId: chatId, navigationController: navigationController)
             childCoordinators.append(coordinator)
             childCoordinators.append(coordinator)
             groupChatDetailViewController.coordinator = coordinator
             groupChatDetailViewController.coordinator = coordinator
             navigationController.pushViewController(groupChatDetailViewController, animated: true)
             navigationController.pushViewController(groupChatDetailViewController, animated: true)