Selaa lähdekoodia

refactor and simplify chat deletion from profile

B. Petersen 5 vuotta sitten
vanhempi
commit
2337c3429e

+ 0 - 1
DcCore/DcCore/DC/events.swift

@@ -10,7 +10,6 @@ public let dcNotificationSecureInviterProgress = Notification.Name(rawValue: "Mr
 public let dcNotificationViewChat = Notification.Name(rawValue: "MrEventViewChat")
 public let dcNotificationContactChanged = Notification.Name(rawValue: "MrEventContactsChanged")
 public let dcNotificationChatModified = Notification.Name(rawValue: "dcNotificationChatModified")
-public let dcNotificationChatDeletedInChatDetail = Notification.Name(rawValue: "ChatDeletedInChatDetail")
 
 @_silgen_name("callbackSwift")
 

+ 0 - 8
deltachat-ios/Controller/ChatListController.swift

@@ -101,14 +101,6 @@ class ChatListController: UITableViewController {
                     self.showChat(chatId: chatId)
                 }
         }
-        deleteChatObserver = nc.addObserver(
-            forName: dcNotificationChatDeletedInChatDetail,
-            object: nil,
-            queue: nil) { notification in
-                if let chatId = notification.userInfo?["chat_id"] as? Int {
-                    self.deleteChat(chatId: chatId, animated: true)
-                }
-        }
     }
 
     override func viewDidDisappear(_ animated: Bool) {

+ 6 - 20
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -317,27 +317,13 @@ class ContactDetailViewController: UITableViewController {
         guard let chatId = viewModel.chatId else {
             return
         }
+        viewModel.context.deleteChat(chatId: chatId)
 
-        /*
-        app will navigate to chatlist or archive and delete the chat there
-        notify chatList/archiveList to delete chat AFTER is is visible
-        */
-        func notifyToDeleteChat() {
-            NotificationCenter.default.post(name: dcNotificationChatDeletedInChatDetail, object: nil, userInfo: ["chat_id": chatId])
+        // just pop to viewControllers - we've in chatlist or archive then
+        // (no not use `navigationController?` here: popping self will make the reference becoming nil)
+        if let navigationController = navigationController {
+            navigationController.popViewController(animated: false)
+            navigationController.popViewController(animated: true)
         }
-
-        CATransaction.begin()
-        CATransaction.setCompletionBlock(notifyToDeleteChat)
-
-        let chat = viewModel.context.getChat(chatId: chatId)
-        if chat.isArchived {
-            navigationController?.popToRootViewController(animated: false) // in main ChatList now
-            let chatlistVM = ChatListViewModel(dcContext: viewModel.context, isArchive: true)
-            let controller = ChatListController(dcContext: viewModel.context, viewModel: chatlistVM)
-            navigationController?.pushViewController(controller, animated: false)
-        } else {
-            navigationController?.popToRootViewController(animated: true) // in main ChatList now
-        }
-        CATransaction.commit()
     }
 }

+ 6 - 19
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -238,27 +238,14 @@ class GroupChatDetailViewController: UIViewController {
     }
 
     private func deleteChat() {
-        /*
-        app will navigate to chatlist or archive and delete the chat there
-        notify chatList/archiveList to delete chat AFTER is is visible
-        */
-        func notifyToDeleteChat() {
-            NotificationCenter.default.post(name: dcNotificationChatDeletedInChatDetail, object: nil, userInfo: ["chat_id": self.chatId])
-        }
-
-        CATransaction.begin()
-        CATransaction.setCompletionBlock(notifyToDeleteChat)
+        dcContext.deleteChat(chatId: chatId)
 
-        let chat = dcContext.getChat(chatId: chatId)
-        if chat.isArchived {
-            navigationController?.popToRootViewController(animated: false) // in main ChatList now
-            let viewModel = ChatListViewModel(dcContext: dcContext, isArchive: true)
-            let controller = ChatListController(dcContext: dcContext, viewModel: viewModel)
-            navigationController?.pushViewController(controller, animated: false)
-        } else {
-            navigationController?.popToRootViewController(animated: true) // in main ChatList now
+        // just pop to viewControllers - we've in chatlist or archive then
+        // (no not use `navigationController?` here: popping self will make the reference becoming nil)
+        if let navigationController = navigationController {
+            navigationController.popViewController(animated: false)
+            navigationController.popViewController(animated: true)
         }
-        CATransaction.commit()
     }
 }