Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Keep streak on current day without photo

laurenspriemad03e8128c46
diff --git a/mobile/apps/photos/lib/services/rituals/rituals_service.dart b/mobile/apps/photos/lib/services/rituals/rituals_service.dart
index 6bfbea8fc9..02c3aa1974 100644
--- a/mobile/apps/photos/lib/services/rituals/rituals_service.dart
+++ b/mobile/apps/photos/lib/services/rituals/rituals_service.dart
@@ -317,7 +317,7 @@ class RitualsService {
ritual.daysOfWeek,
todayMidnight: todayMidnight,
);
- final ritualCurrent = _currentScheduledStreakFromDayKeys(
+ final ritualCurrent = currentScheduledStreakFromDayKeys(
dates,
ritual.daysOfWeek,
todayMidnight: todayMidnight,
@@ -533,7 +533,8 @@ class RitualsService {
}
}
- int _currentScheduledStreakFromDayKeys(
+ @visibleForTesting
+ int currentScheduledStreakFromDayKeys(
Set<int> dayKeys,
List<bool> daysOfWeek, {
required DateTime todayMidnight,
@@ -550,9 +551,12 @@ class RitualsService {
final key = DateTime(day.year, day.month, day.day).millisecondsSinceEpoch;
if (dayKeys.contains(key)) {
current += 1;
- } else {
- break;
+ continue;
+ }
+ if (day == todayMidnight) {
+ continue;
}
+ break;
}
return current;
}
diff --git a/mobile/apps/photos/test/services/rituals_service_test.dart b/mobile/apps/photos/test/services/rituals_service_test.dart
new file mode 100644
index 0000000000..b5cdbfd3eb
--- /dev/null
+++ b/mobile/apps/photos/test/services/rituals_service_test.dart
@@ -0,0 +1,111 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:photos/services/rituals/rituals_service.dart';
+
+void main() {
+ group('RitualsService.currentScheduledStreakFromDayKeys', () {
+ test('keeps streak when today is enabled but incomplete', () {
+ final service = RitualsService.instance;
+ final todayMidnight = DateTime(2025, 6, 15);
+ final daysOfWeek = List<bool>.filled(7, true);
+ final dayKeys = <int>{};
+
+ for (var offset = 1; offset <= 9; offset++) {
+ dayKeys.add(
+ DateTime(
+ todayMidnight.year,
+ todayMidnight.month,
+ todayMidnight.day - offset,
+ ).millisecondsSinceEpoch,
+ );
+ }
+
+ final streak = service.currentScheduledStreakFromDayKeys(
+ dayKeys,
+ daysOfWeek,
+ todayMidnight: todayMidnight,
+ );
+
+ expect(streak, 9);
+ });
+
+ test('increments streak after completing today', () {
+ final service = RitualsService.instance;
+ final todayMidnight = DateTime(2025, 6, 15);
+ final daysOfWeek = List<bool>.filled(7, true);
+ final dayKeys = <int>{todayMidnight.millisecondsSinceEpoch};
+
+ for (var offset = 1; offset <= 9; offset++) {
+ dayKeys.add(
+ DateTime(
+ todayMidnight.year,
+ todayMidnight.month,
+ todayMidnight.day - offset,
+ ).millisecondsSinceEpoch,
+ );
+ }
+
+ final streak = service.currentScheduledStreakFromDayKeys(
+ dayKeys,
+ daysOfWeek,
+ todayMidnight: todayMidnight,
+ );
+
+ expect(streak, 10);
+ });
+
+ test('resets streak when a previous enabled day was missed', () {
+ final service = RitualsService.instance;
+ final todayMidnight = DateTime(2025, 6, 15);
+ final daysOfWeek = List<bool>.filled(7, true);
+ final dayKeys = <int>{};
+
+ for (var offset = 2; offset <= 10; offset++) {
+ dayKeys.add(
+ DateTime(
+ todayMidnight.year,
+ todayMidnight.month,
+ todayMidnight.day - offset,
+ ).millisecondsSinceEpoch,
+ );
+ }
+
+ final streak = service.currentScheduledStreakFromDayKeys(
+ dayKeys,
+ daysOfWeek,
+ todayMidnight: todayMidnight,
+ );
+
+ expect(streak, 0);
+ });
+
+ test('skips disabled days while keeping streak', () {
+ final service = RitualsService.instance;
+ final todayMidnight = DateTime(2025, 6, 16); // Monday
+ final daysOfWeek = <bool>[
+ false, // Sunday
+ true, // Monday
+ true, // Tuesday
+ true, // Wednesday
+ true, // Thursday
+ true, // Friday
+ false, // Saturday
+ ];
+
+ final dayKeys = <int>{
+ DateTime(2025, 6, 13).millisecondsSinceEpoch, // Friday
+ DateTime(2025, 6, 12).millisecondsSinceEpoch, // Thursday
+ DateTime(2025, 6, 11).millisecondsSinceEpoch, // Wednesday
+ DateTime(2025, 6, 10).millisecondsSinceEpoch, // Tuesday
+ DateTime(2025, 6, 9).millisecondsSinceEpoch, // Monday
+ };
+
+ final streak = service.currentScheduledStreakFromDayKeys(
+ dayKeys,
+ daysOfWeek,
+ todayMidnight: todayMidnight,
+ );
+
+ expect(streak, 5);
+ });
+ });
+}