TF-2269 Clear local spam report data when logout and upgrade app

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 55cd12b2f4cab207dfd525b374b58b60843ce735)
This commit is contained in:
dab246
2023-11-06 11:39:17 +07:00
committed by Dat Vu
parent 39bca48671
commit b4cf796a57
7 changed files with 35 additions and 54 deletions
@@ -11,11 +11,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';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class SpamReportCacheDataSourceImpl extends SpamReportDataSource {
class HiveSpamReportDataSourceImpl extends SpamReportDataSource {
final MailboxCacheManager _mailboxCacheManager;
final ExceptionThrower _exceptionThrower;
SpamReportCacheDataSourceImpl(this._mailboxCacheManager, this._exceptionThrower);
HiveSpamReportDataSourceImpl(this._mailboxCacheManager, this._exceptionThrower);
@override
Future<bool> deleteLastTimeDismissedSpamReported() {
@@ -5,35 +5,35 @@ 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/share_preference_spam_report_data_source.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/main/exceptions/exception_thrower.dart';
class SharePreferenceSpamReportDataSourceImpl extends SpamReportDataSource {
final SharePreferenceSpamReportDataSource _sharePreferenceSpamReportDataSource;
class LocalSpamReportDataSourceImpl extends SpamReportDataSource {
final LocalSpamReportManager _localSpamReportManager;
final ExceptionThrower _exceptionThrower;
SharePreferenceSpamReportDataSourceImpl(this._sharePreferenceSpamReportDataSource, this._exceptionThrower);
LocalSpamReportDataSourceImpl(this._localSpamReportManager, this._exceptionThrower);
@override
Future<DateTime> getLastTimeDismissedSpamReported() async {
return Future.sync(() async {
return await _sharePreferenceSpamReportDataSource.getLastTimeDismissedSpamReported();
return await _localSpamReportManager.getLastTimeDismissedSpamReported();
}).catchError(_exceptionThrower.throwException);
}
@override
Future<bool> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported) async {
return Future.sync(() async {
return await _sharePreferenceSpamReportDataSource.storeLastTimeDismissedSpamReported(lastTimeDismissedSpamReported);
return await _localSpamReportManager.storeLastTimeDismissedSpamReported(lastTimeDismissedSpamReported);
}).catchError(_exceptionThrower.throwException);
}
@override
Future<bool> deleteLastTimeDismissedSpamReported() {
return Future.sync(() async {
return await _sharePreferenceSpamReportDataSource.deleteLastTimeDismissedSpamReported();
return await _localSpamReportManager.deleteLastTimeDismissedSpamReported();
}).catchError(_exceptionThrower.throwException);
}
@@ -52,21 +52,21 @@ class SharePreferenceSpamReportDataSourceImpl extends SpamReportDataSource {
@override
Future<void> deleteSpamReportState() {
return Future.sync(() async {
return await _sharePreferenceSpamReportDataSource.deleteLastTimeDismissedSpamReported();
return await _localSpamReportManager.deleteLastTimeDismissedSpamReported();
}).catchError(_exceptionThrower.throwException);
}
@override
Future<SpamReportState> getSpamReportState() {
return Future.sync(() async {
return await _sharePreferenceSpamReportDataSource.getSpamReportState();
return await _localSpamReportManager.getSpamReportState();
}).catchError(_exceptionThrower.throwException);
}
@override
Future<void> storeSpamReportState(SpamReportState spamReportState) {
return Future.sync(() async {
return await _sharePreferenceSpamReportDataSource.storeSpamReportState(spamReportState);
return await _localSpamReportManager.storeSpamReportState(spamReportState);
}).catchError(_exceptionThrower.throwException);
}
@@ -1,69 +1,43 @@
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/core/unsigned_int.dart';
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:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/spam_report_datasource.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/mailbox_dashboard/domain/utils/mailbox_dashboard_constant.dart';
class SharePreferenceSpamReportDataSource extends SpamReportDataSource {
class LocalSpamReportManager {
final SharedPreferences _sharedPreferences;
SharePreferenceSpamReportDataSource(this._sharedPreferences);
LocalSpamReportManager(this._sharedPreferences);
@override
Future<DateTime> getLastTimeDismissedSpamReported() async {
final timeStamp = _sharedPreferences.getInt(MailboxDashboardConstant.keyLastTimeDismissedSpamReported) ?? 0;
final lastTimeDismissedSpamReported = DateTime.fromMillisecondsSinceEpoch(timeStamp);
return lastTimeDismissedSpamReported;
}
@override
Future<bool> storeLastTimeDismissedSpamReported(DateTime lastTimeDismissedSpamReported) async {
final timeStamp = lastTimeDismissedSpamReported.millisecondsSinceEpoch;
return await _sharedPreferences.setInt(MailboxDashboardConstant.keyLastTimeDismissedSpamReported,timeStamp);
}
@override
Future<bool> deleteLastTimeDismissedSpamReported() async {
return await _sharedPreferences.remove(MailboxDashboardConstant.keyLastTimeDismissedSpamReported);
}
@override
Future<UnreadSpamEmailsResponse> findNumberOfUnreadSpamEmails(
Session session,
AccountId accountId,
{
MailboxFilterCondition? mailboxFilterCondition,
UnsignedInt? limit
}
) {
throw UnimplementedError();
}
@override
Future<bool> deleteSpamReportState() async {
return await _sharedPreferences.remove(MailboxDashboardConstant.keySpamReportState);
}
@override
Future<SpamReportState> getSpamReportState() async {
final spamReportState = _sharedPreferences.getString(MailboxDashboardConstant.keySpamReportState) ?? '';
return spamReportState == SpamReportState.disabled.keyValue ? SpamReportState.disabled : SpamReportState.enabled;
}
@override
Future<bool> storeSpamReportState(SpamReportState spamReportState) async {
final spamReportState0 = spamReportState.keyValue;
return await _sharedPreferences.setString(MailboxDashboardConstant.keySpamReportState, spamReportState0);
}
@override
Future<Mailbox> getSpamMailboxCached(AccountId accountId, UserName userName) {
throw UnimplementedError();
Future<void> clear() async {
await deleteLastTimeDismissedSpamReported();
await deleteSpamReportState();
}
}