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

[WIP] TF-3385 Update UI by user actions before web socket #3386

Closed
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
102 changes: 102 additions & 0 deletions lib/features/base/base_mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,106 @@ abstract class BaseMailboxController extends BaseController {
mailboxNode = personalMailboxTree.value.findNodeOnFirstLevel((node) => node.item.name?.name.toLowerCase() == name);
return mailboxNode;
}

void updateMailboxNameById(MailboxId mailboxId, MailboxName mailboxName) {
MailboxNode? selectedNode;

selectedNode = defaultMailboxTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
defaultMailboxTree.value.updateMailboxNameById(mailboxId, mailboxName);
defaultMailboxTree.refresh();
hoangdat marked this conversation as resolved.
Show resolved Hide resolved
return;
}

selectedNode = personalMailboxTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
personalMailboxTree.value.updateMailboxNameById(mailboxId, mailboxName);
personalMailboxTree.refresh();
return;
}

selectedNode = teamMailboxesTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
teamMailboxesTree.value.updateMailboxNameById(mailboxId, mailboxName);
teamMailboxesTree.refresh();
return;
}
}

void updateUnreadCountOfMailboxById(
MailboxId mailboxId, {
int? readCount,
int? unreadCount,
}) {
int unreadChanges = 0;
if (readCount != null) {
unreadChanges -= readCount;
}
if (unreadCount != null) {
unreadChanges += unreadCount;
}

MailboxNode? selectedNode;

selectedNode = defaultMailboxTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
defaultMailboxTree.value.updateMailboxUnreadCountById(
mailboxId,
unreadChanges);
defaultMailboxTree.refresh();
return;
}

selectedNode = personalMailboxTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
personalMailboxTree.value.updateMailboxUnreadCountById(
mailboxId,
unreadChanges);
personalMailboxTree.refresh();
return;
}

selectedNode = teamMailboxesTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
teamMailboxesTree.value.updateMailboxUnreadCountById(
mailboxId,
unreadChanges);
teamMailboxesTree.refresh();
return;
}
}

void clearUnreadCount(MailboxId mailboxId) {
MailboxNode? selectedNode;

selectedNode = defaultMailboxTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
final currentUnreadCount = selectedNode.item.unreadEmails?.value.value.toInt();
defaultMailboxTree.value.updateMailboxUnreadCountById(
mailboxId,
-(currentUnreadCount ?? 0));
defaultMailboxTree.refresh();
return;
}

selectedNode = personalMailboxTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
final currentUnreadCount = selectedNode.item.unreadEmails?.value.value.toInt();
personalMailboxTree.value.updateMailboxUnreadCountById(
mailboxId,
-(currentUnreadCount ?? 0));
personalMailboxTree.refresh();
return;
}

