Skip to content

Commit 391167b

Browse files
committed
store: Add field for tracking loading status.
When an error occurs to a getEvents call, there isn't a visual indicator for the retry attempts. This prepares the data model for the feature. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 1964388 commit 391167b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/model/store.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
295295
final GlobalStore _globalStore;
296296
final ApiConnection connection; // TODO(#135): update zulipFeatureLevel with events
297297

298+
bool get isLoading => _isLoading;
299+
bool _isLoading = false;
300+
@visibleForTesting
301+
set isLoading(bool value) {
302+
if (_isLoading == value) return;
303+
_isLoading = value;
304+
notifyListeners();
305+
}
306+
298307
////////////////////////////////
299308
// Data attached to the realm or the server.
300309

@@ -766,6 +775,7 @@ class UpdateMachine {
766775
result = await getEvents(store.connection,
767776
queueId: queueId, lastEventId: lastEventId);
768777
} catch (e) {
778+
store.isLoading = true;
769779
switch (e) {
770780
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
771781
assert(debugLog('Lost event queue for $store. Replacing…'));
@@ -793,6 +803,7 @@ class UpdateMachine {
793803
}
794804
}
795805

806+
store.isLoading = false;
796807
final events = result.events;
797808
for (final event in events) {
798809
await store.handleEvent(event);

test/model/store_checks.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extension GlobalStoreChecks on Subject<GlobalStore> {
2828

2929
extension PerAccountStoreChecks on Subject<PerAccountStore> {
3030
Subject<ApiConnection> get connection => has((x) => x.connection, 'connection');
31+
Subject<bool> get isLoading => has((x) => x.isLoading, 'isLoading');
3132
Subject<Uri> get realmUrl => has((x) => x.realmUrl, 'realmUrl');
3233
Subject<String> get zulipVersion => has((x) => x.zulipVersion, 'zulipVersion');
3334
Subject<int> get maxFileUploadSizeMib => has((x) => x.maxFileUploadSizeMib, 'maxFileUploadSizeMib');

test/model/store_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,12 @@ void main() {
406406
updateMachine.debugAdvanceLoop();
407407
async.flushMicrotasks();
408408
await Future<void>.delayed(Duration.zero);
409+
check(store).isLoading.isTrue();
409410

410411
// The global store has a new store.
411412
check(globalStore.perAccountSync(store.accountId)).not((it) => it.identicalTo(store));
412413
updateFromGlobalStore();
414+
check(store).isLoading.isFalse();
413415

414416
// The new UpdateMachine updates the new store.
415417
updateMachine.debugPauseLoop();
@@ -435,8 +437,9 @@ void main() {
435437
// Make the request, inducing an error in it.
436438
prepareError();
437439
updateMachine.debugAdvanceLoop();
438-
async.flushMicrotasks();
440+
async.elapse(Duration.zero);
439441
checkLastRequest(lastEventId: 1);
442+
check(store).isLoading.isTrue();
440443

441444
// Polling doesn't resume immediately; there's a timer.
442445
check(async.pendingTimers).length.equals(1);
@@ -452,6 +455,7 @@ void main() {
452455
async.flushTimers();
453456
checkLastRequest(lastEventId: 1);
454457
check(updateMachine.lastEventId).equals(2);
458+
check(store).isLoading.isFalse();
455459
});
456460
}
457461

0 commit comments

Comments
 (0)