Skip to content

Commit c5d0abf

Browse files
PIG208gnprice
authored andcommitted
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 5634c57 commit c5d0abf

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

lib/model/store.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,19 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
360360
connection ??= globalStore.apiConnectionFromAccount(account);
361361
assert(connection.zulipFeatureLevel == account.zulipFeatureLevel);
362362

363+
final queueId = initialSnapshot.queueId;
364+
if (queueId == null) {
365+
// The queueId is optional in the type, but should only be missing in the
366+
// case of unauthenticated access to a web-public realm. We authenticated.
367+
throw Exception("bad initial snapshot: missing queueId");
368+
}
369+
363370
final realmUrl = account.realmUrl;
364371
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
365372
return PerAccountStore._(
366373
globalStore: globalStore,
367374
connection: connection,
375+
queueId: queueId,
368376
realmUrl: realmUrl,
369377
realmWildcardMentionPolicy: initialSnapshot.realmWildcardMentionPolicy,
370378
realmMandatoryTopics: initialSnapshot.realmMandatoryTopics,
@@ -408,6 +416,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
408416
PerAccountStore._({
409417
required GlobalStore globalStore,
410418
required this.connection,
419+
required this.queueId,
411420
required this.realmUrl,
412421
required this.realmWildcardMentionPolicy,
413422
required this.realmMandatoryTopics,
@@ -447,6 +456,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
447456
final GlobalStore _globalStore;
448457
final ApiConnection connection; // TODO(#135): update zulipFeatureLevel with events
449458

459+
final String queueId;
450460
UpdateMachine? get updateMachine => _updateMachine;
451461
UpdateMachine? _updateMachine;
452462
set updateMachine(UpdateMachine? value) {
@@ -1024,12 +1034,7 @@ class UpdateMachine {
10241034
UpdateMachine.fromInitialSnapshot({
10251035
required this.store,
10261036
required InitialSnapshot initialSnapshot,
1027-
}) : queueId = initialSnapshot.queueId ?? (() {
1028-
// The queueId is optional in the type, but should only be missing in the
1029-
// case of unauthenticated access to a web-public realm. We authenticated.
1030-
throw Exception("bad initial snapshot: missing queueId");
1031-
})(),
1032-
lastEventId = initialSnapshot.lastEventId {
1037+
}) : lastEventId = initialSnapshot.lastEventId {
10331038
store.updateMachine = this;
10341039
}
10351040

@@ -1103,7 +1108,6 @@ class UpdateMachine {
11031108
}
11041109

11051110
final PerAccountStore store;
1106-
final String queueId;
11071111
int lastEventId;
11081112

11091113
bool _disposed = false;
@@ -1253,7 +1257,7 @@ class UpdateMachine {
12531257
final GetEventsResult result;
12541258
try {
12551259
result = await getEvents(store.connection,
1256-
queueId: queueId, lastEventId: lastEventId);
1260+
queueId: store.queueId, lastEventId: lastEventId);
12571261
if (_disposed) return;
12581262
} catch (e, stackTrace) {
12591263
if (_disposed) return;

test/model/store_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ void main() {
782782
..method.equals('GET')
783783
..url.path.equals('/api/v1/events')
784784
..url.queryParameters.deepEquals({
785-
'queue_id': updateMachine.queueId,
785+
'queue_id': store.queueId,
786786
'last_event_id': lastEventId.toString(),
787787
});
788788
}
@@ -947,7 +947,7 @@ void main() {
947947

948948
void prepareExpiredEventQueue() {
949949
connection.prepare(apiException: eg.apiExceptionBadEventQueueId(
950-
queueId: updateMachine.queueId));
950+
queueId: store.queueId));
951951
}
952952

953953
Future<void> prepareHandleEventError() async {

test/widgets/message_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void main() {
161161
updateMachine.poll();
162162

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

0 commit comments

Comments
 (0)