TF-2311 Remove session page view
(cherry picked from commit 557d67b816c91076d8cafc9aa680e62d5b012f5b)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/core_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/default_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/empty_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/mail_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/mdn_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/submission_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/vacation_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/websocket_capability.dart';
|
||||
|
||||
class CapabilityPropertiesConverter {
|
||||
|
||||
Map<String, dynamic>? toJson(CapabilityProperties properties) {
|
||||
if (properties is CoreCapability) {
|
||||
return properties.toJson();
|
||||
} else if (properties is MailCapability) {
|
||||
return properties.toJson();
|
||||
} else if (properties is SubmissionCapability) {
|
||||
return properties.toJson();
|
||||
} else if (properties is VacationCapability) {
|
||||
return properties.toJson();
|
||||
} else if (properties is WebSocketCapability) {
|
||||
return properties.toJson();
|
||||
} else if (properties is MdnCapability) {
|
||||
return properties.toJson();
|
||||
} else if (properties is DefaultCapability) {
|
||||
return properties.properties;
|
||||
} else if (properties is EmptyCapability) {
|
||||
return properties.toJson();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/account/account.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/extensions/session_account_extension.dart';
|
||||
|
||||
class SessionAccountConverter {
|
||||
|
||||
MapEntry<String, dynamic> convertToMapEntry(AccountId accountId, Account account) {
|
||||
return MapEntry(
|
||||
const AccountIdConverter().toJson(accountId),
|
||||
account.toJson()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:jmap_dart_client/http/converter/capability_identifier_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/converter/capability_properties_converter.dart';
|
||||
|
||||
class SessionCapabilitiesConverter {
|
||||
|
||||
MapEntry<String, dynamic> convertToMapEntry(CapabilityIdentifier identifier, CapabilityProperties properties) {
|
||||
return MapEntry(
|
||||
const CapabilityIdentifierConverter().toJson(identifier),
|
||||
CapabilityPropertiesConverter().toJson(properties)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/capability_identifier_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
|
||||
class SessionPrimaryAccountConverter {
|
||||
|
||||
MapEntry<String, dynamic> convertToMapEntry(CapabilityIdentifier identifier, AccountId accountId) {
|
||||
return MapEntry(
|
||||
const CapabilityIdentifierConverter().toJson(identifier),
|
||||
const AccountIdConverter().toJson(accountId)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
import 'package:jmap_dart_client/http/converter/account_name_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/account/account.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/converter/session_capabilities_converter.dart';
|
||||
|
||||
extension SessionAccountExtension on Account {
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final val = <String, dynamic>{};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('name', const AccountNameConverter().toJson(name));
|
||||
writeNotNull('isPersonal', isPersonal);
|
||||
writeNotNull('isReadOnly', isReadOnly);
|
||||
writeNotNull('accountCapabilities', accountCapabilities.map((key, value) => SessionCapabilitiesConverter().convertToMapEntry(key, value)));
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:core/presentation/extensions/uri_extension.dart';
|
||||
import 'package:jmap_dart_client/http/converter/state_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/user_name_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/home/data/model/session_hive_obj.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/converter/session_account_converter.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/converter/session_capabilities_converter.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/converter/session_primary_account_converter.dart';
|
||||
|
||||
extension SessionExtensions on Session {
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final val = <String, dynamic>{};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('capabilities', capabilities.map((key, value) => SessionCapabilitiesConverter().convertToMapEntry(key, value)));
|
||||
writeNotNull('accounts', accounts.map((key, value) => SessionAccountConverter().convertToMapEntry(key, value)));
|
||||
writeNotNull('primaryAccounts', primaryAccounts.map((key, value) => SessionPrimaryAccountConverter().convertToMapEntry(key, value)));
|
||||
writeNotNull('username', const UserNameConverter().toJson(username));
|
||||
writeNotNull('apiUrl', apiUrl.toString());
|
||||
writeNotNull('downloadUrl', downloadUrl.toString());
|
||||
writeNotNull('uploadUrl', uploadUrl.toString());
|
||||
writeNotNull('eventSourceUrl', eventSourceUrl.toString());
|
||||
writeNotNull('state', const StateConverter().toJson(state));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
SessionHiveObj toHiveObj() => SessionHiveObj(value: jsonEncode(toJson()));
|
||||
|
||||
String getQualifiedApiUrl({String? baseUrl}) {
|
||||
if (baseUrl != null) {
|
||||
return apiUrl.toQualifiedUrl(baseUrl: Uri.parse(baseUrl)).toString();
|
||||
} else {
|
||||
return apiUrl.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
|
||||
abstract class SessionRepository {
|
||||
Future<Session> getSession();
|
||||
|
||||
Future<void> storeSession(Session session);
|
||||
|
||||
Future<Session> getStoredSession();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
|
||||
class GetSessionLoading extends LoadingState {}
|
||||
|
||||
class GetSessionSuccess extends UIState {
|
||||
final Session session;
|
||||
|
||||
GetSessionSuccess(this.session);
|
||||
|
||||
@override
|
||||
List<Object> get props => [session];
|
||||
}
|
||||
|
||||
class GetSessionFailure extends FeatureFailure {
|
||||
final dynamic remoteException;
|
||||
|
||||
GetSessionFailure({dynamic exception, this.remoteException}) : super(exception: exception);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
|
||||
class StoreSessionLoading extends LoadingState {}
|
||||
|
||||
class StoreSessionSuccess extends UIState {}
|
||||
|
||||
class StoreSessionFailure extends FeatureFailure {
|
||||
|
||||
StoreSessionFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/repository/session_repository.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart';
|
||||
|
||||
class GetSessionInteractor {
|
||||
final SessionRepository sessionRepository;
|
||||
|
||||
GetSessionInteractor(this.sessionRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetSessionLoading());
|
||||
final session = await sessionRepository.getSession();
|
||||
yield Right<Failure, Success>(GetSessionSuccess(session));
|
||||
} catch (e) {
|
||||
if (PlatformInfo.isMobile) {
|
||||
yield* _getStoredSessionFromCache(remoteException: e);
|
||||
} else {
|
||||
yield Left<Failure, Success>(GetSessionFailure(exception: e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Stream<Either<Failure, Success>> _getStoredSessionFromCache({dynamic remoteException}) async* {
|
||||
try {
|
||||
log('GetSessionInteractor::_getStoredSessionFromCache:');
|
||||
yield Right<Failure, Success>(GetSessionLoading());
|
||||
final session = await sessionRepository.getStoredSession();
|
||||
yield Right<Failure, Success>(GetSessionSuccess(session));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetSessionFailure(
|
||||
exception: e,
|
||||
remoteException: remoteException
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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/home/domain/repository/session_repository.dart';
|
||||
import 'package:tmail_ui_user/features/home/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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user