Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit b84bb36

Browse files
authored
Merge pull request #2523 from RocketChat/bug/fixed_bug_mapping_subscription
[FIX] View models deallocation & Subscription object mapping fixing on updates
2 parents 30589ba + 1fdc116 commit b84bb36

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

Rocket.Chat/Controllers/Chat/MessagesSubscriptionViewModel.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ final class MessagesSubscriptionViewModel {
5656
// MARK: Life Cycle
5757

5858
deinit {
59+
destroy()
60+
}
61+
62+
internal func destroy() {
5963
subscriptionQueryToken?.invalidate()
6064

6165
if let subscription = subscription {

Rocket.Chat/Controllers/Chat/MessagesViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ final class MessagesViewController: RocketChatViewController {
114114
deinit {
115115
NotificationCenter.default.removeObserver(self)
116116
SocketManager.removeConnectionHandler(token: socketHandlerToken)
117+
118+
viewModel.destroy()
119+
viewSubscriptionModel.destroy()
117120
}
118121

119122
var allowResignFirstResponder = true

Rocket.Chat/Controllers/Chat/MessagesViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,15 @@ final class MessagesViewModel {
174174
self.controllerContext = controllerContext
175175
}
176176

177-
deinit {
177+
internal func destroy() {
178178
messagesQueryToken?.invalidate()
179179
unsubscribe()
180180
}
181181

182+
deinit {
183+
destroy()
184+
}
185+
182186
// MARK: Subscriptions Control
183187

184188
/**

Rocket.Chat/Managers/Model/SubscriptionManager/SubscriptionManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct SubscriptionManager {
7777

7878
let subscription = Subscription.find(rid: rid, realm: realm) ??
7979
Subscription.getOrCreate(realm: realm, values: object, updates: nil)
80+
subscription.map(object, realm: realm)
8081

8182
if msg == "removed" {
8283
realm.delete(subscription)

0 commit comments

Comments
 (0)