Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEARCH] TF-3006 Mail address handle in quick search bar #3152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 216 additions & 0 deletions docs/adr/0052-logic-sort-order-in-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# 52. Logic Sort Order in search

Date: 2024-10-07

## Status

Accepted

## Context

- Using `sort` by `Subject`, `Sender` or `Relevance` together with `filter` by `conditions` with `before` or `after` date results in incorrect `Email/query` response results.
- ISSUE: https://github.com/linagora/tmail-flutter/pull/2360

```json
{
"using": [
"urn:ietf:params:jmap:core",
"urn:ietf:params:jmap:mail",
"urn:apache:james:params:jmap:mail:shares"
],
"methodCalls": [
[
"Email/query",
{
"accountId": "3cd281b49cxxxxxxxxexx",
"filter": {
"operator": "AND",
"conditions": [
{
"before": "2023-11-10T16:46:32.000Z",
"text": "firstname99"
}
]
},
"sort": [
{
"isAscending": true,
"property": "subject"
}
],
"limit": 20
},
"c0"
],
[
"Email/get",
{
"accountId": "3cd281b49cxxxxxxxxexx",
"#ids": {
"resultOf": "c0",
"name": "Email/query",
"path": "/ids/*"
},
"properties": [
"id",
"subject",
"from",
"to",
"cc",
"bcc",
"keywords",
"size",
"receivedAt",
"sentAt",
"preview",
"hasAttachment",
"replyTo",
"mailboxIds",
"header:X-MEETING-UID:asText"
]
},
"c1"
]
]
}
```

## Decision

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`

```json
{
"using": [
"urn:ietf:params:jmap:core",
"urn:ietf:params:jmap:mail",
"urn:apache:james:params:jmap:mail:shares"
],
"methodCalls": [
[
"Email/query",
{
"accountId": "3cd281b49cxxxxxxxxexx",
"filter": {
"operator": "AND",
"conditions": [
{
"text": "firstname99"
}
]
},
"sort": [
{
"isAscending": true,
"property": "subject"
}
],
"limit": 20,
"position": 20
},
"c0"
],
[
"Email/get",
{
"accountId": "3cd281b49cxxxxxxxxexx",
"#ids": {
"resultOf": "c0",
"name": "Email/query",
"path": "/ids/*"
},
"properties": [
"id",
"subject",
"from",
"to",
"cc",
"bcc",
"keywords",
"size",
"receivedAt",
"sentAt",
"preview",
"hasAttachment",
"replyTo",
"mailboxIds",
"header:X-MEETING-UID:asText"
]
},
"c1"
]
]
}
```

- As for `sort` by `Most Recent` and `Oldest` we need to use `before` and `after` in `conditions` of `filter`

```json
{
"using": [
"urn:ietf:params:jmap:core",
"urn:ietf:params:jmap:mail",
"urn:apache:james:params:jmap:mail:shares"
],
"methodCalls": [
[
"Email/query",
{
"accountId": "3cd281b49cxxxxxxxxexx",
"filter": {
"operator": "AND",
"conditions": [
{
"before": "2023-11-10T16:46:32.000Z",
"text": "firstname99"
}
]
},
"sort": [
{
"isAscending": true,
"property": "receivedAt"
}
],
"limit": 20
},
"c0"
],
[
"Email/get",
{
"accountId": "3cd281b49cxxxxxxxxexx",
"#ids": {
"resultOf": "c0",
"name": "Email/query",
"path": "/ids/*"
},
"properties": [
"id",
"subject",
"from",
"to",
"cc",
"bcc",
"keywords",
"size",
"receivedAt",
"sentAt",
"preview",
"hasAttachment",
"replyTo",
"mailboxIds",
"header:X-MEETING-UID:asText"
]
},
"c1"
]
]
}
```

## Consequences

- Any changes to the `Sort Order` logic in search must be updated in this ADR.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ class OpenEmailDetailedFromSuggestionQuickSearchAction extends DashBoardAction {
List<Object?> get props => [presentationEmail];
}

class StartSearchEmailAction extends DashBoardAction {
final QuickSearchFilter? filter;
class StartSearchEmailAction extends DashBoardAction {}

StartSearchEmailAction({this.filter});
class StartSearchEmailBySearchFilterAction extends DashBoardAction {
final QuickSearchFilter searchFilter;

StartSearchEmailBySearchFilterAction(this.searchFilter);

@override
List<Object?> get props => [filter];
List<Object?> get props => [searchFilter];
}

class EmptyTrashAction extends DashBoardAction {}
Expand Down Expand Up @@ -153,4 +155,6 @@ class CancelSelectionSearchEmailAction extends DashBoardAction {}

class OpenAdvancedSearchViewAction extends DashBoardAction {}

class ClearSearchFilterAppliedAction extends DashBoardAction {}
class ClearSearchFilterAppliedAction extends DashBoardAction {}

class ClearAdvancedSearchFilterEmailAction extends DashBoardAction {}
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,9 @@ class AdvancedFilterController extends BaseController {
}

void clearSearchFilter() {
searchController.clearSearchFilter();
_resetAllToOriginalValue();
_clearAllTextFieldInput();
searchController.searchInputController.clear();
searchController.clearSortOrder();
searchController.deactivateAdvancedSearch();
searchController.isAdvancedSearchViewOpen.value = false;
_mailboxDashBoardController.searchEmail();
_mailboxDashBoardController.handleClearAdvancedSearchFilterEmail();
}

void _updateFilterEmailFromAdvancedSearchView() {
Expand Down Expand Up @@ -119,8 +114,6 @@ class AdvancedFilterController extends BaseController {
searchController.updateFilterEmail(toOption: const None());
}

searchController.updateFilterEmail(sortOrderOption: searchController.sortOrderFiltered.value.getSortOrder());

searchController.updateFilterEmail(
mailboxOption: optionOf(_destinationMailboxSelected),
subjectOption: optionOf(subjectFilterInputController.text),
Expand Down Expand Up @@ -170,7 +163,7 @@ class AdvancedFilterController extends BaseController {
searchController.updateFilterEmail(beforeOption: const None());
}
searchController.isAdvancedSearchViewOpen.value = false;
_mailboxDashBoardController.searchEmail();
_mailboxDashBoardController.handleAdvancedSearchEmail();
}

Future<List<EmailAddress>> getAutoCompleteSuggestion(String word) async {
Expand Down Expand Up @@ -405,17 +398,8 @@ class AdvancedFilterController extends BaseController {
);
} else if (action is ClearDateRangeToAdvancedSearch) {
_updateDateRangeTime(action.receiveTime);
} else if (action is StartSearchEmailAction) {
switch(action.filter) {
case QuickSearchFilter.from:
_updateFromField();
break;
case QuickSearchFilter.to:
_updateToField();
break;
default:
break;
}
} else if (action is StartSearchEmailBySearchFilterAction) {
_handleSearchEmailBySearchFilterAction(action.searchFilter);
} else if (action is SearchEmailByFromFieldsAction) {
searchController.clearSearchFilter();
_resetAllToOriginalValue();
Expand Down Expand Up @@ -480,6 +464,19 @@ class AdvancedFilterController extends BaseController {
applyAdvancedSearchFilter();
}

void _handleSearchEmailBySearchFilterAction(QuickSearchFilter searchFilter) {
switch(searchFilter) {
case QuickSearchFilter.from:
_updateFromField();
break;
case QuickSearchFilter.to:
_updateToField();
break;
default:
break;
}
}

@override
void onClose() {
_removeFocusListener();
Expand Down
Loading
Loading