Skip to content

Commit 33895fd

Browse files
committed
TF-4400 Auto sync UI when change thread state in setting
1 parent ccb8b25 commit 33895fd

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

lib/features/email/presentation/action/email_ui_action.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,5 @@ class SyncUpdateLabelForEmailOnMemory extends EmailUIAction {
147147
shouldRemove,
148148
];
149149
}
150+
151+
class RefreshEmailListViewOnForceEmailQueryAction extends EmailUIAction {}

lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,6 @@ class MailboxDashBoardController extends ReloadableController
949949
}
950950

951951
loadLinagoraEcosystem();
952-
loadPreferencesSetting();
953952
}
954953

955954
void _handleMailtoURL(MailtoArguments arguments) {
@@ -2127,6 +2126,7 @@ class MailboxDashBoardController extends ReloadableController
21272126
sessionCurrent != null) {
21282127
labelController.checkLabelSettingState(sessionCurrent!, accountId.value!);
21292128
}
2129+
loadPreferencesSetting();
21302130
}
21312131

21322132
Future<List<PresentationEmail>> quickSearchEmails(String query) async {
@@ -3463,7 +3463,16 @@ class MailboxDashBoardController extends ReloadableController
34633463
@override
34643464
OnPreferencesSettingChanged get onPreferencesSettingChanged => ({bool isThreadStateChanged = false}) {
34653465
log('MailboxDashBoardController::onPreferencesSettingChanged: isThreadStateChanged = $isThreadStateChanged');
3466-
};
3466+
if (isThreadStateChanged &&
3467+
forceEmailQuery &&
3468+
!searchController.isSearchEmailRunning) {
3469+
_syncEmailListViewOnForceEmailQuery();
3470+
}
3471+
};
3472+
3473+
void _syncEmailListViewOnForceEmailQuery() {
3474+
dispatchEmailUIAction(RefreshEmailListViewOnForceEmailQueryAction());
3475+
}
34673476

34683477
@override
34693478
void onClose() {

lib/features/mailbox_dashboard/presentation/mixin/setup_preferences_setting_mixin.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'package:core/utils/app_logger.dart';
2+
import 'package:core/utils/platform_info.dart';
23
import 'package:tmail_ui_user/features/base/base_controller.dart';
34
import 'package:tmail_ui_user/features/base/mixin/emit_state_mixin.dart';
45
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_setting.dart';
56
import 'package:tmail_ui_user/features/manage_account/domain/state/get_local_settings_state.dart';
67
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_local_settings_interactor.dart';
78
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
9+
import 'package:tmail_ui_user/main/utils/app_config.dart';
810

911
typedef OnPreferencesSettingChanged = void Function({
1012
bool isThreadStateChanged,
@@ -22,6 +24,9 @@ mixin SetupPreferencesSettingMixin on EmitStateMixin {
2224
bool? get isThreadDetailEnabled =>
2325
_preferencesSetting?.isThreadDetailEnabled == true;
2426

27+
bool get forceEmailQuery =>
28+
PlatformInfo.isWeb && AppConfig.isForceEmailQueryEnabled;
29+
2530
void _setPreferencesSetting(PreferencesSetting setting) =>
2631
_preferencesSetting = setting;
2732

lib/features/thread/presentation/thread_controller.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ class ThreadController extends BaseController with EmailActionController {
358358
} else if (action is RefreshAllEmailAction) {
359359
refreshAllEmail(shouldClearCache: PlatformInfo.isWeb);
360360
mailboxDashBoardController.clearEmailUIAction();
361+
} else if (action is RefreshEmailListViewOnForceEmailQueryAction) {
362+
consumeState(Stream.value(Right(GetAllEmailLoading())));
363+
resetToOriginalValue();
364+
getAllEmailAction(forceEmailQuery: forceEmailQuery);
365+
mailboxDashBoardController.clearEmailUIAction();
361366
}
362367
});
363368

@@ -537,7 +542,7 @@ class ThreadController extends BaseController with EmailActionController {
537542
logWarning('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error');
538543
if (error is CannotCalculateChangesMethodResponseException) {
539544
await cachingManager.clearAllEmailAndStateCache();
540-
getAllEmailAction();
545+
getAllEmailAction(forceEmailQuery: forceEmailQuery);
541546
} else if (error is MethodLevelErrors) {
542547
if (currentOverlayContext != null && error.message != null) {
543548
appToast.showToastErrorMessage(
@@ -707,7 +712,7 @@ class ThreadController extends BaseController with EmailActionController {
707712
if (searchController.isSearchEmailRunning) {
708713
_searchEmail(limit: limitEmailFetched);
709714
} else {
710-
getAllEmailAction();
715+
getAllEmailAction(forceEmailQuery: forceEmailQuery);
711716
}
712717
}
713718

0 commit comments

Comments
 (0)