B. Petersen 5 лет назад
Родитель
Сommit
623e85756b

+ 5 - 36
deltachat-ios/Controller/ChatListController.swift

@@ -33,12 +33,13 @@ class ChatListController: UITableViewController {
         return button
     }()
 
-    private lazy var archiveCell: UITableViewCell = {
+    func getArchiveCell(title: String) -> UITableViewCell {
         let cell = UITableViewCell()
         cell.textLabel?.textColor = .systemBlue
+        cell.textLabel?.text = title
         cell.textLabel?.textAlignment = .center
         return cell
-    }()
+    }
 
     init(viewModel: ChatListViewModelProtocol) {
         self.viewModel = viewModel
@@ -66,10 +67,9 @@ class ChatListController: UITableViewController {
 
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
-        getChatList()
 
         if RelayHelper.sharedInstance.isForwarding() {
-            chatTable.scrollToTop()
+            tableView.scrollToTop()
         }
 
         updateTitle()
@@ -141,21 +141,9 @@ class ChatListController: UITableViewController {
     @objc func cancelButtonPressed() {
         // cancel forwarding
         RelayHelper.sharedInstance.cancel()
-        getChatList()
         updateTitle()
     }
 
-    private func getChatList() {
-        var gclFlags: Int32 = 0
-        if showArchive {
-            gclFlags |= DC_GCL_ARCHIVED_ONLY
-        } else if RelayHelper.sharedInstance.isForwarding() {
-            gclFlags |= DC_GCL_FOR_FORWARDING
-        }
-        chatList = dcContext.getChatlist(flags: gclFlags, queryString: nil, queryId: 0)
-        tableView.reloadData()
-    }
-
     override func numberOfSections(in tableView: UITableView) -> Int {
         return viewModel.numberOfSections
     }
@@ -179,8 +167,7 @@ class ChatListController: UITableViewController {
         case .chat(let chatData):
             let chatId = chatData.chatId
             if chatId == DC_CHAT_ID_ARCHIVED_LINK {
-                updateArchivedCell() // to make sure archived chats count is always right
-                return archiveCell
+                return getArchiveCell(title: DcChat(id: chatId).name)
             } else if let chatCell = tableView.dequeueReusableCell(withIdentifier: chatCellReuseIdentifier, for: indexPath) as? ContactCell {
                 // default chatCell
                 chatCell.updateCell(cellViewModel: cellData)
@@ -244,7 +231,6 @@ class ChatListController: UITableViewController {
 
         let archiveAction = UITableViewRowAction(style: .destructive, title: archiveActionTitle) { [unowned self] _, _ in
             self.viewModel.archiveChatToggle(chatId: chatId)
-            self.updateArchivedCell()
         }
         archiveAction.backgroundColor = UIColor.lightGray
 
@@ -281,13 +267,6 @@ class ChatListController: UITableViewController {
         tableView.reloadData()
     }
 
-    func updateArchivedCell() {
-        var title = String.localized("chat_archived_chats_title")
-        let count = viewModel.numberOfArchivedChats
-        title.append(" (\(count))")
-        archiveCell.textLabel?.text = title
-    }
-
     func updateDeaddropCell(_ cell: ContactCell, msgId: Int, cellData: AvatarCellViewModel) {
         cell.backgroundColor = DcColors.deaddropBackground
         cell.contentView.backgroundColor = DcColors.deaddropBackground
@@ -371,16 +350,6 @@ class ChatListController: UITableViewController {
         self.present(alert, animated: true, completion: nil)
     }
 
-    // MARK: - actions
-    @objc func didPressNewChat() {
-        coordinator?.showNewChatController()
-    }
-
-    @objc func cancelButtonPressed() {
-        RelayHelper.sharedInstance.cancel()
-        updateTitle()
-    }
-
     private func deleteChat(chatId: Int, animated: Bool) {
         if !animated {
             _ = viewModel.deleteChat(chatId: chatId)

+ 2 - 4
deltachat-ios/View/ContactCell.swift

@@ -265,9 +265,6 @@ class ContactCell: UITableViewCell {
                 backgroundColor = DcColors.contactCellBackgroundColor
                 contentView.backgroundColor = DcColors.contactCellBackgroundColor
             }
-            setVerified(isVerified: chat.isVerified)
-            setTimeLabel(chatData.summary.timestamp)
-            setStatusIndicators(unreadCount: chatData.unreadMessages, status: chatData.summary.state, visibility: chat.visibility)
             if let img = chat.profileImage {
                 resetBackupImage()
                 setImage(img)
@@ -276,7 +273,8 @@ class ContactCell: UITableViewCell {
             }
             setVerified(isVerified: chat.isVerified)
             setTimeLabel(chatData.summary.timestamp)
-            setStatusIndicators(unreadCount: chatData.unreadMessages, status: chatData.summary.state, visibility: chat.visibility, isLocationStreaming: chat.isSendingLocations)
+            setStatusIndicators(unreadCount: chatData.unreadMessages, status: chatData.summary.state,
+                                visibility: chat.visibility, isLocationStreaming: chat.isSendingLocations)
 
         case .contact(let contactData):
             let contact = DcContact(id: contactData.contactId)

+ 0 - 7
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -25,8 +25,6 @@ protocol ChatListViewModelProtocol: class, UISearchResultsUpdating {
     func archiveChatToggle(chatId: Int)
     func pinChatToggle(chatId: Int)
     func refreshData()
-
-    var numberOfArchivedChats: Int { get }
 }
 
 // MARK: - ChatListViewModel
@@ -195,11 +193,6 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
         self.dcContext.setChatVisibility(chatId: chatId, visibility: pinned ? DC_CHAT_VISIBILITY_NORMAL : DC_CHAT_VISIBILITY_PINNED)
         updateChatList(notifyListener: false)
     }
-
-    var numberOfArchivedChats: Int {
-        let chatList = dcContext.getChatlist(flags: DC_GCL_ARCHIVED_ONLY, queryString: nil, queryId: 0)
-        return chatList.length
-    }
 }
 
 private extension ChatListViewModel {