TF-1899 Implement store session to hive
(cherry picked from commit e42b61f67a8352c9d9bc30207031989785295b65)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/model/session_hive_obj.dart';
|
||||
|
||||
class SessionHiveCacheClient extends HiveCacheClient<SessionHiveObj> {
|
||||
|
||||
@override
|
||||
String get tableName => CachingConstants.sessionCacheBoxName;
|
||||
|
||||
@override
|
||||
bool get encryption => true;
|
||||
}
|
||||
@@ -24,6 +24,7 @@ class CachingConstants {
|
||||
static const String incomingEmailedCacheBoxName = 'incoming_emailed_cache_box';
|
||||
static const String openedEmailCacheBoxName = 'opened_email_cache_box';
|
||||
static const String sendingEmailCacheBoxName = 'sending_email_cache_box';
|
||||
static const String sessionCacheBoxName = 'session_cache_box';
|
||||
|
||||
static const String incomingEmailedContentFolderName = 'incoming_emailed';
|
||||
static const String openedEmailContentFolderName = 'opened_email';
|
||||
|
||||
@@ -2,4 +2,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
|
||||
abstract class SessionDataSource {
|
||||
Future<Session> getSession();
|
||||
|
||||
Future<void> storeSession(Session session);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/session_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/datasource/session_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/model/session_hive_obj.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/extensions/session_extensions.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||
|
||||
class HiveSessionDataSourceImpl extends SessionDataSource {
|
||||
|
||||
final SessionHiveCacheClient _sessionHiveCacheClient;
|
||||
final ExceptionThrower _exceptionThrower;
|
||||
|
||||
HiveSessionDataSourceImpl(this._sessionHiveCacheClient, this._exceptionThrower);
|
||||
|
||||
@override
|
||||
Future<Session> getSession() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> storeSession(Session session) {
|
||||
return Future.sync(() async {
|
||||
return _sessionHiveCacheClient.insertItem(SessionHiveObj.keyValue, session.toHiveObj());
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,9 @@ class SessionDataSourceImpl extends SessionDataSource {
|
||||
return await _sessionAPI.getSession();
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> storeSession(Session session) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
class NotFoundSessionHiveObject implements Exception {}
|
||||
@@ -1,15 +1,21 @@
|
||||
import 'package:core/data/model/source_type/data_source_type.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/datasource/session_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/repository/session_repository.dart';
|
||||
|
||||
class SessionRepositoryImpl extends SessionRepository {
|
||||
|
||||
final SessionDataSource sessionDataSource;
|
||||
final Map<DataSourceType, SessionDataSource> sessionDataSource;
|
||||
|
||||
SessionRepositoryImpl(this.sessionDataSource);
|
||||
|
||||
@override
|
||||
Future<Session> getSession() {
|
||||
return sessionDataSource.getSession();
|
||||
return sessionDataSource[DataSourceType.network]!.getSession();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> storeSession(Session session) {
|
||||
return sessionDataSource[DataSourceType.hiveCache]!.storeSession(session);
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
|
||||
abstract class SessionRepository {
|
||||
Future<Session> getSession();
|
||||
|
||||
Future<void> storeSession(Session session);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
|
||||
class StoreSessionLoading extends UIState {}
|
||||
|
||||
class StoreSessionSuccess extends UIState {}
|
||||
|
||||
class StoreSessionFailure extends FeatureFailure {
|
||||
|
||||
StoreSessionFailure(dynamic exception) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/repository/session_repository.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/state/store_session_state.dart';
|
||||
|
||||
class StoreSessionInteractor {
|
||||
final SessionRepository sessionRepository;
|
||||
|
||||
StoreSessionInteractor(this.sessionRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(Session session) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StoreSessionLoading());
|
||||
await sessionRepository.storeSession(session);
|
||||
yield Right<Failure, Success>(StoreSessionSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(StoreSessionFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import 'package:tmail_ui_user/features/caching/clients/recent_login_url_cache_cl
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_login_username_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_search_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/sending_email_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/session_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/state_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/subscription_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/token_oidc_cache_client.dart';
|
||||
@@ -80,6 +81,7 @@ class LocalBindings extends Bindings {
|
||||
Get.put(OpenedEmailCacheManager(Get.find<OpenedEmailHiveCacheClient>(), Get.find<FileUtils>()));
|
||||
Get.put(SendingEmailHiveCacheClient());
|
||||
Get.put(SendingEmailCacheManager(Get.find<SendingEmailHiveCacheClient>()));
|
||||
Get.put(SessionHiveCacheClient());
|
||||
Get.put(CachingManager(
|
||||
Get.find<MailboxCacheClient>(),
|
||||
Get.find<StateCacheClient>(),
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import 'package:core/data/model/source_type/data_source_type.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/session_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/datasource/session_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/datasource_impl/hive_session_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/datasource_impl/session_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/network/session_api.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/repository/session_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/repository/session_repository.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/usecases/get_session_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
|
||||
|
||||
class SessionBindings extends InteractorsBindings {
|
||||
@@ -18,8 +22,11 @@ class SessionBindings extends InteractorsBindings {
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.put(SessionDataSourceImpl(
|
||||
Get.find<SessionAPI>(),
|
||||
Get.find<RemoteExceptionThrower>()));
|
||||
Get.find<SessionAPI>(),
|
||||
Get.find<RemoteExceptionThrower>()));
|
||||
Get.put(HiveSessionDataSourceImpl(
|
||||
Get.find<SessionHiveCacheClient>(),
|
||||
Get.find<CacheExceptionThrower>()));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -34,6 +41,9 @@ class SessionBindings extends InteractorsBindings {
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {
|
||||
Get.put(SessionRepositoryImpl(Get.find<SessionDataSource>()));
|
||||
Get.put(SessionRepositoryImpl({
|
||||
DataSourceType.network: Get.find<SessionDataSource>(),
|
||||
DataSourceType.hiveCache: Get.find<HiveSessionDataSourceImpl>(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user