소스 검색

proof core DC_EVENT_CHAT_MODIFIED

cyberta 5 년 전
부모
커밋
7693f75e06
2개의 변경된 파일42개의 추가작업 그리고 1개의 파일을 삭제
  1. 28 1
      deltachat-ios/Controller/NewGroupController.swift
  2. 14 0
      deltachat-ios/DC/events.swift

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

@@ -13,6 +13,7 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
     var groupImage: UIImage?
     let isVerifiedGroup: Bool
     let dcContext: DcContext
+    private var contactAddedObserver: NSObjectProtocol?
 
     private let sectionGroupDetails = 0
     private let sectionGroupDetailsRowAvatar = 0
@@ -61,9 +62,35 @@ 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 {
+                    logger.warning("new created group chat id: \(self.groupChatId) vs. DC_EVENT_CHAT_MODIFIED chat Id: \(chatId)")
+                    if self.groupChatId == 0 /*|| chatId != self.groupChatId*/ {
+                        return
+                    }
+                    self.updateGroupContactIdsOnQRCodeInvite()
+                }
+            }
+        }
+    }
+
+    override func viewWillDisappear(_ animated: Bool) {
+        if let observer = self.contactAddedObserver {
+            NotificationCenter.default.removeObserver(observer)
+        }
+    }
+
+
     @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 = [