Skip to content

Commit 3aaf30b

Browse files
committed
snackbar:show snackabr when isstale is true
1 parent e050643 commit 3aaf30b

File tree

5 files changed

+227
-428
lines changed

5 files changed

+227
-428
lines changed

lib/lib/model/store.dart

Whitespace-only changes.

lib/model/store.dart

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export 'database.dart' show Account, AccountsCompanion, AccountAlreadyExistsExce
4545
/// we use outside of tests.
4646
abstract class GlobalStore extends ChangeNotifier {
4747
GlobalStore({required Iterable<Account> accounts})
48-
: _accounts = Map.fromEntries(accounts.map((a) => MapEntry(a.id, a)));
48+
: _accounts = Map.fromEntries(accounts.map((a) => MapEntry(a.id, a)));
4949

5050
/// A cache of the [Accounts] table in the underlying data store.
5151
final Map<int, Account> _accounts;
@@ -67,8 +67,8 @@ abstract class GlobalStore extends ChangeNotifier {
6767

6868
ApiConnection apiConnectionFromAccount(Account account) {
6969
return apiConnection(
70-
realmUrl: account.realmUrl, zulipFeatureLevel: account.zulipFeatureLevel,
71-
email: account.email, apiKey: account.apiKey);
70+
realmUrl: account.realmUrl, zulipFeatureLevel: account.zulipFeatureLevel,
71+
email: account.email, apiKey: account.apiKey);
7272
}
7373

7474
final Map<int, PerAccountStore> _perAccountStores = {};
@@ -186,6 +186,7 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
186186
/// to `globalStore.apiConnectionFromAccount(account)`.
187187
/// When present, it should be a connection that came from that method call,
188188
/// but it may have already been used for other requests.
189+
bool isstale=true; // Drives the connecting snackbar
189190
factory PerAccountStore.fromInitialSnapshot({
190191
required GlobalStore globalStore,
191192
required int accountId,
@@ -208,18 +209,18 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
208209
selfUserId: account.userId,
209210
userSettings: initialSnapshot.userSettings,
210211
users: Map.fromEntries(
211-
initialSnapshot.realmUsers
212-
.followedBy(initialSnapshot.realmNonActiveUsers)
213-
.followedBy(initialSnapshot.crossRealmBots)
214-
.map((user) => MapEntry(user.userId, user))),
212+
initialSnapshot.realmUsers
213+
.followedBy(initialSnapshot.realmNonActiveUsers)
214+
.followedBy(initialSnapshot.crossRealmBots)
215+
.map((user) => MapEntry(user.userId, user))),
215216
streams: streams,
216217
unreads: Unreads(
217218
initial: initialSnapshot.unreadMsgs,
218219
selfUserId: account.userId,
219220
streamStore: streams,
220221
),
221222
recentDmConversationsView: RecentDmConversationsView(
222-
initial: initialSnapshot.recentPrivateConversations, selfUserId: account.userId),
223+
initial: initialSnapshot.recentPrivateConversations, selfUserId: account.userId),
223224
);
224225
}
225226

@@ -240,10 +241,10 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
240241
required this.unreads,
241242
required this.recentDmConversationsView,
242243
}) : assert(selfUserId == globalStore.getAccount(accountId)!.userId),
243-
assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
244-
assert(realmUrl == connection.realmUrl),
245-
_globalStore = globalStore,
246-
_streams = streams;
244+
assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
245+
assert(realmUrl == connection.realmUrl),
246+
_globalStore = globalStore,
247+
_streams = streams;
247248

248249
////////////////////////////////////////////////////////////////
249250
// Data.
@@ -298,7 +299,7 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
298299
Map<int, Subscription> get subscriptions => _streams.subscriptions;
299300
@override
300301
UserTopicVisibilityPolicy topicVisibilityPolicy(int streamId, String topic) =>
301-
_streams.topicVisibilityPolicy(streamId, topic);
302+
_streams.topicVisibilityPolicy(streamId, topic);
302303

303304
final StreamStoreImpl _streams;
304305

