Skip to content

Commit bdb77c9

Browse files
committed
wip store: Update versions on RestartEvent; TODO test non-update case
1 parent 7b8a2f6 commit bdb77c9

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

lib/model/store.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,9 +874,18 @@ class PerAccountStore extends PerAccountStoreBase with
874874

875875
case RestartEvent():
876876
assert(debugLog("server event: restart"));
877-
// TODO(#135): update connection.zulipFeatureLevel
878-
// TODO(#135): update account with zulipVersion and zulipFeatureLevel
879-
// TODO(#135): replace event queue, if needed
877+
if (event.zulipVersion != account.zulipVersion
878+
|| event.zulipMergeBase != account.zulipMergeBase
879+
|| event.zulipFeatureLevel != account.zulipFeatureLevel) {
880+
// TODO(#135): replace event queue, if zulipFeatureLevel makes it necessary
881+
await _globalStore.updateAccount(accountId, AccountsCompanion(
882+
zulipVersion: Value(event.zulipVersion),
883+
zulipMergeBase: Value.absentIfNull(event.zulipMergeBase),
884+
zulipFeatureLevel: Value(event.zulipFeatureLevel),
885+
));
886+
connection.zulipFeatureLevel = event.zulipFeatureLevel;
887+
notifyListeners();
888+
}
880889

881890
case UnexpectedEvent():
882891
assert(debugLog("server event: ${jsonEncode(event.toJson())}")); // TODO log better

test/model/store_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:zulip/model/presence.dart';
2020
import 'package:zulip/model/server_support.dart';
2121
import 'package:zulip/model/store.dart';
2222

23+
import '../api/core_checks.dart';
2324
import '../api/fake_api.dart';
2425
import '../api/model/model_checks.dart';
2526
import '../example_data.dart' as eg;
@@ -465,6 +466,42 @@ void main() {
465466
// Mostly this method just dispatches to ChannelStore and MessageStore etc.,
466467
// and so its tests generally live in the test files for those
467468
// (but they call the handleEvent method because it's the entry point).
469+
470+
test('RestartEvent updates versions', () async {
471+
final account = eg.account(user: eg.selfUser,
472+
zulipFeatureLevel: 123,
473+
zulipMergeBase: '6.0',
474+
zulipVersion: '6.0+gabcd',
475+
);
476+
final globalStore = eg.globalStore();
477+
await globalStore.add(account, eg.initialSnapshot(
478+
zulipFeatureLevel: 123,
479+
zulipMergeBase: '6.0',
480+
zulipVersion: '6.0+gabcd',
481+
));
482+
final store = await globalStore.perAccount(account.id);
483+
484+
int globalUpdateCount = 0;
485+
globalStore.addListener(() => globalUpdateCount++);
486+
int updateCount = 0;
487+
store.addListener(() => updateCount++);
488+
489+
await store.handleEvent(RestartEvent(
490+
id: 1,
491+
zulipVersion: '8.0+g9876',
492+
zulipMergeBase: '8.0',
493+
zulipFeatureLevel: 234,
494+
serverGeneration: 1708639638,
495+
));
496+
check(globalUpdateCount).isGreaterThan(0);
497+
check(updateCount).isGreaterThan(0);
498+
check(store)
499+
..account.which((account) => account
500+
..zulipVersion.equals('8.0+g9876')
501+
..zulipMergeBase.equals('8.0')
502+
..zulipFeatureLevel.equals(234))
503+
..connection.zulipFeatureLevel.equals(234);
504+
});
468505
});
469506

470507
group('UpdateMachine.load', () {

0 commit comments

Comments
 (0)