TF-1045 Remove wrong conditions to append more items after loading more

This commit is contained in:
Dat PHAM HOANG
2022-10-05 16:40:18 +07:00
committed by Dat H. Pham
parent 776dbf749e
commit a363435de2
2 changed files with 12 additions and 8 deletions
@@ -244,9 +244,6 @@ class ThreadRepositoryImpl extends ThreadRepository {
properties: emailRequest.properties)
.then((response) {
var listEmails = response.emailList;
if (listEmails != null && listEmails.isNotEmpty) {
listEmails = listEmails.where((email) => email.id != emailRequest.lastEmailId).toList();
}
return EmailsResponse(emailList: listEmails, state: response.state);
});
@@ -454,6 +454,7 @@ class ThreadController extends BaseController {
}
void loadMoreEmails() {
log('ThreadController::loadMoreEmails()');
if (canLoadMore && _accountId != null) {
startFpsMeter();
consumeState(_loadMoreEmailsInMailboxInteractor.execute(
@@ -469,15 +470,21 @@ class ThreadController extends BaseController {
}
}
bool _ableAppendLoadMore(List<PresentationEmail> listEmail) {
return !(listEmail.where((email) => (email.mailboxIds != null && !email.mailboxIds!.keys.contains(currentMailbox?.id)) || emailList.contains(email)).isNotEmpty);
bool _belongToCurrentMailboxId(PresentationEmail email) {
return (email.mailboxIds != null && email.mailboxIds!.keys.contains(currentMailbox?.id));
}
bool _notDuplicatedInCurrentList(PresentationEmail email) {
return emailList.isEmpty || !emailList.map((element) => element.id).contains(email.id);
}
void _loadMoreEmailsSuccess(LoadMoreEmailsSuccess success) {
if (success.emailList.isNotEmpty) {
if (_ableAppendLoadMore(success.emailList)){
emailList.addAll(success.emailList);
}
final appendableList = success.emailList
.where(_belongToCurrentMailboxId)
.where(_notDuplicatedInCurrentList);
emailList.addAll(appendableList);
} else {
canLoadMore = false;
}