Kaynağa Gözat

Merge pull request #1629 from deltachat/immediate_swipe_action_list_updates

immediately update chatlist on swipe actions
cyBerta 3 yıl önce
ebeveyn
işleme
b79f77b8d9

+ 6 - 4
deltachat-ios/Controller/ChatListController.swift

@@ -446,12 +446,14 @@ class ChatListController: UITableViewController {
 
         let archiveAction = UITableViewRowAction(style: .destructive, title: archiveActionTitle) { [weak self] _, _ in
             self?.viewModel?.archiveChatToggle(chatId: chatId)
+            self?.setEditing(false, animated: true)
         }
         archiveAction.backgroundColor = UIColor.lightGray
 
         let pinned = chat.visibility==DC_CHAT_VISIBILITY_PINNED
         let pinAction = UITableViewRowAction(style: .destructive, title: String.localized(pinned ? "unpin" : "pin")) { [weak self] _, _ in
             self?.viewModel?.pinChatToggle(chatId: chat.id)
+            self?.setEditing(false, animated: true)
         }
         pinAction.backgroundColor = UIColor.systemGreen
 
@@ -465,12 +467,12 @@ class ChatListController: UITableViewController {
 
     override func setEditing(_ editing: Bool, animated: Bool) {
         super.setEditing(editing, animated: animated)
+        tableView.setEditing(editing, animated: animated)
         viewModel?.setEditing(editing)
     }
 
     func setLongTapEditing(_ editing: Bool, initialIndexPath: [IndexPath]? = nil) {
-        tableView.setEditing(editing, animated: true)
-        viewModel?.setEditing(editing)
+        setEditing(editing, animated: true)
         if editing {
             addEditingView()
             if let viewModel = viewModel {
@@ -555,8 +557,8 @@ class ChatListController: UITableViewController {
     }
 
     func handleChatListUpdate() {
-        if tableView.isEditing {
-            viewModel?.setPendingChatListUpdate()
+        if let viewModel = viewModel, viewModel.isEditing {
+            viewModel.setPendingChatListUpdate()
             return
         }
         if Thread.isMainThread {

+ 5 - 5
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -42,7 +42,7 @@ class ChatListViewModel: NSObject {
     private var searchResultSections: [ChatListSectionType] = []
 
     private var isChatListUpdatePending = false
-    private var isEditing = false
+    private(set) var isEditing = false
 
     init(dcContext: DcContext, isArchive: Bool) {
         self.isArchive = isArchive
@@ -235,18 +235,18 @@ class ChatListViewModel: NSObject {
         if !isArchivedBefore {
             NotificationManager.removeNotificationsForChat(dcContext: dcContext, chatId: chatId)
         }
-        updateChatList(notifyListener: false)
+        updateChatList(notifyListener: true)
     }
 
     func pinChatToggle(chatId: Int) {
         let chat: DcChat = dcContext.getChat(chatId: chatId)
         let pinned = chat.visibility == DC_CHAT_VISIBILITY_PINNED
-        pinChat(chatId: chatId, pinned: pinned)
+        pinChat(chatId: chatId, pinned: pinned, notifyListener: true)
     }
 
-    func pinChat(chatId: Int, pinned: Bool) {
+    func pinChat(chatId: Int, pinned: Bool, notifyListener: Bool = false) {
         self.dcContext.setChatVisibility(chatId: chatId, visibility: pinned ? DC_CHAT_VISIBILITY_NORMAL : DC_CHAT_VISIBILITY_PINNED)
-        updateChatList(notifyListener: false)
+        updateChatList(notifyListener: notifyListener)
     }
 
     func hasOnlyPinnedChatsSelected(in indexPaths: [IndexPath]?) -> Bool {