fix(persistence): fix offline message pagination (#1361)
* fix(persistence): fix offline message pagination * chore(persistence): update changelog * fix(persistence): fix pagination offline * fix test
This commit is contained in:
committed by
GitHub
parent
9369defe11
commit
5784c53e6b
@@ -2,6 +2,10 @@
|
||||
|
||||
- Reintroduce support for experimental indexedDB on Web.
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
- Fix offline message pagination.
|
||||
|
||||
## 5.0.0
|
||||
|
||||
- Included the changes from version [4.3.0](#430) and [4.4.0](#440).
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:stream_chat_persistence/src/db/drift_chat_database.dart';
|
||||
@@ -170,7 +172,9 @@ class MessageDao extends DatabaseAccessor<DriftChatDatabase>
|
||||
}
|
||||
}
|
||||
if (messagePagination?.limit != null) {
|
||||
return msgList.take(messagePagination!.limit).toList();
|
||||
return msgList
|
||||
.skip(max(0, msgList.length - messagePagination!.limit))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
return msgList;
|
||||
|
||||
@@ -382,8 +382,8 @@ void main() {
|
||||
messagePagination: pagination,
|
||||
);
|
||||
expect(fetchedMessages.length, limit);
|
||||
expect(fetchedMessages.first.id, greaterThanOrEqual);
|
||||
expect(fetchedMessages.last.id != lessThan, true);
|
||||
expect(fetchedMessages.last.id, 'testMessageId${cid}24');
|
||||
expect(fetchedMessages.first.id != lessThan, true);
|
||||
});
|
||||
|
||||
test('updateMessages', () async {
|
||||
|
||||
Reference in New Issue
Block a user