Browse Source

Merge pull request #717 from deltachat/retain-cycle-fix

Fix retain cycles in ChatList and NewGroupController
nayooti 5 năm trước cách đây
mục cha
commit
1d8e48eb44

+ 6 - 6
deltachat-ios/Controller/ChatListController.swift

@@ -82,22 +82,22 @@ class ChatListController: UITableViewController {
         msgChangedObserver = nc.addObserver(
             forName: dcNotificationChanged,
             object: nil,
-            queue: nil) { _ in
-                self.viewModel.refreshData()
+            queue: nil) { [weak self] _ in
+                self?.viewModel.refreshData()
 
         }
         incomingMsgObserver = nc.addObserver(
             forName: dcNotificationIncoming,
             object: nil,
-            queue: nil) { _ in
-                self.viewModel.refreshData()
+            queue: nil) { [weak self] _ in
+                self?.viewModel.refreshData()
         }
         viewChatObserver = nc.addObserver(
             forName: dcNotificationViewChat,
             object: nil,
-            queue: nil) { notification in
+            queue: nil) { [weak self] notification in
                 if let chatId = notification.userInfo?["chat_id"] as? Int {
-                    self.showChat(chatId: chatId)
+                    self?.showChat(chatId: chatId)
                 }
         }
     }

+ 2 - 1
deltachat-ios/Controller/ChatViewController.swift

@@ -159,7 +159,8 @@ class ChatViewController: MessagesViewController {
             forName: dcNotificationChanged,
             object: nil,
             queue: OperationQueue.main
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if self.disableWriting {
                     // always refresh, as we can't check currently

+ 2 - 1
deltachat-ios/Controller/GroupMembersViewController.swift

@@ -109,7 +109,8 @@ class AddGroupMembersViewController: GroupMembersViewController {
             forName: dcNotificationContactChanged,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if let contactId = ui["contact_id"] as? Int {
                     if contactId == 0 {

+ 2 - 1
deltachat-ios/Controller/NewChatViewController.swift

@@ -96,7 +96,8 @@ class NewChatViewController: UITableViewController {
             forName: dcNotificationSecureJoinerProgress,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if ui["error"] as? Bool ?? false {
                     self.hud?.error(ui["errorMessage"] as? String)

+ 4 - 2
deltachat-ios/Controller/NewGroupController.swift

@@ -74,7 +74,8 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
             forName: dcNotificationChatModified,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if let chatId = ui["chat_id"] as? Int {
                     if self.groupChatId == 0 || chatId != self.groupChatId {
@@ -90,7 +91,8 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
             forName: dcNotificationChanged,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if let chatId = ui["chat_id"] as? Int {
                     if self.groupChatId == 0 || chatId != self.groupChatId {

+ 2 - 1
deltachat-ios/Controller/QrPageController.swift

@@ -239,7 +239,8 @@ extension QrPageController: QrCodeReaderDelegate {
             forName: dcNotificationSecureJoinerProgress,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo,
                 ui["progress"] as? Int == 400,
                 let contactId = ui["contact_id"] as? Int {

+ 4 - 2
deltachat-ios/Controller/SettingsController.swift

@@ -239,7 +239,8 @@ internal final class SettingsViewController: UITableViewController {
             forName: dcNotificationImexProgress,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if ui["error"] as? Bool ?? false {
                     self.hudHandler.setHudError(ui["errorMessage"] as? String)
@@ -254,7 +255,8 @@ internal final class SettingsViewController: UITableViewController {
             forName: dcNotificationConfigureProgress,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if ui["error"] as? Bool ?? false {
                     self.hudHandler.setHudError(ui["errorMessage"] as? String)

+ 2 - 1
deltachat-ios/Handler/ProgressAlertHandler.swift

@@ -64,7 +64,8 @@ extension ProgressAlertHandler {
             forName: dcNotificationConfigureProgress,
             object: nil,
             queue: nil
-        ) { notification in
+        ) { [weak self] notification in
+            guard let self = self else { return }
             if let ui = notification.userInfo {
                 if ui["error"] as? Bool ?? false {
                     self.updateProgressAlert(error: ui["errorMessage"] as? String)