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) properties: emailRequest.properties)
.then((response) { .then((response) {
var listEmails = response.emailList; 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); return EmailsResponse(emailList: listEmails, state: response.state);
}); });
@@ -454,6 +454,7 @@ class ThreadController extends BaseController {
} }
void loadMoreEmails() { void loadMoreEmails() {
log('ThreadController::loadMoreEmails()');
if (canLoadMore && _accountId != null) { if (canLoadMore && _accountId != null) {
startFpsMeter(); startFpsMeter();
consumeState(_loadMoreEmailsInMailboxInteractor.execute( consumeState(_loadMoreEmailsInMailboxInteractor.execute(
@@ -469,15 +470,21 @@ class ThreadController extends BaseController {
} }
} }
bool _ableAppendLoadMore(List<PresentationEmail> listEmail) { bool _belongToCurrentMailboxId(PresentationEmail email) {
return !(listEmail.where((email) => (email.mailboxIds != null && !email.mailboxIds!.keys.contains(currentMailbox?.id)) || emailList.contains(email)).isNotEmpty); 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) { void _loadMoreEmailsSuccess(LoadMoreEmailsSuccess success) {
if (success.emailList.isNotEmpty) { if (success.emailList.isNotEmpty) {
if (_ableAppendLoadMore(success.emailList)){ final appendableList = success.emailList
emailList.addAll(success.emailList); .where(_belongToCurrentMailboxId)
} .where(_notDuplicatedInCurrentList);
emailList.addAll(appendableList);
} else { } else {
canLoadMore = false; canLoadMore = false;
} }