@@ -356,6 +357,7 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
356357
void handleEvent(Event event) {
357358
if (event is HeartbeatEvent) {
358359
assert(debugLog("server event: heartbeat"));
360+
isstale=false; // Dismiss the connecting snackbar
359361
} else if (event is RealmEmojiUpdateEvent) {
360362
assert(debugLog("server event: realm_emoji/update"));
361363
realmEmoji = event.realmEmoji;
@@ -526,11 +528,11 @@ class LiveGlobalStore extends GlobalStore {
526528

527529
@override
528530
ApiConnection apiConnection({
529-
required Uri realmUrl, required int? zulipFeatureLevel,
530-
String? email, String? apiKey}) {
531+
required Uri realmUrl, required int? zulipFeatureLevel,
532+
String? email, String? apiKey}) {
531533
return ApiConnection.live(
532-
realmUrl: realmUrl, zulipFeatureLevel: zulipFeatureLevel,
533-
email: email, apiKey: apiKey);
534+
realmUrl: realmUrl, zulipFeatureLevel: zulipFeatureLevel,
535+
email: email, apiKey: apiKey);
534536
}
535537

536538
// We keep the API simple and synchronous for the bulk of the app's code
@@ -591,11 +593,11 @@ class UpdateMachine {
591593
required this.store,
592594
required InitialSnapshot initialSnapshot,
593595
}) : queueId = initialSnapshot.queueId ?? (() {
594-
// The queueId is optional in the type, but should only be missing in the
595-
// case of unauthenticated access to a web-public realm. We authenticated.
596-
throw Exception("bad initial snapshot: missing queueId");
597-
})(),
598-
lastEventId = initialSnapshot.lastEventId;
596+
// The queueId is optional in the type, but should only be missing in the
597+
// case of unauthenticated access to a web-public realm. We authenticated.
598+
throw Exception("bad initial snapshot: missing queueId");
599+
})(),
600+
lastEventId = initialSnapshot.lastEventId;
599601

600602
/// Load the user's data from the server, and start an event queue going.
601603
///
@@ -616,7 +618,7 @@ class UpdateMachine {
616618
initialSnapshot: initialSnapshot,
617619
);
618620
final updateMachine = UpdateMachine.fromInitialSnapshot(
619-
store: store, initialSnapshot: initialSnapshot);
621+
store: store, initialSnapshot: initialSnapshot);
620622
updateMachine.poll();
621623
// TODO do registerNotificationToken before registerQueue:
622624
// https://github.com/zulip/zulip-flutter/pull/325#discussion_r1365982807
@@ -636,7 +638,7 @@ class UpdateMachine {
636638
return await registerQueue(connection);
637639
} catch (e) {
638640
assert(debugLog('Error fetching initial snapshot: $e\n'
639-
'Backing off, then will retry…'));
641+
'Backing off, then will retry…'));
640642
// TODO tell user if initial-fetch errors persist, or look non-transient
641643
await (backoffMachine ??= BackoffMachine()).wait();
642644
assert(debugLog('… Backoff wait complete, retrying initial fetch.'));
@@ -680,10 +682,11 @@ class UpdateMachine {
680682
final GetEventsResult result;
681683
try {
682684
result = await getEvents(store.connection,
683-
queueId: queueId, lastEventId: lastEventId);
685+
queueId: queueId, lastEventId: lastEventId);
684686
} catch (e) {
685687
switch (e) {
686688
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
689+
687690
assert(debugLog('Lost event queue for $store. Replacing…'));
688691
await store._globalStore._reloadPerAccount(store.accountId);
689692
dispose();
@@ -693,6 +696,7 @@ class UpdateMachine {
693696
case Server5xxException() || NetworkException():
694697
assert(debugLog('Transient error polling event queue for $store: $e\n'
695698
'Backing off, then will retry…'));
699+
store.isstale=true; // drives the connecting snackbar
696700
// TODO tell user if transient polling errors persist
697701
// TODO reset to short backoff eventually
698702
await backoffMachine.wait();

0 commit comments

Comments
 (0)