فهرست منبع

Merge pull request #473 from deltachat/fix_DC_EVENT_CHAT_MODIFIED

Fix dc event chat modified
bjoern 5 سال پیش
والد
کامیت
ab79ed876d
2فایلهای تغییر یافته به همراه64 افزوده شده و 1 حذف شده
  1. 50 1
      deltachat-ios/Controller/NewGroupController.swift
  2. 14 0
      deltachat-ios/DC/events.swift

+ 50 - 1
deltachat-ios/Controller/NewGroupController.swift

@@ -13,6 +13,9 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
     var groupImage: UIImage?
     let isVerifiedGroup: Bool
     let dcContext: DcContext
+    private var contactAddedObserver: NSObjectProtocol?
+    ///TODO: remove the the line below as soon as deltachat-core 4b7b6d6cb3c26d817e3f3eeb6a20d8e8c66a4578 was released
+    private var workaroundObserver: NSObjectProtocol?
 
     private let sectionGroupDetails = 0
     private let sectionGroupDetailsRowAvatar = 0
@@ -61,9 +64,55 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
         doneButton.isEnabled = false
         tableView.register(ContactCell.self, forCellReuseIdentifier: "contactCell")
         tableView.register(ActionCell.self, forCellReuseIdentifier: "actionCell")
-        self.hideKeyboardOnTap() 
+        self.hideKeyboardOnTap()
     }
 
+    override func viewWillAppear(_ animated: Bool) {
+        let nc = NotificationCenter.default
+        contactAddedObserver = nc.addObserver(
+            forName: dcNotificationChatModified,
+            object: nil,
+            queue: nil
+        ) { notification in
+            if let ui = notification.userInfo {
+                if let chatId = ui["chat_id"] as? Int {
+                    if self.groupChatId == 0 || chatId != self.groupChatId {
+                        return
+                    }
+                    self.updateGroupContactIdsOnQRCodeInvite()
+                }
+            }
+        }
+
+        ///TODO: remove the the lines below as soon as deltachat-core 4b7b6d6cb3c26d817e3f3eeb6a20d8e8c66a4578 was released
+        workaroundObserver = nc.addObserver(
+            forName: dcNotificationChanged,
+            object: nil,
+            queue: nil
+        ) { notification in
+            if let ui = notification.userInfo {
+                if let chatId = ui["chat_id"] as? Int {
+                    if self.groupChatId == 0 || chatId != self.groupChatId {
+                        return
+                    }
+                    self.updateGroupContactIdsOnQRCodeInvite()
+                }
+            }
+        }
+    }
+
+    override func viewWillDisappear(_ animated: Bool) {
+        if let observer = self.contactAddedObserver {
+            NotificationCenter.default.removeObserver(observer)
+        }
+
+        ///TODO: remove the the lines below as soon as deltachat-core 4b7b6d6cb3c26d817e3f3eeb6a20d8e8c66a4578 was released
+        if let workaroundObserver = self.workaroundObserver {
+            NotificationCenter.default.removeObserver(workaroundObserver)
+        }
+    }
+
+
     @objc func doneButtonPressed() {
         if groupChatId == 0 {
             groupChatId = dcContext.createGroupChat(verified: isVerifiedGroup, name: groupName)

+ 14 - 0
deltachat-ios/DC/events.swift

@@ -9,6 +9,7 @@ let dcNotificationSecureJoinerProgress = Notification.Name(rawValue: "MrEventSec
 let dcNotificationSecureInviterProgress = Notification.Name(rawValue: "MrEventSecureInviterProgress")
 let dcNotificationViewChat = Notification.Name(rawValue: "MrEventViewChat")
 let dcNotificationContactChanged = Notification.Name(rawValue: "MrEventContactsChanged")
+let dcNotificationChatModified = Notification.Name(rawValue: "dcNotificationChatModified")
 
 @_silgen_name("callbackSwift")
 
@@ -89,6 +90,19 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
             )
         }
 
+    case DC_EVENT_CHAT_MODIFIED:
+        logger.info("chat modified: \(event)")
+        let nc = NotificationCenter.default
+        DispatchQueue.main.async {
+            nc.post(
+                name: dcNotificationChatModified,
+                object: nil,
+                userInfo: [
+                    "chat_id": Int(data1),
+                ]
+            )
+        }
+
     case DC_EVENT_INCOMING_MSG:
         let nc = NotificationCenter.default
         let userInfo = [