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 all commits
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
@@ -0,0 +1,18 @@
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_properties_action.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';

class UpdateMailboxNameAction extends UpdateMailboxPropertiesAction {
const UpdateMailboxNameAction({
required super.mailboxTrees,
required super.mailboxId,
required this.mailboxName,
});

final MailboxName mailboxName;

@override
bool updateProperty(MailboxTree mailboxTree) {
return mailboxTree.updateMailboxNameById(mailboxId, mailboxName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:get/get_rx/get_rx.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';

abstract class UpdateMailboxPropertiesAction {
const UpdateMailboxPropertiesAction({
required this.mailboxTrees,
required this.mailboxId,
});

final List<Rx<MailboxTree>> mailboxTrees;
final MailboxId mailboxId;

bool updateProperty(MailboxTree mailboxTree);

void execute() {
for (var mailboxTree in mailboxTrees) {
if (updateProperty(mailboxTree.value)) {
mailboxTree.refresh();
break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_properties_action.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';

class UpdateMailboxTotalEmailsCountAction extends UpdateMailboxPropertiesAction {
const UpdateMailboxTotalEmailsCountAction({
required super.mailboxTrees,
required super.mailboxId,
required this.totalEmailsCountChanged,
});

final int totalEmailsCountChanged;

@override
bool updateProperty(MailboxTree mailboxTree) {
return mailboxTree.updateMailboxTotalEmailsCountById(
mailboxId,
totalEmailsCountChanged,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_properties_action.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';

class UpdateMailboxUnreadCountAction extends UpdateMailboxPropertiesAction {
const UpdateMailboxUnreadCountAction({
required super.mailboxTrees,
required super.mailboxId,
required this.unreadChanges,
});

final int unreadChanges;

@override
bool updateProperty(MailboxTree mailboxTree) {
return mailboxTree.updateMailboxUnreadCountById(mailboxId, unreadChanges);
}
}
49 changes: 49 additions & 0 deletions lib/features/base/base_mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import 'package:model/mailbox/expand_mode.dart';
import 'package:model/mailbox/presentation_mailbox.dart';
import 'package:model/mailbox/select_mode.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_name_action.dart';
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_total_emails_count_action.dart';
import 'package:tmail_ui_user/features/base/action/update_mailbox_properties_action/update_mailbox_unread_count_action.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_action_state.dart';
Expand Down Expand Up @@ -553,4 +556,50 @@ abstract class BaseMailboxController extends BaseController {
mailboxNode = personalMailboxTree.value.findNodeOnFirstLevel((node) => node.item.name?.name.toLowerCase() == name);
return mailboxNode;
}

void updateMailboxNameById(MailboxId mailboxId, MailboxName mailboxName) {
dab246 marked this conversation as resolved.
Show resolved Hide resolved
UpdateMailboxNameAction(
mailboxTrees: [defaultMailboxTree, personalMailboxTree, teamMailboxesTree],
mailboxId: mailboxId,
mailboxName: mailboxName,
).execute();
}

void updateUnreadCountOfMailboxById(
MailboxId mailboxId, {
required int unreadChanges,
}) {
UpdateMailboxUnreadCountAction(
mailboxTrees: [defaultMailboxTree, personalMailboxTree, teamMailboxesTree],
mailboxId: mailboxId,
unreadChanges: unreadChanges,
).execute();
}

void clearUnreadCount(MailboxId mailboxId) {
final mailboxTrees = [
defaultMailboxTree,
personalMailboxTree,
teamMailboxesTree,
];

for (var mailboxTree in mailboxTrees) {
final selectedNode = mailboxTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode == null) continue;
final currentUnreadCount = selectedNode.item.unreadEmails?.value.value.toInt();
mailboxTree.value.updateMailboxUnreadCountById(
mailboxId,
-(currentUnreadCount ?? 0));
mailboxTree.refresh();
break;
}
}

void updateMailboxTotalEmailsCountById(MailboxId mailboxId, int totalEmails) {
UpdateMailboxTotalEmailsCountAction(
mailboxTrees: [defaultMailboxTree, personalMailboxTree, teamMailboxesTree],
mailboxId: mailboxId,
totalEmailsCountChanged: totalEmails,
).execute();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';

class SaveEmailAsDraftsLoading extends LoadingState {}

class SaveEmailAsDraftsSuccess extends UIState {

final EmailId emailId;
final MailboxId? draftMailboxId;

SaveEmailAsDraftsSuccess(this.emailId);
SaveEmailAsDraftsSuccess(this.emailId, this.draftMailboxId);

@override
List<Object?> get props => [emailId, ...super.props];
List<Object?> get props => [emailId, draftMailboxId, ...super.props];
}

class SaveEmailAsDraftsFailure extends FeatureFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class CreateNewAndSaveEmailToDraftsInteractor {
);

yield dartz.Right<Failure, Success>(
SaveEmailAsDraftsSuccess(emailDraftSaved.id!)
SaveEmailAsDraftsSuccess(
emailDraftSaved.id!,
createEmailRequest.draftsMailboxId,
)
);
} else {
yield dartz.Right<Failure, Success>(UpdatingEmailDrafts());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ 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/user_name.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
import 'package:model/account/account_request.dart';
import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart';
import 'package:model/email/mark_star_action.dart';
import 'package:model/email/read_actions.dart';
import 'package:model/extensions/email_extension.dart';
import 'package:model/extensions/email_id_extensions.dart';
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart';
Expand Down Expand Up @@ -79,8 +81,13 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
AccountId accountId,
EmailId emailId,
{CancelToken? cancelToken}
) {
throw UnimplementedError();
) async {
await _emailCacheManager.update(
accountId,
session.username,
destroyed: [emailId],
);
return true;
}

@override
Expand All @@ -91,8 +98,16 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
Session session,
AccountId accountId,
List<EmailId> emailIds,
) {
throw UnimplementedError();
) async {
await _emailCacheManager.update(
accountId,
session.username,
destroyed: emailIds,
);
return (
emailIdsSuccess: emailIds,
mapErrors: <Id, SetError>{}
);
}

@override
Expand Down Expand Up @@ -137,8 +152,29 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
AccountId accountId,
List<EmailId> emailIds,
ReadActions readActions,
) {
throw UnimplementedError();
) async {
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 _emailCacheManager.storeMultipleEmails(
accountId,
session.username,
storedEmails.map((email) => email.toEmailCache()).toList(),
);
return (
emailIdsSuccess: emailIds,
mapErrors: <Id, SetError>{}
);
}

@override
Expand All @@ -150,8 +186,29 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
AccountId accountId,
List<EmailId> emailIds,
MarkStarAction markStarAction,
) {
throw UnimplementedError();
) async {
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 _emailCacheManager.storeMultipleEmails(
accountId,
session.username,
storedEmails.map((email) => email.toEmailCache()).toList(),
);
return (
emailIdsSuccess: emailIds,
mapErrors: <Id, SetError>{}
);
}

@override
Expand All @@ -162,8 +219,32 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
Session session,
AccountId accountId,
MoveToMailboxRequest moveRequest,
) {
throw UnimplementedError();
) async {
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 _emailCacheManager.storeMultipleEmails(
accountId,
session.username,
storedEmails.map((email) => email.toEmailCache()).toList(),
);
return (
emailIdsSuccess: emailIds,
mapErrors: <Id, SetError>{}
);
}

@override
Expand All @@ -172,8 +253,13 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
AccountId accountId,
EmailId emailId,
{CancelToken? cancelToken}
) {
throw UnimplementedError();
) async {
await _emailCacheManager.update(
accountId,
session.username,
destroyed: [emailId],
);
return true;
}

@override
Expand All @@ -182,8 +268,9 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
AccountId accountId,
Email email,
{CancelToken? cancelToken}
) {
throw UnimplementedError();
) async {
await _emailCacheManager.update(accountId, session.username, created: [email]);
return email;
}

@override
Expand Down Expand Up @@ -232,8 +319,13 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
Email newEmail,
EmailId oldEmailId,
{CancelToken? cancelToken}
) {
throw UnimplementedError();
) async {
await _emailCacheManager.update(
accountId,
session.username,
updated: [newEmail],
);
return newEmail;
}

@override
Expand Down
Loading
Loading