This commit refactors the data repositories to remove user-specific filtering. It simplifies the data access logic by retrieving all data from the Hive boxes and removing the need to filter by `userId` in the repository methods. This change makes the app function in single-user mode and removes the need to manage multiple user contexts within the data layer. Specifically: - Removes `userId` parameter from repository methods. - Updates the setting repository to use fixed keys. - Removes user ID filtering from queries. - Removes user ID parameters from Cubits and Blocs - Updates initial data creation
66 lines
2.5 KiB
Dart
66 lines
2.5 KiB
Dart
|
|
import 'package:hive_ce/hive.dart';
|
|
|
|
import '/utils/id_generator.dart';
|
|
part 'sms_handler_settings.g.dart';
|
|
|
|
/// Перечисление для определения типа обработки СМС.
|
|
@HiveType(typeId: 10)
|
|
enum SmsProcessingType {
|
|
/// Обработка с использованием регулярного выражения.
|
|
@HiveField(0)
|
|
regexp,
|
|
|
|
/// Обработка с использованием кастомной функции.
|
|
@HiveField(1)
|
|
customFunction,
|
|
}
|
|
|
|
/// Модель для хранения правила обработки СМС от конкретного отправителя.
|
|
@HiveType(typeId: 11)
|
|
class SmsProcessingRule extends HiveObject {
|
|
/// Тип обработки (regexp или кастомная функция).
|
|
@HiveField(0)
|
|
final SmsProcessingType type;
|
|
|
|
/// Шаблон регулярного выражения (используется, если type == SmsProcessingType.regexp).
|
|
@HiveField(1)
|
|
final String? pattern;
|
|
|
|
/// Идентификатор кастомной функции (используется, если type == SmsProcessingType.customFunction).
|
|
/// В коде этот ID будет сопоставляться с реальной функцией.
|
|
@HiveField(2)
|
|
final String? customFunctionId;
|
|
|
|
@HiveField(3)
|
|
final String id;
|
|
|
|
SmsProcessingRule({
|
|
String? id,
|
|
required this.type,
|
|
this.pattern,
|
|
this.customFunctionId,
|
|
}) : assert(
|
|
(type == SmsProcessingType.regexp && pattern != null) ||
|
|
(type == SmsProcessingType.customFunction && customFunctionId != null),
|
|
'Pattern must be provided for regexp type, and customFunctionId for customFunction type.',
|
|
), id = id ?? IdGenerator.generateId();
|
|
}
|
|
|
|
/// Модель для хранения всех настроек обработки СМС для одного пользователя.
|
|
@HiveType(typeId: 12)
|
|
class SmsHandlerSettings extends HiveObject {
|
|
|
|
@HiveField(0)
|
|
final String id;
|
|
/// Карта правил обработки, где ключ - это идентификатор отправителя (например, 'SBERBANK' или номер телефона),
|
|
/// а значение - правило обработки для этого отправителя.
|
|
@HiveField(1)
|
|
final Map<String, SmsProcessingRule> rulesBySender;
|
|
|
|
SmsHandlerSettings({
|
|
String? id,
|
|
required this.rulesBySender,
|
|
}) : id = id ?? IdGenerator.generateId();
|
|
}
|