TF-348 Fix unread email counter not updating
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
|
||||
class RefreshChangesAllMailboxSuccess extends UIState {
|
||||
final List<PresentationMailbox> mailboxList;
|
||||
final State? currentMailboxState;
|
||||
|
||||
RefreshChangesAllMailboxSuccess({
|
||||
required this.mailboxList,
|
||||
required this.currentMailboxState
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mailboxList, currentMailboxState];
|
||||
}
|
||||
|
||||
class RefreshChangesAllMailboxFailure extends FeatureFailure {
|
||||
final exception;
|
||||
|
||||
RefreshChangesAllMailboxFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import 'package:jmap_dart_client/jmap/core/state.dart' as jmapState;
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_response.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/refresh_changes_all_mailboxes_state.dart';
|
||||
|
||||
class RefreshAllMailboxInteractor {
|
||||
final MailboxRepository _mailboxRepository;
|
||||
@@ -20,7 +20,7 @@ class RefreshAllMailboxInteractor {
|
||||
.refresh(accountId, currentState)
|
||||
.map(_toGetMailboxState);
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetAllMailboxFailure(e));
|
||||
yield Left<Failure, Success>(RefreshChangesAllMailboxFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class RefreshAllMailboxInteractor {
|
||||
?.map((mailbox) => mailbox.toPresentationMailbox()).toList()
|
||||
?? List<PresentationMailbox>.empty();
|
||||
|
||||
return Right<Failure, Success>(GetAllMailboxSuccess(
|
||||
return Right<Failure, Success>(RefreshChangesAllMailboxSuccess(
|
||||
mailboxList: mailboxList,
|
||||
currentMailboxState: mailboxResponse.state)
|
||||
);
|
||||
|
||||
@@ -17,11 +17,13 @@ import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_draft
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/send_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/move_to_mailbox_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/create_new_mailbox_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/delete_multiple_mailbox_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/refresh_changes_all_mailboxes_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/rename_mailbox_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/state/search_mailbox_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_mailbox_interactor.dart';
|
||||
@@ -107,18 +109,22 @@ class MailboxController extends BaseMailboxController {
|
||||
|
||||
mailboxDashBoardController.viewState.listen((state) {
|
||||
state.map((success) {
|
||||
if (success is MarkAsEmailReadSuccess ||
|
||||
success is MarkAsMultipleEmailReadAllSuccess ||
|
||||
success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
|
||||
log('MailboxController::onReady(): ${success.runtimeType}');
|
||||
|
||||
if (success is MarkAsMultipleEmailReadAllSuccess
|
||||
|| success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
|
||||
mailboxDashBoardController.clearState();
|
||||
refreshMailboxChanges();
|
||||
} else if (success is MoveMultipleEmailToMailboxAllSuccess
|
||||
|| success is MoveMultipleEmailToMailboxHasSomeEmailFailure) {
|
||||
mailboxDashBoardController.clearState();
|
||||
refreshMailboxChanges();
|
||||
} else if (success is SaveEmailAsDraftsSuccess
|
||||
|| success is RemoveEmailDraftsSuccess
|
||||
|| success is SendEmailSuccess
|
||||
|| success is UpdateEmailDraftsSuccess) {
|
||||
} else if (success is MarkAsEmailReadSuccess
|
||||
|| success is MoveToMailboxSuccess
|
||||
|| success is SaveEmailAsDraftsSuccess
|
||||
|| success is RemoveEmailDraftsSuccess
|
||||
|| success is SendEmailSuccess
|
||||
|| success is UpdateEmailDraftsSuccess) {
|
||||
refreshMailboxChanges();
|
||||
}
|
||||
});
|
||||
@@ -147,6 +153,13 @@ class MailboxController extends BaseMailboxController {
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
await buildTree(allMailboxes);
|
||||
|
||||
_setUpMapMailboxIdDefault(allMailboxes, defaultMailboxTree.value, folderMailboxTree.value);
|
||||
} else if (success is RefreshChangesAllMailboxSuccess) {
|
||||
log('MailboxController::onData(): ${allMailboxes.length}');
|
||||
allMailboxes = success.mailboxList;
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
await refreshTree(allMailboxes);
|
||||
|
||||
_setUpMapMailboxIdDefault(allMailboxes, defaultMailboxTree.value, folderMailboxTree.value);
|
||||
}
|
||||
});
|
||||
@@ -171,10 +184,8 @@ class MailboxController extends BaseMailboxController {
|
||||
_searchMailboxSuccess(success);
|
||||
} else if (success is DeleteMultipleMailboxSuccess) {
|
||||
_deleteMailboxSuccess(success);
|
||||
} else if (success is GetAllMailboxSuccess) {
|
||||
if (isSearchActive()) {
|
||||
_searchMailboxAction(allMailboxes, searchQuery.value);
|
||||
}
|
||||
} else if ((success is GetAllMailboxSuccess || success is RefreshChangesAllMailboxSuccess) && isSearchActive()) {
|
||||
_searchMailboxAction(allMailboxes, searchQuery.value);
|
||||
} else if (success is RenameMailboxSuccess) {
|
||||
refreshMailboxChanges();
|
||||
}
|
||||
|
||||
@@ -75,4 +75,54 @@ class TreeBuilder {
|
||||
defaultTree.root.childrenItems?.sort((thisMailbox, thatMailbox) => thisMailbox.compareTo(thatMailbox));
|
||||
return Tuple2(defaultTree, folderTree);
|
||||
}
|
||||
|
||||
Future<Tuple2<MailboxTree, MailboxTree>> generateMailboxTreeInUIAfterRefreshChanges(
|
||||
List<PresentationMailbox> allMailboxes,
|
||||
MailboxTree defaultTreeBeforeChanges,
|
||||
MailboxTree folderTreeBeforeChanges,
|
||||
) async {
|
||||
final Map<MailboxId, MailboxNode> mailboxDictionary = HashMap();
|
||||
|
||||
final newDefaultTree = MailboxTree(MailboxNode.root());
|
||||
final newFolderTree = MailboxTree(MailboxNode.root());
|
||||
|
||||
allMailboxes.forEach((mailbox) {
|
||||
final mailboxNodeBeforeChanges = defaultTreeBeforeChanges.findNode((node) => node.item.id == mailbox.id) ??
|
||||
folderTreeBeforeChanges.findNode((node) => node.item.id == mailbox.id);
|
||||
if (mailboxNodeBeforeChanges != null) {
|
||||
mailboxDictionary[mailbox.id] = MailboxNode(
|
||||
mailbox,
|
||||
expandMode: mailboxNodeBeforeChanges.expandMode,
|
||||
selectMode: mailboxNodeBeforeChanges.selectMode);
|
||||
} else {
|
||||
mailboxDictionary[mailbox.id] = MailboxNode(mailbox);
|
||||
}
|
||||
});
|
||||
|
||||
allMailboxes.forEach((mailbox) {
|
||||
final parentId = mailbox.parentId;
|
||||
final parentNode = mailboxDictionary[parentId];
|
||||
final node = mailboxDictionary[mailbox.id];
|
||||
if (node != null) {
|
||||
if (parentNode != null) {
|
||||
parentNode.addChildNode(node);
|
||||
parentNode.childrenItems?.sortByCompare<MailboxName?>(
|
||||
(node) => node.item.name,
|
||||
(name, other) => name?.compareAlphabetically(other) ?? -1
|
||||
);
|
||||
} else {
|
||||
var tree = mailbox.hasRole() ? newDefaultTree : newFolderTree;
|
||||
|
||||
tree.root.addChildNode(node);
|
||||
tree.root.childrenItems?.sortByCompare<MailboxName?>(
|
||||
(node) => node.item.name,
|
||||
(name, other) => name?.compareAlphabetically(other) ?? -1
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
newDefaultTree.root.childrenItems?.sort((thisMailbox, thatMailbox) => thisMailbox.compareTo(thatMailbox));
|
||||
return Tuple2(newDefaultTree, newFolderTree);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user