mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-20 20:12:22 +01:00
SickDayPool gains keep: mark/clear write state+actor+keep on one tick, setKept re-stamps only keep+actor, read rules 1-5 in sick_day_keep.dart. The native SickDays cache now holds only days on which the alarm stands down, so a sick day that keeps the alarm rings like a normal day. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PAhbNszs5JKdtnD4uBi3xp
50 lines
2.1 KiB
Dart
50 lines
2.1 KiB
Dart
import 'package:crdt_sync/crdt_sync.dart';
|
|
import 'package:wake_alarm_sync/services/alarm_scheduler.dart';
|
|
import 'package:wake_alarm_sync/services/day_pool_sync.dart';
|
|
import 'package:wake_alarm_sync/services/firebase_backend.dart';
|
|
import 'package:wake_alarm_sync/services/sick_day_keep.dart';
|
|
import 'package:wake_alarm_sync/services/sick_day_pool.dart';
|
|
|
|
/// Moves the sick-day pool between this phone and every other device, over
|
|
/// `sickdays-sync/devices` -- the node `sickdays sync` on the PC uses.
|
|
///
|
|
/// Every sync ends by handing the merged pool to the native ring path
|
|
/// ([AlarmScheduler.setSickDays]): that cache, not the Dart store, is what
|
|
/// `AlarmReceiver` reads when it decides whether to ring. Only days on
|
|
/// which the *alarm* stands down go there: a sick day that keeps the alarm
|
|
/// rings, judges the stick and shows its stakes exactly like a normal day.
|
|
class SickDaySync {
|
|
/// Creates a syncer; both seams are injectable for tests.
|
|
SickDaySync({
|
|
Future<RemoteStore?> Function()? openClient,
|
|
AlarmScheduler? scheduler,
|
|
}) : _openClient = openClient ?? openFirebase,
|
|
_scheduler = scheduler ?? AlarmScheduler();
|
|
|
|
final Future<RemoteStore?> Function() _openClient;
|
|
final AlarmScheduler _scheduler;
|
|
|
|
/// Pulls, merges and pushes [pool], then refreshes the native cache.
|
|
/// Never throws; see [syncDayPoolLog].
|
|
Future<String> sync(SickDayPool pool) => syncDayPoolLog(
|
|
openClient: _openClient,
|
|
deviceId: pool.deviceId,
|
|
pathPrefix: SickDayPool.pathPrefix,
|
|
filename: SickDayPool.filename,
|
|
commitMessage: 'sickdays: update pool',
|
|
snapshot: pool.snapshot,
|
|
replaceAll: pool.replaceAll,
|
|
publish: () => publishToNative(pool),
|
|
logName: 'SickDaySync',
|
|
);
|
|
|
|
/// Writes the dates on which the alarm stands down (sick, alarm not
|
|
/// kept; past ones included) where `AlarmReceiver` can read them. The one
|
|
/// place the keep set is applied for the native side: every native reader
|
|
/// (ring, stick, stakes) means "the alarm stands down".
|
|
Future<void> publishToNative(SickDayPool pool) => publishQuietly(
|
|
() => _scheduler.setSickDays(pool.standDownIsoDates(SickLocker.alarm)),
|
|
logName: 'SickDaySync',
|
|
);
|
|
}
|