TF-3977 Add disable spam banner in preferences setting
This commit is contained in:
@@ -8,11 +8,11 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_repor
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/unread_spam_emails_response.dart';
|
||||
|
||||
abstract class SpamReportDataSource {
|
||||
Future<bool> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported);
|
||||
Future<void> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported);
|
||||
|
||||
Future<DateTime> getLastTimeDismissedSpamReported();
|
||||
|
||||
Future<bool> deleteLastTimeDismissedSpamReported();
|
||||
Future<void> deleteLastTimeDismissedSpamReported();
|
||||
|
||||
Future<UnreadSpamEmailsResponse> findNumberOfUnreadSpamEmails(
|
||||
Session session,
|
||||
@@ -27,7 +27,5 @@ abstract class SpamReportDataSource {
|
||||
|
||||
Future<void> storeSpamReportState(SpamReportState spamReportState);
|
||||
|
||||
Future<void> deleteSpamReportState();
|
||||
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName);
|
||||
}
|
||||
-5
@@ -22,11 +22,6 @@ class HiveSpamReportDataSourceImpl extends SpamReportDataSource {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSpamReportState() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UnreadSpamEmailsResponse> findNumberOfUnreadSpamEmails(Session session, AccountId accountId, {MailboxFilterCondition? mailboxFilterCondition, UnsignedInt? limit}) {
|
||||
throw UnimplementedError();
|
||||
|
||||
+30
-18
@@ -5,35 +5,50 @@ import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_filter_condition.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/spam_report_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/local/local_spam_report_manager.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/unread_spam_emails_response.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/local/preferences_setting_manager.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/preferences/spam_report_config.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||
|
||||
class LocalSpamReportDataSourceImpl extends SpamReportDataSource {
|
||||
final LocalSpamReportManager _localSpamReportManager;
|
||||
final PreferencesSettingManager _preferencesSettingManager;
|
||||
final ExceptionThrower _exceptionThrower;
|
||||
|
||||
LocalSpamReportDataSourceImpl(this._localSpamReportManager, this._exceptionThrower);
|
||||
LocalSpamReportDataSourceImpl(
|
||||
this._preferencesSettingManager,
|
||||
this._exceptionThrower,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<DateTime> getLastTimeDismissedSpamReported() async {
|
||||
return Future.sync(() async {
|
||||
return await _localSpamReportManager.getLastTimeDismissedSpamReported();
|
||||
final spamReportConfig =
|
||||
await _preferencesSettingManager.getSpamReportConfig();
|
||||
return DateTime.fromMillisecondsSinceEpoch(
|
||||
spamReportConfig.lastTimeDismissedMilliseconds,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported) async {
|
||||
Future<void> storeLastTimeDismissedSpamReported(
|
||||
DateTime lastTimeDismissedSpamReported,
|
||||
) async {
|
||||
return Future.sync(() async {
|
||||
return await _localSpamReportManager.storeLastTimeDismissedSpamReported(lastTimeDismissedSpamReported);
|
||||
return await _preferencesSettingManager.updateSpamReport(
|
||||
lastTimeDismissedMilliseconds:
|
||||
lastTimeDismissedSpamReported.millisecondsSinceEpoch,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future<bool> deleteLastTimeDismissedSpamReported() {
|
||||
Future<void> deleteLastTimeDismissedSpamReported() {
|
||||
return Future.sync(() async {
|
||||
return await _localSpamReportManager.deleteLastTimeDismissedSpamReported();
|
||||
return await _preferencesSettingManager.updateSpamReport(
|
||||
lastTimeDismissedMilliseconds: 0,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@@ -49,24 +64,21 @@ class LocalSpamReportDataSourceImpl extends SpamReportDataSource {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSpamReportState() {
|
||||
return Future.sync(() async {
|
||||
return await _localSpamReportManager.deleteLastTimeDismissedSpamReported();
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SpamReportState> getSpamReportState() {
|
||||
return Future.sync(() async {
|
||||
return await _localSpamReportManager.getSpamReportState();
|
||||
final spamReportConfig =
|
||||
await _preferencesSettingManager.getSpamReportConfig();
|
||||
return spamReportConfig.spamReportState;
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> storeSpamReportState(SpamReportState spamReportState) {
|
||||
return Future.sync(() async {
|
||||
return await _localSpamReportManager.storeSpamReportState(spamReportState);
|
||||
return await _preferencesSettingManager.updateSpamReport(
|
||||
isEnabled: spamReportState == SpamReportState.enabled,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
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';
|
||||
|
||||
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(_keyLastTimeDismissedSpamReported) ?? 0;
|
||||
log('LocalSpamReportManager::getLastTimeDismissedSpamReported:timeStamp: $timeStamp');
|
||||
final lastTimeDismissedSpamReported = DateTime.fromMillisecondsSinceEpoch(timeStamp);
|
||||
return lastTimeDismissedSpamReported;
|
||||
}
|
||||
|
||||
Future<bool> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported) async {
|
||||
final timeStamp = lastTimeDismissedSpamReported.millisecondsSinceEpoch;
|
||||
log('LocalSpamReportManager::storeLastTimeDismissedSpamReported:timeStamp: $timeStamp');
|
||||
return await _sharedPreferences.setInt(_keyLastTimeDismissedSpamReported, timeStamp);
|
||||
}
|
||||
|
||||
Future<bool> deleteLastTimeDismissedSpamReported() async {
|
||||
return await _sharedPreferences.remove(_keyLastTimeDismissedSpamReported);
|
||||
}
|
||||
|
||||
Future<bool> deleteSpamReportState() async {
|
||||
return await _sharedPreferences.remove(_keySpamReportState);
|
||||
}
|
||||
|
||||
Future<SpamReportState> getSpamReportState() async {
|
||||
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(_keySpamReportState, spamReportState0);
|
||||
}
|
||||
|
||||
Future<void> clear() async {
|
||||
await deleteLastTimeDismissedSpamReported();
|
||||
await deleteSpamReportState();
|
||||
}
|
||||
}
|
||||
@@ -36,11 +36,6 @@ class SpamReportRepositoryImpl extends SpamReportRepository {
|
||||
return mapDataSource[DataSourceType.local]!.storeSpamReportState(spamReportState);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSpamReportState() {
|
||||
return mapDataSource[DataSourceType.local]!.deleteSpamReportState();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName) {
|
||||
return mapDataSource[DataSourceType.hiveCache]!.getSpamMailboxCached(accountId, userName);
|
||||
|
||||
Reference in New Issue
Block a user