Ver Fonte

Merge pull request #937 from deltachat/adapt-to-notices-api

catch new DC_EVENT_MSGS_NOTICED as needed
bjoern há 4 anos atrás
pai
commit
31db0bf698

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

@@ -11,6 +11,7 @@ public let dcNotificationViewChat = Notification.Name(rawValue: "MrEventViewChat
 public let dcNotificationContactChanged = Notification.Name(rawValue: "MrEventContactsChanged")
 public let dcNotificationChatModified = Notification.Name(rawValue: "dcNotificationChatModified")
 public let dcEphemeralTimerModified =  Notification.Name(rawValue: "dcEphemeralTimerModified")
+public let dcMsgsNoticed = Notification.Name(rawValue: "dcMsgsNoticed")
 
 public func handleEvent(event: DcEvent) {
     let id = event.id
@@ -94,6 +95,18 @@ public func handleEvent(event: DcEvent) {
             )
         }
 
+    case DC_EVENT_MSGS_NOTICED:
+        let nc = NotificationCenter.default
+        DispatchQueue.main.async {
+            nc.post(
+                name: dcMsgsNoticed,
+                object: nil,
+                userInfo: [
+                    "chat_id": Int(data1),
+                ]
+            )
+        }
+
     case DC_EVENT_CHAT_MODIFIED:
         DcContext.shared.logger?.info("chat modified: \(id)")
         let nc = NotificationCenter.default

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

@@ -10,6 +10,7 @@ class ChatListController: UITableViewController {
     private let contactCellReuseIdentifier = "contact_cell"
 
     private var msgChangedObserver: Any?
+    private var msgsNoticedObserver: Any?
     private var incomingMsgObserver: Any?
     private var viewChatObserver: Any?
 
@@ -105,6 +106,13 @@ class ChatListController: UITableViewController {
             queue: nil) { [weak self] _ in
                 self?.viewModel.refreshData()
 
+        }
+        msgsNoticedObserver = nc.addObserver(
+            forName: dcMsgsNoticed,
+            object: nil,
+            queue: nil) { [weak self] _ in
+                self?.viewModel.refreshData()
+
         }
         incomingMsgObserver = nc.addObserver(
             forName: dcNotificationIncoming,