瀏覽代碼

Merge pull request #1163 from deltachat/minor-chatlist-fixes

minor chatlist fixes
bjoern 4 年之前
父節點
當前提交
fc80262db3
共有 2 個文件被更改,包括 19 次插入3 次删除
  1. 7 1
      deltachat-ios/AppDelegate.swift
  2. 12 2
      deltachat-ios/ViewModel/ChatListViewModel.swift

+ 7 - 1
deltachat-ios/AppDelegate.swift

@@ -370,7 +370,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         // we're in background, run IO for a little time
         dcContext.maybeStartIo()
-        dcContext.maybeNetwork()
+
+        // maybeNetwork() shall not be called in ui thread;
+        // even if we're in backround now, app may be starting just now and maybeNetwork() will block in that case
+        // (series of performFetchWithCompletionHandler/applicationWillEnterForeground are not rare)
+        DispatchQueue.global(qos: .background).async { [weak self] in
+            self?.dcContext.maybeNetwork()
+        }
 
         DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in
             logger.info("⬅️ finishing fetch")

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

@@ -119,10 +119,20 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
             switch searchResultSections[section] {
             case .chats:
                 return makeChatCellViewModel(index: row, searchText: searchText)
+
             case .contacts:
-                return ContactCellViewModel.make(contactId: searchResultContactIds[row], searchText: searchText, dcContext: dcContext)
+                if row >= 0 && row < searchResultContactIds.count {
+                    return ContactCellViewModel.make(contactId: searchResultContactIds[row], searchText: searchText, dcContext: dcContext)
+                } else {
+                    logger.warning("search: requested contact index \(row) not in range 0..\(searchResultContactIds.count)")
+                }
+
             case .messages:
-                return makeMessageCellViewModel(msgId: searchResultMessageIds[row])
+                if row >= 0 && row < searchResultMessageIds.count {
+                    return makeMessageCellViewModel(msgId: searchResultMessageIds[row])
+                } else {
+                    logger.warning("search: requested message index \(row) not in range 0..\(searchResultMessageIds.count)")
+                }
             }
         }
         return makeChatCellViewModel(index: row, searchText: "")