diff --git a/lib/features/thread/data/repository/thread_repository_impl.dart b/lib/features/thread/data/repository/thread_repository_impl.dart index 0c72b2f90..15f8a91a7 100644 --- a/lib/features/thread/data/repository/thread_repository_impl.dart +++ b/lib/features/thread/data/repository/thread_repository_impl.dart @@ -83,6 +83,7 @@ class ThreadRepositoryImpl extends ThreadRepository { session, accountId, sort: sort, + limit: limit, position: position, mailboxId: emailFilter?.mailboxId, propertiesCreated: propertiesCreated, @@ -187,6 +188,16 @@ class ThreadRepositoryImpl extends ThreadRepository { 'Server email count = $serverCount', ); + if (serverCount > 0 || + (serverResponse.notFoundEmailIds?.isNotEmpty ?? false)) { + await _updateEmailCache( + accountId, + session.username, + newCreated: serverResponse.emailList, + newDestroyed: serverResponse.notFoundEmailIds, + ); + } + // Combine server list + keep existing state yield EmailsResponse( emailList: serverResponse.emailList, @@ -203,6 +214,7 @@ class ThreadRepositoryImpl extends ThreadRepository { AccountId accountId, { Set? sort, + UnsignedInt? limit, int? position, MailboxId? mailboxId, Properties? propertiesCreated, @@ -212,7 +224,7 @@ class ThreadRepositoryImpl extends ThreadRepository { final networkEmailResponse = await mapDataSource[DataSourceType.network]!.getAllEmail( session, accountId, - limit: ThreadConstants.defaultLimit, + limit: limit ?? ThreadConstants.defaultLimit, position: position, sort: sort, filter: filter ?? EmailFilterCondition(inMailbox: mailboxId), @@ -323,6 +335,7 @@ class ThreadRepositoryImpl extends ThreadRepository { jmap.State currentState, { Set? sort, + UnsignedInt? limit, EmailFilter? emailFilter, Properties? propertiesCreated, Properties? propertiesUpdated, @@ -343,19 +356,26 @@ class ThreadRepositoryImpl extends ThreadRepository { session.username, inMailboxId: emailFilter?.mailboxId, sort: sort, - filterOption: emailFilter?.filterOption + limit: limit, + filterOption: emailFilter?.filterOption, ), stateDataSource.getState(accountId, session.username, StateType.email) ]).then((List response) { return EmailsResponse(emailList: response.first, state: response.last); }); + final currentLimitEmails = + limit?.value ?? ThreadConstants.defaultLimit.value; + + log('ThreadRepositoryImpl::refreshChanges: Current limit emails is $currentLimitEmails'); + if (!newEmailResponse.hasEmails() - || (newEmailResponse.emailList?.length ?? 0) < ThreadConstants.defaultLimit.value) { + || (newEmailResponse.emailList?.length ?? 0) < currentLimitEmails) { final networkEmailResponse = await _getFirstPage( session, accountId, sort: sort, + limit: limit, filter: emailFilter?.filter, mailboxId: emailFilter?.mailboxId, propertiesCreated: propertiesCreated, diff --git a/lib/features/thread/domain/repository/thread_repository.dart b/lib/features/thread/domain/repository/thread_repository.dart index c4f381bca..f3a061cc6 100644 --- a/lib/features/thread/domain/repository/thread_repository.dart +++ b/lib/features/thread/domain/repository/thread_repository.dart @@ -59,6 +59,7 @@ abstract class ThreadRepository { jmap.State currentState, { Set? sort, + UnsignedInt? limit, EmailFilter? emailFilter, Properties? propertiesCreated, Properties? propertiesUpdated, diff --git a/lib/features/thread/domain/usecases/refresh_changes_emails_in_mailbox_interactor.dart b/lib/features/thread/domain/usecases/refresh_changes_emails_in_mailbox_interactor.dart index afa4200f3..3d9d2da59 100644 --- a/lib/features/thread/domain/usecases/refresh_changes_emails_in_mailbox_interactor.dart +++ b/lib/features/thread/domain/usecases/refresh_changes_emails_in_mailbox_interactor.dart @@ -4,6 +4,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; import 'package:jmap_dart_client/jmap/core/sort/comparator.dart'; +import 'package:jmap_dart_client/jmap/core/unsigned_int.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:tmail_ui_user/features/thread/domain/model/email_filter.dart'; import 'package:tmail_ui_user/features/thread/domain/model/email_response.dart'; @@ -23,6 +24,7 @@ class RefreshChangesEmailsInMailboxInteractor { jmap.State currentState, { Set? sort, + UnsignedInt? limit, Properties? propertiesCreated, Properties? propertiesUpdated, EmailFilter? emailFilter, @@ -37,6 +39,7 @@ class RefreshChangesEmailsInMailboxInteractor { accountId, currentState, sort: sort, + limit: limit, propertiesCreated: propertiesCreated, propertiesUpdated: propertiesUpdated, emailFilter: emailFilter) diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index 60daa4d5b..fd857d207 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -719,6 +719,7 @@ class ThreadController extends BaseController with EmailActionController { _accountId!, mailboxDashBoardController.currentEmailState!, sort: EmailSortOrderType.mostRecent.getSortOrder().toNullable(), + limit: limitEmailFetched, propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod( _session!, _accountId!, diff --git a/test/features/search/verify_before_time_in_search_email_filter_test.dart b/test/features/search/verify_before_time_in_search_email_filter_test.dart index ddda2d9cd..f36c07c2e 100644 --- a/test/features/search/verify_before_time_in_search_email_filter_test.dart +++ b/test/features/search/verify_before_time_in_search_email_filter_test.dart @@ -822,6 +822,7 @@ void main() { any, any, sort: anyNamed('sort'), + limit: anyNamed('limit'), propertiesCreated: anyNamed('propertiesCreated'), propertiesUpdated: anyNamed('propertiesUpdated'), emailFilter: anyNamed('emailFilter'), @@ -851,6 +852,7 @@ void main() { AccountFixtures.aliceAccountId, mailboxDashboardController.currentEmailState!, sort: EmailSortOrderType.mostRecent.getSortOrder().toNullable(), + limit: threadController.limitEmailFetched, propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod( SessionFixtures.aliceSession, AccountFixtures.aliceAccountId, @@ -986,6 +988,7 @@ void main() { any, any, sort: anyNamed('sort'), + limit: anyNamed('limit'), propertiesCreated: anyNamed('propertiesCreated'), propertiesUpdated: anyNamed('propertiesUpdated'), emailFilter: anyNamed('emailFilter'), @@ -1015,6 +1018,7 @@ void main() { AccountFixtures.aliceAccountId, mailboxDashboardController.currentEmailState!, sort: EmailSortOrderType.mostRecent.getSortOrder().toNullable(), + limit: threadController.limitEmailFetched, propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod( SessionFixtures.aliceSession, AccountFixtures.aliceAccountId, @@ -1095,6 +1099,7 @@ void main() { any, any, sort: anyNamed('sort'), + limit: anyNamed('limit'), propertiesCreated: anyNamed('propertiesCreated'), propertiesUpdated: anyNamed('propertiesUpdated'), emailFilter: anyNamed('emailFilter'), @@ -1124,6 +1129,7 @@ void main() { AccountFixtures.aliceAccountId, mailboxDashboardController.currentEmailState!, sort: EmailSortOrderType.mostRecent.getSortOrder().toNullable(), + limit: threadController.limitEmailFetched, propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod( SessionFixtures.aliceSession, AccountFixtures.aliceAccountId, diff --git a/test/features/thread/presentation/controller/thread_controller_test.dart b/test/features/thread/presentation/controller/thread_controller_test.dart index 62ae6318a..5da43ea79 100644 --- a/test/features/thread/presentation/controller/thread_controller_test.dart +++ b/test/features/thread/presentation/controller/thread_controller_test.dart @@ -316,6 +316,7 @@ void main() { any, any, sort: anyNamed('sort'), + limit: anyNamed('limit'), propertiesCreated: anyNamed('propertiesCreated'), propertiesUpdated: anyNamed('propertiesUpdated'), emailFilter: anyNamed('emailFilter'),