mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 16:04:20 +00:00
refactor: adopt @riverpod codegen for composer cache provider chain
This commit is contained in:
1 parent
7c8267ec7e
commit
7d37a297ef
10 files changed
+59
-43
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
@@ -10,6 +11,8 @@ import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_persistent_cache.dart';
|
||||
|
||||
part 'composer_hive_cache_client.g.dart';
|
||||
|
||||
class ComposerHiveCacheClient extends HiveCacheClient<String> {
|
||||
@override
|
||||
String get tableName => CachingConstants.composerHiveCacheBoxName;
|
||||
@@ -67,3 +70,7 @@ class ComposerHiveCacheClient extends HiveCacheClient<String> {
|
||||
) =>
|
||||
deleteItem(_entryKey(accountId, userName, composerId));
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
ComposerHiveCacheClient composerHiveCacheClient(Ref ref) =>
|
||||
ComposerHiveCacheClient();
|
||||
@@ -1,39 +0,0 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/composer_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/composer_cache_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource_impl/composer_persistent_cache_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/mark_composer_cache_clean_close_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/remove_all_composer_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/resolve_composer_cache_for_restore_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/thrower/cache_exception_thrower.dart';
|
||||
|
||||
final _composerHiveCacheClientProvider =
|
||||
Provider<ComposerHiveCacheClient>((_) => ComposerHiveCacheClient());
|
||||
|
||||
final _cacheExceptionThrowerProvider =
|
||||
Provider<CacheExceptionThrower>((_) => CacheExceptionThrower());
|
||||
|
||||
final _composerCacheDatasourceProvider = Provider<ComposerCacheDatasource>(
|
||||
(ref) => ComposerPersistentCacheDatasourceImpl(
|
||||
ref.read(_composerHiveCacheClientProvider),
|
||||
ref.read(_cacheExceptionThrowerProvider),
|
||||
),
|
||||
);
|
||||
|
||||
final composerCacheRepositoryProvider = Provider<ComposerCacheRepository>(
|
||||
(ref) => ComposerCacheRepositoryImpl(ref.read(_composerCacheDatasourceProvider)),
|
||||
);
|
||||
|
||||
final removeAllComposerCacheProvider = Provider<RemoveAllComposerCacheInteractor>(
|
||||
(ref) => RemoveAllComposerCacheInteractor(ref.read(composerCacheRepositoryProvider)),
|
||||
);
|
||||
|
||||
final markComposerLocalCacheCleanCloseProvider = Provider<MarkComposerCacheCleanCloseInteractor>(
|
||||
(ref) => MarkComposerCacheCleanCloseInteractor(ref.read(composerCacheRepositoryProvider)),
|
||||
);
|
||||
|
||||
final resolveComposerCacheForRestoreProvider = Provider<ResolveComposerCacheForRestoreInteractor>(
|
||||
(ref) => ResolveComposerCacheForRestoreInteractor(ref.read(composerCacheRepositoryProvider)),
|
||||
);
|
||||
+11
@@ -1,10 +1,14 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/composer_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/composer_cache_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/thrower/cache_exception_thrower.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/thrower/exception_thrower.dart';
|
||||
|
||||
part 'composer_persistent_cache_datasource_impl.g.dart';
|
||||
|
||||
class ComposerPersistentCacheDatasourceImpl extends ComposerCacheDatasource {
|
||||
final ComposerHiveCacheClient _cacheClient;
|
||||
final ExceptionThrower _exceptionThrower;
|
||||
@@ -50,3 +54,10 @@ class ComposerPersistentCacheDatasourceImpl extends ComposerCacheDatasource {
|
||||
).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
ComposerCacheDatasource composerCacheDatasource(Ref ref) =>
|
||||
ComposerPersistentCacheDatasourceImpl(
|
||||
ref.watch(composerHiveCacheClientProvider),
|
||||
ref.watch(cacheExceptionThrowerProvider),
|
||||
);
|
||||
@@ -1,9 +1,13 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/composer_cache_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource_impl/composer_persistent_cache_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart';
|
||||
|
||||
part 'composer_cache_repository_impl.g.dart';
|
||||
|
||||
class ComposerCacheRepositoryImpl extends ComposerCacheRepository {
|
||||
final ComposerCacheDatasource _composerCacheDatasource;
|
||||
|
||||
@@ -46,5 +50,8 @@ class ComposerCacheRepositoryImpl extends ComposerCacheRepository {
|
||||
userName,
|
||||
composerId,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
ComposerCacheRepository composerCacheRepository(Ref ref) =>
|
||||
ComposerCacheRepositoryImpl(ref.watch(composerCacheDatasourceProvider));
|
||||
+8
@@ -3,10 +3,14 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_persistent_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/mark_composer_cache_clean_close_state.dart';
|
||||
|
||||
part 'mark_composer_cache_clean_close_interactor.g.dart';
|
||||
|
||||
/// Two-step write (mark then remove) ensures the entry is not treated as a
|
||||
/// recoverable snapshot if removal is interrupted
|
||||
/// (see [ComposerPersistentCache.isRestorable]).
|
||||
@@ -46,3 +50,7 @@ class MarkComposerCacheCleanCloseInteractor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
MarkComposerCacheCleanCloseInteractor markComposerLocalCacheCleanClose(Ref ref) =>
|
||||
MarkComposerCacheCleanCloseInteractor(ref.watch(composerCacheRepositoryProvider));
|
||||
+8
@@ -3,9 +3,13 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/remove_all_composer_cache_state.dart';
|
||||
|
||||
part 'remove_all_composer_cache_interactor.g.dart';
|
||||
|
||||
class RemoveAllComposerCacheInteractor {
|
||||
final ComposerCacheRepository _composerCacheRepository;
|
||||
|
||||
@@ -20,3 +24,7 @@ class RemoveAllComposerCacheInteractor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
RemoveAllComposerCacheInteractor removeAllComposerCache(Ref ref) =>
|
||||
RemoveAllComposerCacheInteractor(ref.watch(composerCacheRepositoryProvider));
|
||||
+8
@@ -3,10 +3,14 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_persistent_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/repository/composer_cache_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/resolve_composer_cache_for_restore_state.dart';
|
||||
|
||||
part 'resolve_composer_cache_for_restore_interactor.g.dart';
|
||||
|
||||
/// Fetches, validates, and cleans up the composer cache in one pass.
|
||||
///
|
||||
/// Returns [ResolveComposerCacheForRestoreSuccess] with a non-null [cache]
|
||||
@@ -40,3 +44,7 @@ class ResolveComposerCacheForRestoreInteractor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
ResolveComposerCacheForRestoreInteractor resolveComposerCacheForRestore(Ref ref) =>
|
||||
ResolveComposerCacheForRestoreInteractor(ref.watch(composerCacheRepositoryProvider));
|
||||
+1
-1
@@ -200,7 +200,7 @@ abstract class MailboxDashBoardBindings extends BaseBindings {
|
||||
|
||||
@override
|
||||
void bindingsController() {
|
||||
// Must be registered first so [localSettingsNotifierProvider] is populated
|
||||
// Must be registered first so [localSettingsProvider] is populated
|
||||
// before any controller reads local settings.
|
||||
Get.put(LocalSettingsService(Get.find<GetLocalSettingsInteractor>()));
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/providers/composer_cache_providers.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/resolve_composer_cache_for_restore_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_persistent_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/resolve_composer_cache_for_restore_state.dart';
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'package:core/domain/exceptions/app_base_exception.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/thrower/exception_thrower.dart';
|
||||
|
||||
part 'cache_exception_thrower.g.dart';
|
||||
|
||||
class CacheExceptionThrower extends ExceptionThrower {
|
||||
|
||||
@override
|
||||
@@ -20,4 +23,7 @@ class CacheExceptionThrower extends ExceptionThrower {
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
CacheExceptionThrower cacheExceptionThrower(Ref ref) => CacheExceptionThrower();
|
||||
Reference in new issue
Block a user