Skip to content

armgit / ente

Public Imported from GitHub
0

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

birthday notifications setting

laurenspriem81bfc83e9d19
diff --git a/mobile/lib/services/memories_cache_service.dart b/mobile/lib/services/memories_cache_service.dart
index 0492001a76..a4b3a3eb15 100644
--- a/mobile/lib/services/memories_cache_service.dart
+++ b/mobile/lib/services/memories_cache_service.dart
@@ -107,6 +107,17 @@ class MemoriesCacheService {
}
}
+ Future<void> toggleBirthdayNotifications() async {
+ final oldValue = localSettings.birthdayNotificationsEnabled;
+ await localSettings.setBirthdayNotificationsEnabled(!oldValue);
+ _logger.info("Turning birhtdayNotifications ${oldValue ? "off" : "on"}");
+ if (oldValue) {
+ await _clearAllScheduledBirthdayNotifications();
+ } else {
+ queueUpdateCache();
+ }
+ }
+
bool get enableSmartMemories =>
flagService.hasGrantedMLConsent &&
localSettings.isMLLocalIndexingEnabled &&
@@ -262,6 +273,12 @@ class MemoriesCacheService {
.clearAllScheduledNotifications(containingPayload: "onThisDay");
}
+ Future<void> _clearAllScheduledBirthdayNotifications() async {
+ _logger.info('Clearing all scheduled birthday notifications');
+ await NotificationService.instance
+ .clearAllScheduledNotifications(containingPayload: "birthday");
+ }
+
Future<void> _scheduleMemoryNotifications(
List<SmartMemory> allMemories,
) async {
@@ -326,8 +343,11 @@ class MemoriesCacheService {
Future<void> _scheduleBirthdayNotifications(
List<SmartMemory> allMemories,
) async {
- await NotificationService.instance
- .clearAllScheduledNotifications(containingPayload: "birthday");
+ if (!localSettings.birthdayNotificationsEnabled) {
+ _logger.info("birthday notifications are disabled, skipping scheduling");
+ return;
+ }
+ await _clearAllScheduledBirthdayNotifications();
final scheduledPersons = <String>{};
final toSchedule = <PeopleMemory>[];
final peopleToBirthdayMemories = <String, List<PeopleMemory>>{};
diff --git a/mobile/lib/ui/settings/notification_settings_screen.dart b/mobile/lib/ui/settings/notification_settings_screen.dart
index de4df89574..6c12c94c8f 100644
--- a/mobile/lib/ui/settings/notification_settings_screen.dart
+++ b/mobile/lib/ui/settings/notification_settings_screen.dart
@@ -103,9 +103,35 @@ class NotificationSettingsScreen extends StatelessWidget {
isGestureDetectorDisabled: true,
),
MenuSectionDescriptionWidget(
- content:
- S.of(context).onThisDayNotificationExplanation,
+ content: S
+ .of(context)
+ .onThisDayNotificationExplanation,
+ ),
+ sectionOptionSpacing,
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: "Birhtday notifications",
+ ),
+ menuItemColor: colorScheme.fillFaint,
+ trailingWidget: ToggleSwitchWidget(
+ value: () =>
+ NotificationService.instance
+ .hasGrantedPermissions() &&
+ localSettings.birthdayNotificationsEnabled,
+ onChanged: () async {
+ await NotificationService.instance
+ .requestPermissions();
+ await memoriesCacheService
+ .toggleBirthdayNotifications();
+ },
+ ),
+ singleBorderRadius: 8,
+ alignCaptionedTextToLeft: true,
+ isGestureDetectorDisabled: true,
),
+ MenuSectionDescriptionWidget(
+ content:
+ "Receive reminders when it's someone's birthday. Tapping on the notification will take you to photos of the birthday person."),
],
),
],
diff --git a/mobile/lib/utils/local_settings.dart b/mobile/lib/utils/local_settings.dart
index ab63e2ab81..4133bf0087 100644
--- a/mobile/lib/utils/local_settings.dart
+++ b/mobile/lib/utils/local_settings.dart
@@ -28,6 +28,8 @@ class LocalSettings {
static const kCuratedMemoriesEnabled = "ls.curated_memories_enabled";
static const kOnThisDayNotificationsEnabled =
"ls.on_this_day_notifications_enabled";
+ static const kBirthdayNotificationsEnabled =
+ "ls.birthday_notifications_enabled";
static const kRateUsPromptThreshold = 2;
static const shouldLoopVideoKey = "video.should_loop";
static const onGuestViewKey = "on_guest_view";
@@ -129,6 +131,14 @@ class LocalSettings {
return value;
}
+ bool get birthdayNotificationsEnabled =>
+ _prefs.getBool(kBirthdayNotificationsEnabled) ?? true;
+
+ Future<bool> setBirthdayNotificationsEnabled(bool value) async {
+ await _prefs.setBool(kBirthdayNotificationsEnabled, value);
+ return value;
+ }
+
bool get userEnabledMultiplePart =>
_prefs.getBool(kEnableMultiplePart) ?? true;