fix(mobile): show memories right after the first login (#33030)
This commit is contained in:
1 parent
d25a353d94
commit
06c41fdcac
3 files changed
+28
-1
No files matched your search
@@ -93,6 +93,10 @@ class MemoryRepository extends DatabaseAccessor<Drift> with $MemoryRepositoryMix
|
||||
Future<int> getCount() {
|
||||
return _db.managers.memoryEntity.count();
|
||||
}
|
||||
|
||||
Stream<void> watchChanges() {
|
||||
return _db.tableUpdates(TableUpdateQuery.onAllTables([_db.memoryEntity, _db.memoryAssetEntity]));
|
||||
}
|
||||
}
|
||||
|
||||
extension on MemoryEntityData {
|
||||
|
||||
@@ -17,7 +17,11 @@ final memoryLaneProvider = FutureProvider.autoDispose<List<Memory>>((ref) {
|
||||
final timer = Timer(nextMidnight.difference(now) + const Duration(seconds: 5), ref.invalidateSelf);
|
||||
ref.onDispose(timer.cancel);
|
||||
|
||||
final service = MemoryService(ref.watch(driftProvider).memoryRepository);
|
||||
final repository = ref.watch(driftProvider).memoryRepository;
|
||||
final subscription = repository.watchChanges().listen((_) => ref.invalidateSelf());
|
||||
ref.onDispose(subscription.cancel);
|
||||
|
||||
final service = MemoryService(repository);
|
||||
return service.getMemoryLane(userId);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:fake_async/fake_async.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -48,6 +50,7 @@ void main() {
|
||||
userService = MockUserService();
|
||||
|
||||
when(() => memoryRepository.getAll('user-1')).thenAnswer((_) async => []);
|
||||
when(() => memoryRepository.watchChanges()).thenAnswer((_) => const Stream.empty());
|
||||
when(() => userService.tryGetMyUser()).thenReturn(user());
|
||||
when(() => userService.watchMyUser()).thenAnswer((_) => const Stream.empty());
|
||||
});
|
||||
@@ -71,6 +74,22 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
test('re-queries when the memory tables change', () {
|
||||
fakeAsync((async) {
|
||||
final changes = StreamController<void>.broadcast();
|
||||
when(() => memoryRepository.watchChanges()).thenAnswer((_) => changes.stream);
|
||||
final container = makeContainer();
|
||||
container.listen(memoryLaneProvider, (_, _) {});
|
||||
async.flushMicrotasks();
|
||||
verify(() => memoryRepository.getAll('user-1')).called(1);
|
||||
|
||||
changes.add(null);
|
||||
async.elapse(Duration.zero);
|
||||
verify(() => memoryRepository.getAll('user-1')).called(1);
|
||||
unawaited(changes.close());
|
||||
});
|
||||
});
|
||||
|
||||
test('cancels the midnight timer when disposed', () {
|
||||
fakeAsync((async) {
|
||||
final container = makeContainer();
|
||||
|
||||
Reference in new issue
Block a user