refactor(calendar): remove deprecated reminder components

This commit is contained in:
qzl
2026-03-20 18:42:58 +08:00
parent 9ece726de0
commit 6e35fff9a4
20 changed files with 47 additions and 1143 deletions
@@ -1,26 +1,17 @@
import 'dart:math';
import '../data/services/calendar_service.dart';
import '../../../core/notifications/local_notification_service.dart';
import 'models/reminder_action.dart';
import 'models/reminder_payload.dart';
import 'reminder_outbox_store.dart';
class ReminderActionExecutor {
final CalendarService _calendarService;
final LocalNotificationService _notificationService;
final ReminderOutboxStore _outboxStore;
final Random _random;
ReminderActionExecutor({
required CalendarService calendarService,
required LocalNotificationService notificationService,
required ReminderOutboxStore outboxStore,
Random? random,
}) : _calendarService = calendarService,
_notificationService = notificationService,
_outboxStore = outboxStore,
_random = random ?? Random();
_notificationService = notificationService;
Future<void> handleAction({
required ReminderAction action,
@@ -35,7 +26,7 @@ class ReminderActionExecutor {
if (action == ReminderAction.archive) {
for (final id in ids) {
await _notificationService.cancelEventReminder(id);
await _archiveEvent(id, ReminderAction.archive);
await _archiveEvent(id);
}
return;
}
@@ -47,21 +38,6 @@ class ReminderActionExecutor {
}
}
Future<void> replayPendingActions() async {
final pending = await _outboxStore.listPending();
for (final item in pending) {
if (item.targetStatus != 'archived') {
continue;
}
try {
await _calendarService.archiveEvent(item.eventId);
await _outboxStore.markDone(item.opId);
} catch (error) {
await _outboxStore.markRetry(item.opId, error.toString());
}
}
}
Future<void> _snoozeEvent(String eventId) async {
final event = await _calendarService.getEventById(eventId);
if (event == null) {
@@ -71,37 +47,21 @@ class ReminderActionExecutor {
final endAt = event.endAt;
if (endAt != null && !now.isBefore(endAt)) {
await _notificationService.cancelEventReminder(eventId);
await _archiveEvent(eventId, ReminderAction.archive);
await _archiveEvent(eventId);
return;
}
final nextAt = now.add(const Duration(minutes: 10));
if (endAt != null && !nextAt.isBefore(endAt)) {
await _notificationService.cancelEventReminder(eventId);
await _archiveEvent(eventId, ReminderAction.archive);
await _archiveEvent(eventId);
return;
}
await _notificationService.scheduleReminderAt(event, nextAt);
}
Future<void> _archiveEvent(String eventId, ReminderAction action) async {
try {
await _calendarService.archiveEvent(eventId);
return;
} catch (_) {
// fall through to enqueue local outbox for retry
}
final opId =
'${DateTime.now().millisecondsSinceEpoch}-${_random.nextInt(1 << 32)}';
final outboxItem = ReminderOutboxItem(
opId: opId,
eventId: eventId,
action: action,
targetStatus: 'archived',
occurredAt: DateTime.now(),
);
await _outboxStore.enqueue(outboxItem);
Future<void> _archiveEvent(String eventId) async {
await _calendarService.archiveEvent(eventId);
}
}