Skip to content

Commit

Permalink
TF-3025 Avoid search results being reloaded when performing certain a…
Browse files Browse the repository at this point in the history
…ctions `read/star/...`
  • Loading branch information
dab246 authored and hoangdat committed Oct 14, 2024
1 parent f54c612 commit 2e0026b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/features/thread/domain/state/search_email_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:model/email/presentation_email.dart';

class SearchingState extends LoadingState {}

class RefreshingSearchState extends LoadingState {}

class SearchEmailSuccess extends UIState {
final List<PresentationEmail> emailList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ class SearchEmailInteractor {
Set<Comparator>? sort,
Filter? filter,
Properties? properties,
bool isRefreshChange = false,
}
) async* {
try {
yield Right(SearchingState());
if (isRefreshChange) {
yield Right(RefreshingSearchState());
} else {
yield Right(SearchingState());
}

final emailList = await threadRepository.searchEmails(
session,
Expand Down
11 changes: 7 additions & 4 deletions lib/features/thread/presentation/thread_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class ThreadController extends BaseController with EmailActionController {
void _refreshEmailChanges({jmap.State? currentEmailState}) {
log('ThreadController::_refreshEmailChanges(): currentEmailState: $currentEmailState');
if (searchController.isSearchEmailRunning) {
_searchEmail(limit: limitEmailFetched);
_searchEmail(limit: limitEmailFetched, isRefreshChange: true);
} else {
final newEmailState = currentEmailState ?? _currentEmailState;
log('ThreadController::_refreshEmailChanges(): newEmailState: $newEmailState');
Expand Down Expand Up @@ -802,12 +802,14 @@ class ThreadController extends BaseController with EmailActionController {
searchController.clearTextSearch();
}

void _searchEmail({UnsignedInt? limit}) {
void _searchEmail({UnsignedInt? limit, bool isRefreshChange = false}) {
if (_session != null && _accountId != null) {
if (listEmailController.hasClients) {
if (!isRefreshChange && listEmailController.hasClients) {
listEmailController.jumpTo(0);
}
mailboxDashBoardController.emailsInCurrentMailbox.clear();
if (!isRefreshChange) {
mailboxDashBoardController.emailsInCurrentMailbox.clear();
}
canSearchMore = false;

searchController.updateFilterEmail(
Expand All @@ -826,6 +828,7 @@ class ThreadController extends BaseController with EmailActionController {
moreFilterCondition: _getFilterCondition()
),
properties: EmailUtils.getPropertiesForEmailGetMethod(_session!, _accountId!),
isRefreshChange: isRefreshChange
));
} else {
consumeState(Stream.value(Left(SearchEmailFailure(NotFoundSessionException()))));
Expand Down

0 comments on commit 2e0026b

Please sign in to comment.