TF-2269 Show the report once a day
Signed-off-by: dab246 <tdvu@linagora.com> Signed-off-by: dab246 <tdvu@linagora.com> Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit 74bed6e6dfbd32d70baeb131546b490199bb8fbb)
This commit is contained in:
@@ -1,39 +1,44 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/utils/mailbox_dashboard_constant.dart';
|
||||
|
||||
class LocalSpamReportManager {
|
||||
static const String _keyLastTimeDismissedSpamReported = 'KEY_LAST_TIME_DISMISSED_SPAM_REPORTED';
|
||||
static const String _keySpamReportState = 'KEY_SPAM_REPORT_STATE';
|
||||
|
||||
final SharedPreferences _sharedPreferences;
|
||||
|
||||
LocalSpamReportManager(this._sharedPreferences);
|
||||
|
||||
Future<DateTime> getLastTimeDismissedSpamReported() async {
|
||||
final timeStamp = _sharedPreferences.getInt(MailboxDashboardConstant.keyLastTimeDismissedSpamReported) ?? 0;
|
||||
final timeStamp = _sharedPreferences.getInt(_keyLastTimeDismissedSpamReported) ?? 0;
|
||||
log('LocalSpamReportManager::getLastTimeDismissedSpamReported:timeStamp: $timeStamp');
|
||||
final lastTimeDismissedSpamReported = DateTime.fromMillisecondsSinceEpoch(timeStamp);
|
||||
return lastTimeDismissedSpamReported;
|
||||
}
|
||||
|
||||
Future<bool> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported) async {
|
||||
final timeStamp = lastTimeDismissedSpamReported.millisecondsSinceEpoch;
|
||||
return await _sharedPreferences.setInt(MailboxDashboardConstant.keyLastTimeDismissedSpamReported,timeStamp);
|
||||
log('LocalSpamReportManager::storeLastTimeDismissedSpamReported:timeStamp: $timeStamp');
|
||||
return await _sharedPreferences.setInt(_keyLastTimeDismissedSpamReported, timeStamp);
|
||||
}
|
||||
|
||||
Future<bool> deleteLastTimeDismissedSpamReported() async {
|
||||
return await _sharedPreferences.remove(MailboxDashboardConstant.keyLastTimeDismissedSpamReported);
|
||||
return await _sharedPreferences.remove(_keyLastTimeDismissedSpamReported);
|
||||
}
|
||||
|
||||
Future<bool> deleteSpamReportState() async {
|
||||
return await _sharedPreferences.remove(MailboxDashboardConstant.keySpamReportState);
|
||||
return await _sharedPreferences.remove(_keySpamReportState);
|
||||
}
|
||||
|
||||
Future<SpamReportState> getSpamReportState() async {
|
||||
final spamReportState = _sharedPreferences.getString(MailboxDashboardConstant.keySpamReportState) ?? '';
|
||||
final spamReportState = _sharedPreferences.getString(_keySpamReportState) ?? '';
|
||||
return spamReportState == SpamReportState.disabled.keyValue ? SpamReportState.disabled : SpamReportState.enabled;
|
||||
}
|
||||
|
||||
Future<bool> storeSpamReportState(SpamReportState spamReportState) async {
|
||||
final spamReportState0 = spamReportState.keyValue;
|
||||
return await _sharedPreferences.setString(MailboxDashboardConstant.keySpamReportState, spamReportState0);
|
||||
return await _sharedPreferences.setString(_keySpamReportState, spamReportState0);
|
||||
}
|
||||
|
||||
Future<void> clear() async {
|
||||
|
||||
+10
-7
@@ -8,9 +8,10 @@ import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/spam_report_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_number_of_unread_spam_emails_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_spam_mailbox_cached_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/utils/mailbox_dashboard_constant.dart';
|
||||
|
||||
class GetSpamMailboxCachedInteractor {
|
||||
static const int spamReportBannerDisplayIntervalInHour = 12;
|
||||
|
||||
final SpamReportRepository _spamReportRepository;
|
||||
|
||||
GetSpamMailboxCachedInteractor(this._spamReportRepository);
|
||||
@@ -18,12 +19,7 @@ class GetSpamMailboxCachedInteractor {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetSpamMailboxCachedLoading());
|
||||
|
||||
final lastTimeDismissedSpamReported = await _spamReportRepository.getLastTimeDismissedSpamReported();
|
||||
final timeLast = DateTime.now().difference(lastTimeDismissedSpamReported);
|
||||
final checkTimeCondition = timeLast.inHours > MailboxDashboardConstant.spamReportBannerDisplayTimeOut;
|
||||
log('GetSpamMailboxCachedInteractor::execute:lastTimeDismissedSpamReported: $lastTimeDismissedSpamReported | timeLast: $timeLast | checkTimeCondition: $checkTimeCondition');
|
||||
if (checkTimeCondition) {
|
||||
if (await _validateIntervalToShowBanner()) {
|
||||
final spamMailbox = await _spamReportRepository.getSpamMailboxCached(accountId, userName);
|
||||
final countUnreadSpamMailbox = spamMailbox.unreadEmails?.value.value.toInt() ?? 0;
|
||||
if (countUnreadSpamMailbox > 0) {
|
||||
@@ -38,4 +34,11 @@ class GetSpamMailboxCachedInteractor {
|
||||
yield Left<Failure, Success>(GetSpamMailboxCachedFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _validateIntervalToShowBanner() async {
|
||||
final lastTimeDismissedSpamReported = await _spamReportRepository.getLastTimeDismissedSpamReported();
|
||||
final currentTime = DateTime.now().difference(lastTimeDismissedSpamReported);
|
||||
log('GetSpamMailboxCachedInteractor::_compareSpamReportTime:lastTimeDismissedSpamReported: $lastTimeDismissedSpamReported | currentTime: $currentTime');
|
||||
return currentTime.inHours > spamReportBannerDisplayIntervalInHour;
|
||||
}
|
||||
}
|
||||
+10
-7
@@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
@@ -8,9 +9,9 @@ import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/spam_report_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_number_of_unread_spam_emails_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_spam_mailbox_cached_interactor.dart';
|
||||
|
||||
class GetUnreadSpamMailboxInteractor {
|
||||
static const int conditionsForDisplayingSpamReportBanner = 4;
|
||||
final SpamReportRepository _spamReportRepository;
|
||||
|
||||
GetUnreadSpamMailboxInteractor(this._spamReportRepository);
|
||||
@@ -25,12 +26,7 @@ class GetUnreadSpamMailboxInteractor {
|
||||
) async* {
|
||||
try {
|
||||
yield Right(GetUnreadSpamMailboxLoading());
|
||||
final lastTimeDismissedSpamReported = await _spamReportRepository.getLastTimeDismissedSpamReported();
|
||||
final timeLast = DateTime.now().difference(lastTimeDismissedSpamReported);
|
||||
|
||||
final checkTimeCondition = (timeLast.inHours > 0) && (timeLast.inHours > conditionsForDisplayingSpamReportBanner);
|
||||
|
||||
if (checkTimeCondition) {
|
||||
if (await _validateIntervalToShowBanner()) {
|
||||
final response = await _spamReportRepository.getUnreadSpamMailbox(
|
||||
session,
|
||||
accountId,
|
||||
@@ -50,4 +46,11 @@ class GetUnreadSpamMailboxInteractor {
|
||||
yield Left(GetUnreadSpamMailboxFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _validateIntervalToShowBanner() async {
|
||||
final lastTimeDismissedSpamReported = await _spamReportRepository.getLastTimeDismissedSpamReported();
|
||||
final currentTime = DateTime.now().difference(lastTimeDismissedSpamReported);
|
||||
log('GetUnreadSpamMailboxInteractor::_compareSpamReportTime:lastTimeDismissedSpamReported: $lastTimeDismissedSpamReported | currentTime: $currentTime');
|
||||
return currentTime.inHours > GetSpamMailboxCachedInteractor.spamReportBannerDisplayIntervalInHour;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
class MailboxDashboardConstant {
|
||||
static const String keyLastTimeDismissedSpamReported = 'KEY_LAST_TIME_DISMISSED_SPAM_REPORTED';
|
||||
static const String keySpamReportState = 'KEY_SPAM_REPORT_STATE';
|
||||
static const int spamReportBannerDisplayTimeOut = 4;
|
||||
}
|
||||
Reference in New Issue
Block a user