Merge pull request #1407 from GetStream/fix/lastSyncedDateInitialization
fix(llc): initializing last synced data
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
## Upcomming
|
||||||
|
|
||||||
|
🐞 Fixed
|
||||||
|
- Fixed initializing last synced date.
|
||||||
|
|
||||||
## 5.1.0
|
## 5.1.0
|
||||||
|
|
||||||
✅ Added
|
✅ Added
|
||||||
|
|||||||
@@ -453,6 +453,15 @@ class StreamChatClient {
|
|||||||
if (persistenceEnabled) {
|
if (persistenceEnabled) {
|
||||||
await sync(cids: cids, lastSyncAt: _lastSyncedAt);
|
await sync(cids: cids, lastSyncAt: _lastSyncedAt);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// channels are empty, assuming it's a fresh start
|
||||||
|
// and making sure `lastSyncAt` is initialized
|
||||||
|
if (persistenceEnabled) {
|
||||||
|
final lastSyncAt = await _chatPersistenceClient?.getLastSyncAt();
|
||||||
|
if (lastSyncAt == null) {
|
||||||
|
await _chatPersistenceClient?.updateLastSyncAt(DateTime.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleEvent(Event(
|
handleEvent(Event(
|
||||||
type: EventType.connectionRecovered,
|
type: EventType.connectionRecovered,
|
||||||
|
|||||||
@@ -516,6 +516,9 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
|
when(() => persistence.updateLastSyncAt(any()))
|
||||||
|
.thenAnswer((_) => Future.value());
|
||||||
|
when(persistence.getLastSyncAt).thenAnswer((_) async => null);
|
||||||
client = StreamChatClient(apiKey, chatApi: api, ws: ws)
|
client = StreamChatClient(apiKey, chatApi: api, ws: ws)
|
||||||
..chatPersistenceClient = persistence;
|
..chatPersistenceClient = persistence;
|
||||||
await client.connectUser(user, token);
|
await client.connectUser(user, token);
|
||||||
@@ -532,9 +535,12 @@ void main() {
|
|||||||
test(
|
test(
|
||||||
'''should update persistence connectionInfo and lastSync when sync succeeds''',
|
'''should update persistence connectionInfo and lastSync when sync succeeds''',
|
||||||
() async {
|
() async {
|
||||||
|
// persistence.updateLastSyncAt might be called
|
||||||
|
// when connecting the user.
|
||||||
|
// Resetting the logs so we start counting invocations correctly.
|
||||||
|
reset(persistence);
|
||||||
const cids = ['test-cid-1', 'test-cid-2', 'test-cid-3'];
|
const cids = ['test-cid-1', 'test-cid-2', 'test-cid-3'];
|
||||||
final lastSyncAt = DateTime.now();
|
final lastSyncAt = DateTime.now();
|
||||||
|
|
||||||
when(() => api.general.sync(cids, lastSyncAt))
|
when(() => api.general.sync(cids, lastSyncAt))
|
||||||
.thenAnswer((_) async => SyncResponse()
|
.thenAnswer((_) async => SyncResponse()
|
||||||
..events = [
|
..events = [
|
||||||
@@ -567,6 +573,10 @@ void main() {
|
|||||||
test(
|
test(
|
||||||
'should work fine if persistence contains sync params',
|
'should work fine if persistence contains sync params',
|
||||||
() async {
|
() async {
|
||||||
|
// persistence.updateLastSyncAt might be called
|
||||||
|
// when connecting the user.
|
||||||
|
// Resetting the logs so we start counting invocations correctly.
|
||||||
|
reset(persistence);
|
||||||
const cids = ['test-cid-1', 'test-cid-2', 'test-cid-3'];
|
const cids = ['test-cid-1', 'test-cid-2', 'test-cid-3'];
|
||||||
final lastSyncAt = DateTime.now();
|
final lastSyncAt = DateTime.now();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user