Skip to content

Commit 8ad1968

Browse files
committed
store [nfc]: Move queueId to PerAccountStore
This is an NFC because UpdateMachine would have thrown (before this change) when the null-check is not on PerAccountStore. This queueId will later be used for local-echoing.
1 parent 72cb129 commit 8ad1968

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

lib/model/store.dart

+12-8
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,19 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
333333
connection ??= globalStore.apiConnectionFromAccount(account);
334334
assert(connection.zulipFeatureLevel == account.zulipFeatureLevel);
335335

336+
final queueId = initialSnapshot.queueId;
337+
if (queueId == null) {
338+
// The queueId is optional in the type, but should only be missing in the
339+
// case of unauthenticated access to a web-public realm. We authenticated.
340+
throw Exception("bad initial snapshot: missing queueId");
341+
}
342+
336343
final realmUrl = account.realmUrl;
337344
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
338345
return PerAccountStore._(
339346
globalStore: globalStore,
340347
connection: connection,
348+
queueId: queueId,
341349
realmUrl: realmUrl,
342350
realmWildcardMentionPolicy: initialSnapshot.realmWildcardMentionPolicy,
343351
realmMandatoryTopics: initialSnapshot.realmMandatoryTopics,
@@ -381,6 +389,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
381389
PerAccountStore._({
382390
required GlobalStore globalStore,
383391
required this.connection,
392+
required this.queueId,
384393
required this.realmUrl,
385394
required this.realmWildcardMentionPolicy,
386395
required this.realmMandatoryTopics,
@@ -420,6 +429,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
420429
final GlobalStore _globalStore;
421430
final ApiConnection connection; // TODO(#135): update zulipFeatureLevel with events
422431

432+
final String queueId;
423433
UpdateMachine? get updateMachine => _updateMachine;
424434
UpdateMachine? _updateMachine;
425435
set updateMachine(UpdateMachine? value) {
@@ -997,12 +1007,7 @@ class UpdateMachine {
9971007
UpdateMachine.fromInitialSnapshot({
9981008
required this.store,
9991009
required InitialSnapshot initialSnapshot,
1000-
}) : queueId = initialSnapshot.queueId ?? (() {
1001-
// The queueId is optional in the type, but should only be missing in the
1002-
// case of unauthenticated access to a web-public realm. We authenticated.
1003-
throw Exception("bad initial snapshot: missing queueId");
1004-
})(),
1005-
lastEventId = initialSnapshot.lastEventId {
1010+
}) : lastEventId = initialSnapshot.lastEventId {
10061011
store.updateMachine = this;
10071012
}
10081013

@@ -1068,7 +1073,6 @@ class UpdateMachine {
10681073
}
10691074

10701075
final PerAccountStore store;
1071-
final String queueId;
10721076
int lastEventId;
10731077

10741078
bool _disposed = false;
@@ -1209,7 +1213,7 @@ class UpdateMachine {
12091213
final GetEventsResult result;
12101214
try {
12111215
result = await getEvents(store.connection,
1212-
queueId: queueId, lastEventId: lastEventId);
1216+
queueId: store.queueId, lastEventId: lastEventId);
12131217
if (_disposed) return;
12141218
} catch (e, stackTrace) {
12151219
if (_disposed) return;

test/model/store_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ void main() {
673673
..method.equals('GET')
674674
..url.path.equals('/api/v1/events')
675675
..url.queryParameters.deepEquals({
676-
'queue_id': updateMachine.queueId,
676+
'queue_id': store.queueId,
677677
'last_event_id': lastEventId.toString(),
678678
});
679679
}
@@ -838,7 +838,7 @@ void main() {
838838

839839
void prepareExpiredEventQueue() {
840840
connection.prepare(apiException: eg.apiExceptionBadEventQueueId(
841-
queueId: updateMachine.queueId));
841+
queueId: store.queueId));
842842
}
843843

844844
Future<void> prepareHandleEventError() async {

test/widgets/message_list_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void main() {
159159
updateMachine.poll();
160160

161161
updateMachine.debugPrepareLoopError(
162-
eg.apiExceptionBadEventQueueId(queueId: updateMachine.queueId));
162+
eg.apiExceptionBadEventQueueId(queueId: store.queueId));
163163
updateMachine.debugAdvanceLoop();
164164
await tester.pump();
165165
// Event queue has been replaced; but the [MessageList] hasn't been

0 commit comments

Comments
 (0)