Cache Linagora Ecosystem in controller for Scribe
This commit is contained in:
@@ -58,23 +58,4 @@ class LinagoraEcosystemApi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> getScribePromptUrl(String baseUrl) async {
|
||||
LinagoraEcosystem? linagoraEcosystem;
|
||||
|
||||
try {
|
||||
linagoraEcosystem = await getLinagoraEcosystem(baseUrl);
|
||||
} catch (exception) {
|
||||
if (exception is NotFoundLinagoraEcosystem) {
|
||||
return null;
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
|
||||
final scribePromptProperty =
|
||||
linagoraEcosystem.properties?[LinagoraEcosystemIdentifier.scribePromptUrl] as ApiUrlLinagoraEcosystem?;
|
||||
log('LinagoraEcosystemApi::getScribePromptUrl: scribePromptProperty = $scribePromptProperty');
|
||||
|
||||
return scribePromptProperty?.value;
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,4 +1,5 @@
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/network/linagora_ecosystem_api.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/linagora_ecosystem_repository.dart';
|
||||
|
||||
class LinagoraEcosystemRepositoryImpl extends LinagoraEcosystemRepository {
|
||||
@@ -7,7 +8,8 @@ class LinagoraEcosystemRepositoryImpl extends LinagoraEcosystemRepository {
|
||||
LinagoraEcosystemRepositoryImpl(this._linagoraEcosystemApi);
|
||||
|
||||
@override
|
||||
Future<String?> getScribePromptUrl(String baseUrl) {
|
||||
return _linagoraEcosystemApi.getScribePromptUrl(baseUrl);
|
||||
Future<LinagoraEcosystem> getLinagoraEcosystem(String baseUrl) {
|
||||
return _linagoraEcosystemApi.getLinagoraEcosystem(baseUrl);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/api_url_linagora_ecosystem.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/app_linagora_ecosystem.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/converters/linagora_ecosystem_converter.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem_identifier.dart';
|
||||
@@ -44,4 +45,7 @@ extension LinagoraEcosystemExtension on LinagoraEcosystem {
|
||||
List<AppLinagoraEcosystem> get listAppLinagoraEcosystemOnAndroid {
|
||||
return listAppLinagoraEcosystem.where((app) => app.isAppAndroidEnabled).toList();
|
||||
}
|
||||
|
||||
String? get scribePromptUrl =>
|
||||
(properties?[LinagoraEcosystemIdentifier.scribePromptUrl] as ApiUrlLinagoraEcosystem?)?.value;
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
||||
|
||||
abstract class LinagoraEcosystemRepository {
|
||||
Future<String?> getScribePromptUrl(String baseUrl);
|
||||
Future<LinagoraEcosystem> getLinagoraEcosystem(String baseUrl);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
||||
|
||||
class GetLinagoraEcosystemSuccess extends Success {
|
||||
final LinagoraEcosystem linagoraEcosystem;
|
||||
|
||||
GetLinagoraEcosystemSuccess(this.linagoraEcosystem);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [linagoraEcosystem];
|
||||
}
|
||||
|
||||
class GetLinagoraEcosystemFailure extends Failure {
|
||||
final dynamic exception;
|
||||
|
||||
GetLinagoraEcosystemFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
|
||||
class GetScribePromptUrlSuccess extends Success {
|
||||
final String? promptUrl;
|
||||
|
||||
GetScribePromptUrlSuccess(this.promptUrl);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [promptUrl];
|
||||
}
|
||||
|
||||
class GetScribePromptUrlFailure extends Failure {
|
||||
final dynamic exception;
|
||||
|
||||
GetScribePromptUrlFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
}
|
||||
+6
-6
@@ -1,20 +1,20 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/linagora_ecosystem_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_scribe_prompt_url_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_linagora_ecosystem_state.dart';
|
||||
|
||||
class GetScribePromptUrlInteractor {
|
||||
class GetLinagoraEcosystemInteractor {
|
||||
final LinagoraEcosystemRepository _linagoraEcosystemRepository;
|
||||
|
||||
GetScribePromptUrlInteractor(this._linagoraEcosystemRepository);
|
||||
GetLinagoraEcosystemInteractor(this._linagoraEcosystemRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(String baseUrl) async* {
|
||||
try {
|
||||
final promptUrl = await _linagoraEcosystemRepository.getScribePromptUrl(baseUrl);
|
||||
final linagoraEcosystem = await _linagoraEcosystemRepository.getLinagoraEcosystem(baseUrl);
|
||||
|
||||
yield Right(GetScribePromptUrlSuccess(promptUrl));
|
||||
yield Right(GetLinagoraEcosystemSuccess(linagoraEcosystem));
|
||||
} catch (e) {
|
||||
yield Left(GetScribePromptUrlFailure(e));
|
||||
yield Left(GetLinagoraEcosystemFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -96,7 +96,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_all
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_app_dashboard_configuration_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_app_grid_linagra_ecosystem_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_composer_cache_on_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_scribe_prompt_url_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_linagora_system_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_spam_mailbox_cached_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_spam_report_state_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_stored_email_sort_order_interactor.dart';
|
||||
@@ -384,7 +384,7 @@ class MailboxDashBoardBindings extends BaseBindings {
|
||||
Get.lazyPut(() => EmptySpamFolderInteractor(Get.find<ThreadRepository>()));
|
||||
Get.lazyPut(() => GetAppDashboardConfigurationInteractor(Get.find<AppGridRepository>()));
|
||||
Get.lazyPut(() => GetAppGridLinagraEcosystemInteractor(Get.find<AppGridRepository>()));
|
||||
Get.lazyPut(() => GetScribePromptUrlInteractor(Get.find<LinagoraEcosystemRepository>()));
|
||||
Get.lazyPut(() => GetLinagoraEcosystemInteractor(Get.find<LinagoraEcosystemRepository>()));
|
||||
Get.lazyPut(() => GetEmailByIdInteractor(
|
||||
Get.find<ThreadRepository>(),
|
||||
Get.find<EmailRepository>()));
|
||||
|
||||
+8
-6
@@ -106,7 +106,7 @@ import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_action
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/exceptions/spam_report_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_composer_cache_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_scribe_prompt_url_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_linagora_ecosystem_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_stored_email_sort_order_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_text_formatting_menu_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/remove_email_drafts_state.dart';
|
||||
@@ -156,6 +156,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/sear
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/quick_search_filter.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/search_email_filter.dart';
|
||||
import 'package:tmail_ui_user/features/mailto/presentation/model/mailto_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/ai_scribe_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/create_new_rule_filter_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/get_ai_scribe_config_state.dart';
|
||||
@@ -338,6 +339,7 @@ class MailboxDashBoardController extends ReloadableController
|
||||
StreamSubscription<DeepLinkData?>? _deepLinkDataStreamSubscription;
|
||||
int minInputLengthAutocomplete = AppConfig.defaultMinInputLengthAutocomplete;
|
||||
EmailSortOrderType currentSortOrder = SearchEmailFilter.defaultSortOrder;
|
||||
LinagoraEcosystem? cachedLinagoraEcosystem;
|
||||
PaywallController? paywallController;
|
||||
final workerObxVariables = <Worker>[];
|
||||
|
||||
@@ -544,8 +546,8 @@ class MailboxDashBoardController extends ReloadableController
|
||||
updateTextFormattingMenuState(success.isDisplayed);
|
||||
} else if (success is GetAIScribeConfigSuccess) {
|
||||
handleLoadAIScribeConfigSuccess(success.aiScribeConfig);
|
||||
} else if (success is GetScribePromptUrlSuccess) {
|
||||
handleGetScribePromptUrlSuccess(success);
|
||||
} else if (success is GetLinagoraEcosystemSuccess) {
|
||||
handleGetLinagoraEcosystemSuccess(success);
|
||||
} else {
|
||||
super.handleSuccessViewState(success);
|
||||
}
|
||||
@@ -596,8 +598,8 @@ class MailboxDashBoardController extends ReloadableController
|
||||
updateTextFormattingMenuState(false);
|
||||
} else if (failure is GetAIScribeConfigFailure) {
|
||||
handleLoadAIScribeConfigFailure();
|
||||
} else if (failure is GetScribePromptUrlFailure) {
|
||||
handleGetScribePromptUrlFailure(failure);
|
||||
} else if (failure is GetLinagoraEcosystemFailure) {
|
||||
handleGetLinagoraEcosystemFailure(failure);
|
||||
} else {
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
@@ -929,7 +931,7 @@ class MailboxDashBoardController extends ReloadableController
|
||||
injectWebSocket(session: session, accountId: currentAccountId);
|
||||
}
|
||||
|
||||
loadScribePromptUrl();
|
||||
loadLinagoraEcosystem();
|
||||
}
|
||||
|
||||
void _handleMailtoURL(MailtoArguments arguments) {
|
||||
|
||||
+24
-19
@@ -1,44 +1,49 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:scribe/scribe/ai/data/service/prompt_service.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_scribe_prompt_url_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_scribe_prompt_url_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_linagora_ecosystem_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_linagora_system_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
extension SetupScribePromptUrlExtension on MailboxDashBoardController {
|
||||
void loadScribePromptUrl() {
|
||||
final interactor = getBinding<GetScribePromptUrlInteractor>();
|
||||
|
||||
void loadLinagoraEcosystem() {
|
||||
if (cachedLinagoraEcosystem != null) {
|
||||
_applyScribePromptUrl(cachedLinagoraEcosystem!.scribePromptUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
final interactor = getBinding<GetLinagoraEcosystemInteractor>();
|
||||
|
||||
if (interactor != null) {
|
||||
final baseUrl = dynamicUrlInterceptors.jmapUrl;
|
||||
if (baseUrl != null && baseUrl.isNotEmpty) {
|
||||
consumeState(interactor.execute(baseUrl));
|
||||
} else {
|
||||
logError('SetupScribePromptUrlExtension::loadScribePromptUrl: jmapUrl is null or empty');
|
||||
logError('SetupScribePromptUrlExtension::loadLinagoraEcosystem: jmapUrl is null or empty');
|
||||
}
|
||||
} else {
|
||||
logError('SetupScribePromptUrlExtension::loadScribePromptUrl: GetScribePromptUrlInteractor not found');
|
||||
logError('SetupScribePromptUrlExtension::loadLinagoraEcosystem: GetLinagoraEcosystemInteractor not found');
|
||||
}
|
||||
}
|
||||
|
||||
void handleGetScribePromptUrlSuccess(GetScribePromptUrlSuccess success) {
|
||||
final promptService = getBinding<PromptService>();
|
||||
|
||||
if (promptService != null) {
|
||||
promptService.setPromptUrl(success.promptUrl);
|
||||
} else {
|
||||
logWarning('SetupScribePromptUrlExtension::handleGetScribePromptUrlFailure: PromptService not found');
|
||||
}
|
||||
void handleGetLinagoraEcosystemSuccess(GetLinagoraEcosystemSuccess success) {
|
||||
cachedLinagoraEcosystem = success.linagoraEcosystem;
|
||||
_applyScribePromptUrl(cachedLinagoraEcosystem!.scribePromptUrl);
|
||||
}
|
||||
|
||||
void handleGetScribePromptUrlFailure(GetScribePromptUrlFailure failure) {
|
||||
logError('SetupScribePromptUrlExtension::handleGetScribePromptUrlFailure: GetScribePromptUrl failed - ${failure.exception}');
|
||||
void handleGetLinagoraEcosystemFailure(GetLinagoraEcosystemFailure failure) {
|
||||
logError('SetupScribePromptUrlExtension::handleGetLinagoraEcosystemFailure: GetScribePromptUrl failed - ${failure.exception}');
|
||||
_applyScribePromptUrl(null);
|
||||
}
|
||||
|
||||
void _applyScribePromptUrl(String? promptUrl) {
|
||||
final promptService = getBinding<PromptService>();
|
||||
|
||||
if (promptService != null) {
|
||||
promptService.setPromptUrl(null);
|
||||
promptService.setPromptUrl(promptUrl);
|
||||
} else {
|
||||
logWarning('SetupScribePromptUrlExtension::handleGetScribePromptUrlFailure: PromptService not found');
|
||||
logWarning('SetupScribePromptUrlExtension::_applyScribePromptUrl: PromptService not found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user