TF-4265 Additional config for include and exclude keywords
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/config/app_config_parser.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/keyword_config.dart';
|
||||
|
||||
class AttachmentKeywordsConfigurationParser
|
||||
extends AppConfigParser<KeywordConfig> {
|
||||
@override
|
||||
Future<KeywordConfig> parse(String value) async {
|
||||
try {
|
||||
final jsonObject = jsonDecode(value);
|
||||
return KeywordConfig.fromJson(jsonObject);
|
||||
} catch (e) {
|
||||
logWarning('AttachmentKeywordsConfigurationParser::parse(): $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<KeywordConfig> parseData(ByteData data) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/config/app_config_loader.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/manager/attachment_keywords_configuration_parser.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/keyword_config.dart';
|
||||
import 'package:tmail_ui_user/main/utils/app_config.dart';
|
||||
|
||||
class KeywordConfigManager {
|
||||
static final KeywordConfigManager _instance = KeywordConfigManager._();
|
||||
|
||||
factory KeywordConfigManager() => _instance;
|
||||
|
||||
KeywordConfigManager._();
|
||||
|
||||
KeywordConfig? _cachedConfig;
|
||||
AppConfigLoader? _appConfigLoader;
|
||||
|
||||
static const String _configPath =
|
||||
AppConfig.attachmentKeywordsConfigurationPath;
|
||||
|
||||
Future<KeywordConfig> getConfig() async {
|
||||
if (_cachedConfig != null) {
|
||||
return _cachedConfig!;
|
||||
}
|
||||
|
||||
try {
|
||||
_appConfigLoader ??= AppConfigLoader();
|
||||
_cachedConfig = await _appConfigLoader?.load<KeywordConfig>(
|
||||
_configPath,
|
||||
AttachmentKeywordsConfigurationParser(),
|
||||
);
|
||||
} catch (e) {
|
||||
logWarning(
|
||||
"KeywordConfigManager::getConfig:Error loading keyword config: $e");
|
||||
_cachedConfig = const KeywordConfig();
|
||||
}
|
||||
|
||||
return _cachedConfig!;
|
||||
}
|
||||
|
||||
void clearCache() {
|
||||
_cachedConfig = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user