TF-3977 Separate settings keys for easier in conflict
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/converters/default_preferences_config_converter.dart';
|
||||
|
||||
class DefaultPreferencesConfig extends PreferencesConfig {
|
||||
final dynamic data;
|
||||
|
||||
DefaultPreferencesConfig(this.data);
|
||||
|
||||
factory DefaultPreferencesConfig.fromJson(Map<String, dynamic> json) =>
|
||||
const DefaultPreferencesConfigConverter().fromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() =>
|
||||
const DefaultPreferencesConfigConverter().toJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [data];
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
|
||||
class EmptyPreferencesConfig extends PreferencesConfig {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => {};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class PreferencesConfig with EquatableMixin {
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/spam_report_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/thread_detail_config.dart';
|
||||
|
||||
class PreferencesSetting with EquatableMixin {
|
||||
final List<PreferencesConfig> configs;
|
||||
|
||||
PreferencesSetting(this.configs);
|
||||
|
||||
factory PreferencesSetting.initial() {
|
||||
return PreferencesSetting([
|
||||
ThreadDetailConfig.initial(),
|
||||
SpamReportConfig.initial(),
|
||||
]);
|
||||
}
|
||||
|
||||
ThreadDetailConfig get threadConfig {
|
||||
final threadConfig =
|
||||
configs.firstWhereOrNull((config) => config is ThreadDetailConfig);
|
||||
if (threadConfig != null) {
|
||||
return threadConfig as ThreadDetailConfig;
|
||||
} else {
|
||||
return ThreadDetailConfig.initial();
|
||||
}
|
||||
}
|
||||
|
||||
SpamReportConfig get spamReportConfig {
|
||||
final spamConfig =
|
||||
configs.firstWhereOrNull((config) => config is SpamReportConfig);
|
||||
if (spamConfig != null) {
|
||||
return spamConfig as SpamReportConfig;
|
||||
} else {
|
||||
return SpamReportConfig.initial();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [configs];
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
|
||||
part 'spam_report_config.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class SpamReportConfig extends PreferencesConfig {
|
||||
final bool isEnabled;
|
||||
final int lastTimeDismissedMilliseconds;
|
||||
|
||||
SpamReportConfig({
|
||||
this.isEnabled = true,
|
||||
this.lastTimeDismissedMilliseconds = 0,
|
||||
});
|
||||
|
||||
factory SpamReportConfig.initial() {
|
||||
return SpamReportConfig(
|
||||
isEnabled: true,
|
||||
lastTimeDismissedMilliseconds: 0,
|
||||
);
|
||||
}
|
||||
|
||||
factory SpamReportConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$SpamReportConfigFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$SpamReportConfigToJson(this);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isEnabled, lastTimeDismissedMilliseconds];
|
||||
}
|
||||
|
||||
extension SpamReportConfigExtension on SpamReportConfig {
|
||||
SpamReportConfig copyWith({
|
||||
bool? isEnabled,
|
||||
int? lastTimeDismissedMilliseconds,
|
||||
}) {
|
||||
return SpamReportConfig(
|
||||
isEnabled: isEnabled ?? this.isEnabled,
|
||||
lastTimeDismissedMilliseconds:
|
||||
lastTimeDismissedMilliseconds ?? this.lastTimeDismissedMilliseconds,
|
||||
);
|
||||
}
|
||||
|
||||
SpamReportState get spamReportState =>
|
||||
isEnabled ? SpamReportState.enabled : SpamReportState.disabled;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
|
||||
part 'thread_detail_config.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ThreadDetailConfig extends PreferencesConfig {
|
||||
final bool isEnabled;
|
||||
|
||||
ThreadDetailConfig({this.isEnabled = false});
|
||||
|
||||
factory ThreadDetailConfig.initial() {
|
||||
return ThreadDetailConfig(
|
||||
isEnabled: false,
|
||||
);
|
||||
}
|
||||
|
||||
factory ThreadDetailConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$ThreadDetailConfigFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$ThreadDetailConfigToJson(this);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isEnabled];
|
||||
}
|
||||
|
||||
extension ThreadDetailConfigExtension on ThreadDetailConfig {
|
||||
ThreadDetailConfig copyWith({bool? isEnabled}) {
|
||||
return ThreadDetailConfig(
|
||||
isEnabled: isEnabled ?? this.isEnabled,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/preferences/preferences_root.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_setting.dart';
|
||||
|
||||
abstract class ManageAccountRepository {
|
||||
Future<void> persistLanguage(Locale localeCurrent);
|
||||
|
||||
Future<void> updateLocalSettings(PreferencesRoot preferencesRoot);
|
||||
Future<PreferencesSetting> toggleLocalSettingsState(PreferencesConfig preferencesConfig);
|
||||
|
||||
Future<PreferencesRoot> getLocalSettings();
|
||||
Future<PreferencesSetting> getLocalSettings();
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/preferences/preferences_root.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_setting.dart';
|
||||
|
||||
class GettingLocalSettingsState extends LoadingState {}
|
||||
|
||||
class GetLocalSettingsSuccess extends UIState {
|
||||
GetLocalSettingsSuccess(this.preferencesRoot);
|
||||
GetLocalSettingsSuccess(this.preferencesSetting);
|
||||
|
||||
final PreferencesRoot preferencesRoot;
|
||||
final PreferencesSetting preferencesSetting;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [preferencesRoot];
|
||||
List<Object?> get props => [preferencesSetting];
|
||||
}
|
||||
|
||||
class GetLocalSettingsFailure extends FeatureFailure {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/preferences/preferences_root.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_setting.dart';
|
||||
|
||||
class UpdatingLocalSettingsState extends LoadingState {}
|
||||
|
||||
class UpdateLocalSettingsSuccess extends UIState {
|
||||
final PreferencesRoot preferencesRoot;
|
||||
final PreferencesSetting preferencesSetting;
|
||||
|
||||
UpdateLocalSettingsSuccess(this.preferencesRoot);
|
||||
UpdateLocalSettingsSuccess(this.preferencesSetting);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [preferencesRoot];
|
||||
List<Object?> get props => [preferencesSetting];
|
||||
}
|
||||
|
||||
class UpdateLocalSettingsFailure extends FeatureFailure {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/get_local_settings_state.dart';
|
||||
@@ -16,7 +15,6 @@ class GetLocalSettingsInteractor {
|
||||
final result = await _manageAccountRepository.getLocalSettings();
|
||||
yield Right(GetLocalSettingsSuccess(result));
|
||||
} catch (e) {
|
||||
logError('$runtimeType::execute(): exception: $e');
|
||||
yield Left(GetLocalSettingsFailure(exception: e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
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:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/update_local_settings_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/preferences/preferences_root.dart';
|
||||
|
||||
class UpdateLocalSettingsInteractor {
|
||||
const UpdateLocalSettingsInteractor(this._manageAccountRepository);
|
||||
|
||||
final ManageAccountRepository _manageAccountRepository;
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
PreferencesRoot preferencesRoot,
|
||||
) async* {
|
||||
Stream<Either<Failure, Success>> execute(PreferencesConfig preferencesConfig) async* {
|
||||
try {
|
||||
yield Right(UpdatingLocalSettingsState());
|
||||
await _manageAccountRepository.updateLocalSettings(preferencesRoot);
|
||||
yield Right(UpdateLocalSettingsSuccess(preferencesRoot));
|
||||
final preferencesSetting = await _manageAccountRepository.toggleLocalSettingsState(
|
||||
preferencesConfig,
|
||||
);
|
||||
yield Right(UpdateLocalSettingsSuccess(preferencesSetting));
|
||||
} catch (e) {
|
||||
logError('$runtimeType::execute(): exception: $e');
|
||||
yield Left(UpdateLocalSettingsFailure(exception: e));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user