selectedNode = teamMailboxesTree.value.findNode((node) => node.item.id == mailboxId);
if (selectedNode != null) {
final currentUnreadCount = selectedNode.item.unreadEmails?.value.value.toInt();
teamMailboxesTree.value.updateMailboxUnreadCountById(
mailboxId,
-(currentUnreadCount ?? 0));
teamMailboxesTree.refresh();
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
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';
import 'package:model/email/read_actions.dart';
import 'package:tmail_ui_user/features/email/domain/model/mark_read_action.dart';

class MarkAsEmailReadSuccess extends UIState {
final EmailId emailId;
final ReadActions readActions;
final MarkReadAction markReadAction;
final MailboxId? mailboxId;

MarkAsEmailReadSuccess(
this.emailId,
this.readActions,
this.markReadAction,
this.mailboxId,
);

@override
List<Object?> get props => [emailId, readActions, markReadAction];
List<Object?> get props => [emailId, readActions, markReadAction, mailboxId];
}

class MarkAsEmailReadFailure extends FeatureFailure {
Expand Down
6 changes: 4 additions & 2 deletions lib/features/email/domain/state/mark_as_email_star_state.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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:model/email/mark_star_action.dart';

class MarkAsStarEmailSuccess extends UIState {
final MarkStarAction markStarAction;
final EmailId emailId;

MarkAsStarEmailSuccess(this.markStarAction);
MarkAsStarEmailSuccess(this.markStarAction, this.emailId);

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

class MarkAsStarEmailFailure extends FeatureFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/email/read_actions.dart';
import 'package:tmail_ui_user/features/email/domain/model/mark_read_action.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
Expand All @@ -20,6 +21,7 @@ class MarkAsEmailReadInteractor {
EmailId emailId,
ReadActions readAction,
MarkReadAction markReadAction,
MailboxId? mailboxId,
) async* {
try {
final result = await _emailRepository.markAsRead(
Expand All @@ -33,6 +35,7 @@ class MarkAsEmailReadInteractor {
result.first,
readAction,
markReadAction,
mailboxId,
));
} catch (e) {
yield Left(MarkAsEmailReadFailure(readAction, exception: e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MarkAsStarEmailInteractor {
[emailId],
markStarAction,
);
yield Right(MarkAsStarEmailSuccess(markStarAction));
yield Right(MarkAsStarEmailSuccess(markStarAction, emailId));
} catch (e) {
yield Left(MarkAsStarEmailFailure(markStarAction, exception: e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
presentationEmail.id!,
readActions,
markReadAction,
presentationEmail.mailboxContain?.mailboxId,
));
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/features/mailbox/domain/state/mark_as_mailbox_read_state.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';

Expand All @@ -24,8 +25,10 @@ class UpdatingMarkAsMailboxReadState extends UIState {
class MarkAsMailboxReadAllSuccess extends UIActionState {

final String mailboxDisplayName;
final MailboxId mailboxId;

MarkAsMailboxReadAllSuccess(this.mailboxDisplayName,
this.mailboxId,
{
jmap.State? currentEmailState,
jmap.State? currentMailboxState,
Expand All @@ -35,6 +38,7 @@ class MarkAsMailboxReadAllSuccess extends UIActionState {
@override
List<Object?> get props => [
mailboxDisplayName,
mailboxId,
...super.props
];
}
Expand All @@ -43,16 +47,22 @@ class MarkAsMailboxReadHasSomeEmailFailure extends UIState {

final String mailboxDisplayName;
final int countEmailsRead;
final MailboxId mailboxId;
final List<EmailId> successEmailIds;

MarkAsMailboxReadHasSomeEmailFailure(
this.mailboxDisplayName,
this.countEmailsRead,
this.mailboxId,
this.successEmailIds,
);

@override
List<Object?> get props => [
mailboxDisplayName,
countEmailsRead,
mailboxId,
successEmailIds,
];
}

Expand Down
10 changes: 9 additions & 1 deletion lib/features/mailbox/domain/state/rename_mailbox_state.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_mailbox_request.dart';

class LoadingRenameMailbox extends UIState {}

class RenameMailboxSuccess extends UIState {}
class RenameMailboxSuccess extends UIState {
RenameMailboxSuccess({required this.request});

final RenameMailboxRequest request;

@override
List<Object> get props => [request];
}

class RenameMailboxFailure extends FeatureFailure {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class MarkAsMailboxReadInteractor {
onProgressController);

if (totalEmailUnread == listEmails.length) {
yield Right(MarkAsMailboxReadAllSuccess(mailboxDisplayName));
yield Right(MarkAsMailboxReadAllSuccess(mailboxDisplayName, mailboxId));
} else if (listEmails.isNotEmpty) {
yield Right(MarkAsMailboxReadHasSomeEmailFailure(
mailboxDisplayName,
listEmails.length,
mailboxId,
listEmails,
));
} else {
yield Left(MarkAsMailboxReadAllFailure(mailboxDisplayName: mailboxDisplayName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RenameMailboxInteractor {
yield Right<Failure, Success>(LoadingRenameMailbox());
final result = await _mailboxRepository.renameMailbox(session, accountId, request);
if (result) {
yield Right<Failure, Success>(RenameMailboxSuccess());
yield Right<Failure, Success>(RenameMailboxSuccess(request: request));
} else {
yield Left<Failure, Success>(RenameMailboxFailure(null));
}
Expand Down
Loading
Loading