Browse Source

Merge pull request #1183 from deltachat/simplify_delete_saved_messages

simplify chat deletion
cyBerta 4 years ago
parent
commit
a1451b05bd

+ 1 - 3
deltachat-ios/Controller/ChatListController.swift

@@ -458,9 +458,7 @@ class ChatListController: UITableViewController {
             return
         }
 
-        if let row = viewModel.deleteChat(chatId: chatId) {
-            tableView.deleteRows(at: [IndexPath(row: row, section: 0)], with: .fade)
-        }
+        viewModel.deleteChat(chatId: chatId)
     }
 
     // MARK: - coordinator

+ 2 - 13
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -22,8 +22,7 @@ protocol ChatListViewModelProtocol: class, UISearchResultsUpdating {
     func titleForHeaderIn(section: Int) -> String? // only visible on search results
     var emptySearchText: String? { get }
 
-    /// returns ROW of table
-    func deleteChat(chatId: Int) -> Int?
+    func deleteChat(chatId: Int)
     func archiveChatToggle(chatId: Int)
     func pinChatToggle(chatId: Int)
     func refreshData()
@@ -201,18 +200,8 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
         return nil
     }
 
-    func deleteChat(chatId: Int) -> Int? {
-        // find index of chatId
-        let indexToDelete = Array(0..<chatList.length).filter { chatList.getChatId(index: $0) == chatId }.first
-        let chat = dcContext.getChat(chatId: chatId)
+    func deleteChat(chatId: Int) {
         dcContext.deleteChat(chatId: chatId)
-        updateChatList(notifyListener: false)
-        safe_assert(indexToDelete != nil)
-        // Do not return the index of the tableview cell for the selfTalk chat:
-        // Immediately after deleting the chat, a message to the device talk chat gets added.
-        // If the device talk chat was not existing it would be created and added to the table data source.
-        // That case invalidates the index.
-        return chat.isSelfTalk ? nil : indexToDelete
     }
 
     func archiveChatToggle(chatId: Int) {