Skip to content

Commit

Permalink
TF-3292 Fix [SEARCH] If I filter emails by date and then sort them by…
Browse files Browse the repository at this point in the history
… relevance, the filter isn't applied
  • Loading branch information
dab246 committed Nov 26, 2024
1 parent d339dd8 commit e426bc8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/adr/0052-logic-sort-order-in-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Accepted

Brief the logic flows when click `Sort Order` in search:

- To sort by `Subject`, `Sender` or `Relevance` we will have to use the `position` property and ignore `before` and `after` in `conditions` of `filter`
- To sort by `Subject`, `Sender` or `Relevance` we will have to use the `position` property of `filter`

```json
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,12 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin {
? text?.value.trim()
: null,
inMailbox: mailbox?.mailboxId,
after: sortOrderType.isScrollByPosition()
? null
: emailReceiveTimeType.getAfterDate(startDate),
after: emailReceiveTimeType.getAfterDate(startDate),
hasAttachment: !hasAttachment ? null : hasAttachment,
subject: subject?.trim().isNotEmpty == true
? subject?.trim()
: null,
before: sortOrderType.isScrollByPosition()
? null
: emailReceiveTimeType.getBeforeDate(endDate, before),
before: emailReceiveTimeType.getBeforeDate(endDate, before),
from: from.length == 1
? from.first
: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ class SearchEmailController extends BaseController
currentSearchText.value = value;
_updateSimpleSearchFilter(
textOption: option(value.isNotEmpty, SearchQuery(value)),
beforeOption: const None(),
beforeOption: !searchEmailFilter.value.sortOrderType.isScrollByPosition()
? const None()
: null,
positionOption: option(searchEmailFilter.value.sortOrderType.isScrollByPosition(), 0)
);
if (value.isNotEmpty && session != null && accountId != null) {
Expand Down Expand Up @@ -296,7 +298,9 @@ class SearchEmailController extends BaseController
? UnsignedInt(listResultSearch.length)
: ThreadConstants.defaultLimit;
_updateSimpleSearchFilter(
beforeOption: const None(),
beforeOption: !searchEmailFilter.value.sortOrderType.isScrollByPosition()
? const None()
: null,
positionOption: option(searchEmailFilter.value.sortOrderType.isScrollByPosition(), 0)
);
consumeState(_refreshChangesSearchEmailInteractor.execute(
Expand Down Expand Up @@ -390,7 +394,9 @@ class SearchEmailController extends BaseController

_updateSimpleSearchFilter(
positionOption: option(searchEmailFilter.value.sortOrderType.isScrollByPosition(), 0),
beforeOption: const None(),
beforeOption: !searchEmailFilter.value.sortOrderType.isScrollByPosition()
? const None()
: null,
);

consumeState(_searchEmailInteractor.execute(
Expand Down
10 changes: 5 additions & 5 deletions lib/features/thread/presentation/thread_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,10 @@ class ThreadController extends BaseController with EmailActionController {

searchController.updateFilterEmail(
positionOption: option(_searchEmailFilter.sortOrderType.isScrollByPosition(), 0),
beforeOption: const None());
beforeOption: !_searchEmailFilter.sortOrderType.isScrollByPosition()
? const None()
: null,
);

searchController.activateSimpleSearch();

Expand Down Expand Up @@ -895,10 +898,7 @@ class ThreadController extends BaseController with EmailActionController {
if (_searchEmailFilter.sortOrderType.isScrollByPosition()) {
final nextPosition = mailboxDashBoardController.emailsInCurrentMailbox.length;
log('ThreadController::_searchMoreEmails:nextPosition: $nextPosition');
searchController.updateFilterEmail(
positionOption: Some(nextPosition),
beforeOption: const None()
);
searchController.updateFilterEmail(positionOption: Some(nextPosition));
} else if (_searchEmailFilter.sortOrderType == EmailSortOrderType.oldest) {
searchController.updateFilterEmail(startDateOption: optionOf(lastEmail?.receivedAt));
} else {
Expand Down

0 comments on commit e426bc8

Please sign in to comment.