Skip to content

Commit 2609910

Browse files
committed
store: Add nullable [PerAccountStore.updateMachine]; dispose in [dispose]
1 parent 6cfe900 commit 2609910

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/model/store.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
310310
final GlobalStore _globalStore;
311311
final ApiConnection connection; // TODO(#135): update zulipFeatureLevel with events
312312

313+
UpdateMachine? get updateMachine => _updateMachine;
314+
UpdateMachine? _updateMachine;
315+
set updateMachine(UpdateMachine? value) {
316+
assert(_updateMachine == null);
317+
assert(value != null);
318+
_updateMachine = value;
319+
}
320+
313321
bool get isLoading => _isLoading;
314322
bool _isLoading = false;
315323
@visibleForTesting
@@ -452,6 +460,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
452460
unreads.dispose();
453461
_messages.dispose();
454462
typingStatus.dispose();
463+
updateMachine?.dispose();
455464
super.dispose();
456465
}
457466

@@ -729,7 +738,9 @@ class UpdateMachine {
729738
// case of unauthenticated access to a web-public realm. We authenticated.
730739
throw Exception("bad initial snapshot: missing queueId");
731740
})(),
732-
lastEventId = initialSnapshot.lastEventId;
741+
lastEventId = initialSnapshot.lastEventId {
742+
store.updateMachine = this;
743+
}
733744

734745
/// Load the user's data from the server, and start an event queue going.
735746
///
@@ -874,8 +885,8 @@ class UpdateMachine {
874885
switch (e) {
875886
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
876887
assert(debugLog('Lost event queue for $store. Replacing…'));
888+
// This disposes the store, which disposes this update machine.
877889
await store._globalStore._reloadPerAccount(store.accountId);
878-
dispose();
879890
debugLog('… Event queue replaced.');
880891
return;
881892

0 commit comments

Comments
 (0)