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

TF-3385 Update UI by user actions before web socket #3390

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e9c0165
TF-3385 Update mailbox name
tddang-linagora Dec 31, 2024
5ea7b35
TF-3385 Update mark as read and star
tddang-linagora Dec 31, 2024
718cab4
TF-3385 Update recover deleted emails
tddang-linagora Dec 31, 2024
ce74d88
TF-3385 Update save and remove draft email
tddang-linagora Jan 2, 2025
f2d5d23
TF-3385 Update permanently delete emails
tddang-linagora Jan 2, 2025
3edffcf
TF-3385 Update empty trash and spam emails
tddang-linagora Jan 2, 2025
bc50f8d
TF-3385 Update move emails
tddang-linagora Jan 2, 2025
f99451b
TF-3385 Clean up ThreadController and SearchEmailController ever list…
tddang-linagora Jan 2, 2025
7928788
TF-3385 Update cache on set method
tddang-linagora Jan 2, 2025
e21b618
TF-3385 Create abstract group for update mailbox actions
tddang-linagora Jan 3, 2025
df05177
TF-3385 Get & set multiple changes in email cache
tddang-linagora Jan 3, 2025
b8539c9
TF-3385 Add try-catch to cache method calls on user actions
tddang-linagora Jan 3, 2025
ac55a23
TF-3385 Remove skipCache mechanism in get all emails
tddang-linagora Jan 3, 2025
60ad59e
TF-3385 Fix mark as read not work properly
tddang-linagora Jan 3, 2025
7a879b5
TF-3385 Fix move and delete emails not work properly
tddang-linagora Jan 3, 2025
ed342e7
TF-3385 Optimize misc
tddang-linagora Jan 3, 2025
fc0a3b7
TF-3385 Revert undo operation handling
tddang-linagora Jan 3, 2025
c1ae133
TF-3385 Fix change flags not working
tddang-linagora Jan 3, 2025
8ea24f9
TF-3385 Fix Map read status from fromIterable to fromEntries
tddang-linagora Jan 3, 2025
e6914ee
TF-3385 Fix tests update email flags extension
tddang-linagora Jan 3, 2025
d71609e
TF-3385 Fix Map spam/unspam from fromIterable to fromEntries
hoangdat Jan 3, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,24 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
List<EmailId> emailIds,
ReadActions readActions,
) async {
final storedEmails = await Future.wait(emailIds.map(
(emailId) => getStoredEmail(session, accountId, emailId),
));
final cacheEmails = await _emailCacheManager.getMultipleStoredEmails(
accountId,
session.username,
emailIds,
);
final storedEmails = cacheEmails.map((emailCache) => emailCache.toEmail()).toList();
for (var email in storedEmails) {
if (readActions == ReadActions.markAsUnread) {
email.keywords?.remove(KeyWordIdentifier.emailSeen);
} else {
email.keywords?[KeyWordIdentifier.emailSeen] = true;
}
}
await Future.wait(storedEmails.map(
(email) => storeEmail(session, accountId, email),
));
await _emailCacheManager.storeMultipleEmails(
accountId,
session.username,
storedEmails.map((email) => email.toEmailCache()).toList(),
);
return (
emailIdsSuccess: emailIds,
mapErrors: <Id, SetError>{}
Expand All @@ -182,19 +187,24 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
List<EmailId> emailIds,
MarkStarAction markStarAction,
) async {
final storedEmails = await Future.wait(emailIds.map(
(emailId) => getStoredEmail(session, accountId, emailId),
));
final cacheEmails = await _emailCacheManager.getMultipleStoredEmails(
accountId,
session.username,
emailIds,
);
final storedEmails = cacheEmails.map((emailCache) => emailCache.toEmail()).toList();
for (var email in storedEmails) {
if (markStarAction == MarkStarAction.unMarkStar) {
email.keywords?.remove(KeyWordIdentifier.emailFlagged);
} else {
email.keywords?[KeyWordIdentifier.emailFlagged] = true;
}
}
await Future.wait(storedEmails.map(
(email) => storeEmail(session, accountId, email),
));
await _emailCacheManager.storeMultipleEmails(
accountId,
session.username,
storedEmails.map((email) => email.toEmailCache()).toList(),
);
return (
emailIdsSuccess: emailIds,
mapErrors: <Id, SetError>{}
Expand All @@ -210,24 +220,27 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
AccountId accountId,
MoveToMailboxRequest moveRequest,
) async {
final emailIds = moveRequest.currentMailboxes.entries.fold(
<EmailId>{},
(emailIds, entry) {
emailIds.addAll(entry.value);
return emailIds;
},
).toList();
final storedEmails = await Future.wait(emailIds.map(
(emailId) => getStoredEmail(session, accountId, emailId),
));
final emailIds = moveRequest
.currentMailboxes
.values
.expand((emails) => emails)
.toList();
final cacheEmails = await _emailCacheManager.getMultipleStoredEmails(
accountId,
session.username,
emailIds,
);
final storedEmails = cacheEmails.map((emailCache) => emailCache.toEmail()).toList();
for (int i = 0; i < storedEmails.length; i++) {
storedEmails[i] = storedEmails[i].updatedEmail(
newMailboxIds: {moveRequest.destinationMailboxId: true},
);
}
await Future.wait(storedEmails.map(
(email) => storeEmail(session, accountId, email),
));
await _emailCacheManager.storeMultipleEmails(
accountId,
session.username,
storedEmails.map((email) => email.toEmailCache()).toList(),
);
return (
emailIdsSuccess: emailIds,
mapErrors: <Id, SetError>{}
Expand Down
20 changes: 20 additions & 0 deletions lib/features/thread/data/local/email_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ class EmailCacheManager {
return _emailCacheClient.insertItem(keyCache, emailCache);
}

Future<void> storeMultipleEmails(AccountId accountId, UserName userName, List<EmailCache> emailsCache) {
return Future.wait(emailsCache.map((emailCache) => storeEmail(
accountId,
userName,
emailCache,
)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use Future.wait let's use store multiple value to box of hive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

Future<EmailCache> getStoredEmail(AccountId accountId, UserName userName, EmailId emailId) async {
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
final emailCache = await _emailCacheClient.getItem(keyCache, needToReopen: true);
Expand All @@ -104,4 +112,16 @@ class EmailCacheManager {
throw NotFoundStoredEmailException();
}
}

Future<List<EmailCache>> getMultipleStoredEmails(
AccountId accountId,
UserName userName,
List<EmailId> emailIds,
) async {
final keys = emailIds
.map((emailId) => TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey)
.toList();
final emails = await _emailCacheClient.getValuesByListKey(keys);
return emails;
}
}