Skip to content

Commit

Permalink
fix: fix offset logic from RPC to prevent duplicated items from being…
Browse files Browse the repository at this point in the history
… fetched and improve async logic
  • Loading branch information
brenodt authored and MathJud committed Nov 17, 2022
1 parent 524fd22 commit 1a9ca6d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions qaul_ui/packages/qaul_rpc/lib/src/libqaul_worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,22 @@ class LibqaulWorker {
}

Future<List<FileHistoryEntity>> getFileHistory(
{int? page = 0, int? itemsPerPage = 20}) async {
{int page = 0, int itemsPerPage = 20}) async {
Future<void> sendFileHistoryRequest() async {
final msg = ChatFile(
fileHistory: FileHistoryRequest(offset: page, limit: itemsPerPage),
);
fileHistory: FileHistoryRequest(
offset: page * itemsPerPage,
limit: itemsPerPage,
));
await _sendMessage(Modules.CHATFILE, msg);
}

List<FileHistoryEntity> newItems = [];
try {
await sendFileHistoryRequest();

for (var i = 0; i < 5; i++) {
await sendFileHistoryRequest();
await Future.delayed(Duration(milliseconds: (i + 1) * 10));
await Future.delayed(Duration(milliseconds: (i + 1) * 500));
newItems = _reader(fileHistoryEntitiesProvider);
if (newItems.isNotEmpty) break;
}
Expand Down

0 comments on commit 1a9ca6d

Please sign in to comment.