Merge pull request #552 from GetStream/remove-sync

fix: sync events only in case persistence is enabled
This commit is contained in:
Salvatore Giordano
2021-07-16 17:19:28 +02:00
committed by GitHub
2 changed files with 20 additions and 14 deletions
@@ -426,7 +426,10 @@ class StreamChatClient {
await queryChannelsOnline( await queryChannelsOnline(
filter: Filter.in_('cid', cids), filter: Filter.in_('cid', cids),
paginationParams: const PaginationParams(limit: 30), paginationParams: const PaginationParams(limit: 30),
).then((_) => sync(cids: cids, lastSyncAt: _lastSyncedAt)); );
if (persistenceEnabled) {
await sync(cids: cids, lastSyncAt: _lastSyncedAt);
}
} }
handleEvent(Event( handleEvent(Event(
type: EventType.connectionRecovered, type: EventType.connectionRecovered,
@@ -296,15 +296,15 @@ void main() {
await tester.runAsync(() async { await tester.runAsync(() async {
final mockClient = MockClient(); final mockClient = MockClient();
final mockOnBackgroundEventReceived = MockOnBackgroundEventReceived(); final mockOnBackgroundEventReceived = MockOnBackgroundEventReceived();
const backgroundKeepAlive = const Duration(seconds: 3); const backgroundKeepAlive = Duration(seconds: 3);
const streamChatCoreKey = Key('streamChatCore'); const streamChatCoreKey = Key('streamChatCore');
const childKey = Key('child'); const childKey = Key('child');
final streamChatCore = StreamChatCore( final streamChatCore = StreamChatCore(
key: streamChatCoreKey, key: streamChatCoreKey,
client: mockClient, client: mockClient,
child: Offstage(key: childKey),
onBackgroundEventReceived: mockOnBackgroundEventReceived, onBackgroundEventReceived: mockOnBackgroundEventReceived,
backgroundKeepAlive: backgroundKeepAlive, backgroundKeepAlive: backgroundKeepAlive,
child: const Offstage(key: childKey),
); );
await tester.pumpWidget(streamChatCore); await tester.pumpWidget(streamChatCore);
@@ -313,12 +313,13 @@ void main() {
expect(find.byKey(childKey), findsOneWidget); expect(find.byKey(childKey), findsOneWidget);
final event = Event(type: EventType.any); final event = Event(type: EventType.any);
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event)); when(mockClient.on).thenAnswer((_) => Stream.value(event));
final streamChatCoreState = tester.state<StreamChatCoreState>( final streamChatCoreState = tester.state<StreamChatCoreState>(
find.byKey(streamChatCoreKey), find.byKey(streamChatCoreKey),
); );
// ignore: cascade_invocations
streamChatCoreState streamChatCoreState
.didChangeAppLifecycleState(AppLifecycleState.paused); .didChangeAppLifecycleState(AppLifecycleState.paused);
@@ -346,8 +347,8 @@ void main() {
final streamChatCore = StreamChatCore( final streamChatCore = StreamChatCore(
key: streamChatCoreKey, key: streamChatCoreKey,
client: mockClient, client: mockClient,
child: Offstage(key: childKey),
connectivityStream: Stream.value(ConnectivityResult.mobile), connectivityStream: Stream.value(ConnectivityResult.mobile),
child: const Offstage(key: childKey),
); );
await tester.pumpWidget(streamChatCore); await tester.pumpWidget(streamChatCore);
@@ -356,10 +357,10 @@ void main() {
expect(find.byKey(childKey), findsOneWidget); expect(find.byKey(childKey), findsOneWidget);
final event = Event(type: EventType.any); final event = Event(type: EventType.any);
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event)); when(mockClient.on).thenAnswer((_) => Stream.value(event));
when(() => mockClient.openConnection()) when(mockClient.openConnection)
.thenAnswer((_) async => OwnUser(id: 'test')); .thenAnswer((_) async => OwnUser(id: 'test'));
when(() => mockClient.closeConnection()).thenAnswer((_) async => null); when(mockClient.closeConnection).thenAnswer((_) async {});
when(() => mockClient.wsConnectionStatus) when(() => mockClient.wsConnectionStatus)
.thenReturn(ConnectionStatus.disconnected); .thenReturn(ConnectionStatus.disconnected);
@@ -367,6 +368,7 @@ void main() {
find.byKey(streamChatCoreKey), find.byKey(streamChatCoreKey),
); );
// ignore: cascade_invocations
streamChatCoreState streamChatCoreState
.didChangeAppLifecycleState(AppLifecycleState.paused); .didChangeAppLifecycleState(AppLifecycleState.paused);
@@ -375,7 +377,7 @@ void main() {
streamChatCoreState streamChatCoreState
.didChangeAppLifecycleState(AppLifecycleState.inactive); .didChangeAppLifecycleState(AppLifecycleState.inactive);
verify(() => mockClient.openConnection()).called(1); verify(mockClient.openConnection).called(1);
}); });
}, },
); );
@@ -391,18 +393,18 @@ void main() {
const childKey = Key('child'); const childKey = Key('child');
final event = Event(); final event = Event();
when(() => mockClient.on()).thenAnswer((_) => Stream.value(event)); when(mockClient.on).thenAnswer((_) => Stream.value(event));
when(() => mockClient.openConnection()) when(mockClient.openConnection)
.thenAnswer((_) async => OwnUser(id: 'test')); .thenAnswer((_) async => OwnUser(id: 'test'));
when(() => mockClient.closeConnection()).thenAnswer((_) async => null); when(mockClient.closeConnection).thenAnswer((_) async {});
when(() => mockClient.wsConnectionStatus) when(() => mockClient.wsConnectionStatus)
.thenReturn(ConnectionStatus.disconnected); .thenReturn(ConnectionStatus.disconnected);
final streamChatCore = StreamChatCore( final streamChatCore = StreamChatCore(
key: streamChatCoreKey, key: streamChatCoreKey,
client: mockClient, client: mockClient,
child: Offstage(key: childKey),
connectivityStream: Stream.value(ConnectivityResult.none), connectivityStream: Stream.value(ConnectivityResult.none),
child: const Offstage(key: childKey),
); );
await tester.pumpWidget(streamChatCore); await tester.pumpWidget(streamChatCore);
@@ -414,6 +416,7 @@ void main() {
find.byKey(streamChatCoreKey), find.byKey(streamChatCoreKey),
); );
// ignore: cascade_invocations
streamChatCoreState streamChatCoreState
.didChangeAppLifecycleState(AppLifecycleState.paused); .didChangeAppLifecycleState(AppLifecycleState.paused);
@@ -422,7 +425,7 @@ void main() {
streamChatCoreState streamChatCoreState
.didChangeAppLifecycleState(AppLifecycleState.inactive); .didChangeAppLifecycleState(AppLifecycleState.inactive);
verifyNever(() => mockClient.openConnection()); verifyNever(mockClient.openConnection);
}); });
}, },
); );