Skip to content

armgit / ente

Public Imported from GitHub
0

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

toggle settings for social notifications

laurenspriem6bd3bb326d8d
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arb
index b74e780d90..2b4ad74395 100644
--- a/mobile/apps/photos/lib/l10n/intl_en.arb
+++ b/mobile/apps/photos/lib/l10n/intl_en.arb
@@ -640,6 +640,12 @@
"notifications": "Notifications",
"sharedPhotoNotifications": "New shared photos",
"sharedPhotoNotificationsExplanation": "Receive notifications when someone adds a photo to a shared album that you're a part of",
+ "commentNotifications": "Comments",
+ "commentNotificationsExplanation": "Receive notifications when someone comments on your shared photos",
+ "likeNotifications": "Likes",
+ "likeNotificationsExplanation": "Receive notifications when someone likes your photos",
+ "replyNotifications": "Replies",
+ "replyNotificationsExplanation": "Receive notifications when someone replies to your comments",
"advanced": "Advanced",
"general": "General",
"security": "Security",
diff --git a/mobile/apps/photos/lib/services/notification_service.dart b/mobile/apps/photos/lib/services/notification_service.dart
index 6cbbcf76e2..a20f1c3e74 100644
--- a/mobile/apps/photos/lib/services/notification_service.dart
+++ b/mobile/apps/photos/lib/services/notification_service.dart
@@ -16,6 +16,12 @@ class NotificationService {
"notification_permission_granted";
static const String keyShouldShowNotificationsForSharedPhotos =
"notifications_enabled_shared_photos";
+ static const String keyShouldShowCommentNotifications =
+ "notifications_enabled_social_comments";
+ static const String keyShouldShowLikeNotifications =
+ "notifications_enabled_social_likes";
+ static const String keyShouldShowReplyNotifications =
+ "notifications_enabled_social_replies";
NotificationService._privateConstructor();
@@ -157,6 +163,42 @@ class NotificationService {
);
}
+ bool shouldShowCommentNotifications() {
+ final result = _preferences.getBool(keyShouldShowCommentNotifications);
+ return result ?? true;
+ }
+
+ Future<void> setShouldShowCommentNotifications(bool value) {
+ return _preferences.setBool(
+ keyShouldShowCommentNotifications,
+ value,
+ );
+ }
+
+ bool shouldShowLikeNotifications() {
+ final result = _preferences.getBool(keyShouldShowLikeNotifications);
+ return result ?? true;
+ }
+
+ Future<void> setShouldShowLikeNotifications(bool value) {
+ return _preferences.setBool(
+ keyShouldShowLikeNotifications,
+ value,
+ );
+ }
+
+ bool shouldShowReplyNotifications() {
+ final result = _preferences.getBool(keyShouldShowReplyNotifications);
+ return result ?? true;
+ }
+
+ Future<void> setShouldShowReplyNotifications(bool value) {
+ return _preferences.setBool(
+ keyShouldShowReplyNotifications,
+ value,
+ );
+ }
+
Future<void> showNotification(
String title,
String message, {
diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
index dab491933f..e953f3970a 100644
--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
@@ -1128,8 +1128,17 @@ class RemoteSyncService {
final hiddenCollectionIds = _collectionsService.getHiddenCollectionIds();
final latestByKey = <String, _SocialActivityCandidate>{};
+ final bool enableCommentNotifications =
+ NotificationService.instance.shouldShowCommentNotifications();
+ final bool enableLikeNotifications =
+ NotificationService.instance.shouldShowLikeNotifications();
+ final bool enableReplyNotifications =
+ NotificationService.instance.shouldShowReplyNotifications();
void considerCandidate(_SocialActivityCandidate candidate) {
+ if (!_isSocialNotificationEnabledForType(candidate.type)) {
+ return;
+ }
if (candidate.createdAt <= cutoffTime) {
return;
}
@@ -1150,10 +1159,12 @@ class RemoteSyncService {
final db = SocialDB.instance;
- final List<Comment> fileComments = await db.getCommentsOnFilesSince(
- excludeUserID: userID,
- sinceTime: cutoffTime,
- );
+ final List<Comment> fileComments = enableCommentNotifications
+ ? await db.getCommentsOnFilesSince(
+ excludeUserID: userID,
+ sinceTime: cutoffTime,
+ )
+ : <Comment>[];
for (final comment in fileComments) {
considerCandidate(
_SocialActivityCandidate(
@@ -1168,14 +1179,18 @@ class RemoteSyncService {
);
}
- final List<Comment> replies = await db.getRepliesToUserCommentsSince(
- targetUserID: userID,
- sinceTime: cutoffTime,
- );
- final List<Reaction> photoLikes = await db.getReactionsOnFilesSince(
- excludeUserID: userID,
- sinceTime: cutoffTime,
- );
+ final List<Comment> replies = enableReplyNotifications
+ ? await db.getRepliesToUserCommentsSince(
+ targetUserID: userID,
+ sinceTime: cutoffTime,
+ )
+ : <Comment>[];
+ final List<Reaction> photoLikes = enableLikeNotifications
+ ? await db.getReactionsOnFilesSince(
+ excludeUserID: userID,
+ sinceTime: cutoffTime,
+ )
+ : <Reaction>[];
final repliesNeedingOwnerCheck = <Comment>[];
final fileIDsNeedingOwnership = <int>{};
@@ -1293,9 +1308,24 @@ class RemoteSyncService {
}
bool _shouldShowSocialNotifications() {
- return NotificationService.instance
- .shouldShowNotificationsForSharedPhotos() &&
- isFirstRemoteSyncDone();
+ return isFirstRemoteSyncDone() &&
+ (NotificationService.instance.shouldShowCommentNotifications() ||
+ NotificationService.instance.shouldShowLikeNotifications() ||
+ NotificationService.instance.shouldShowReplyNotifications());
+ }
+
+ bool _isSocialNotificationEnabledForType(FeedItemType type) {
+ switch (type) {
+ case FeedItemType.comment:
+ return NotificationService.instance.shouldShowCommentNotifications();
+ case FeedItemType.reply:
+ return NotificationService.instance.shouldShowReplyNotifications();
+ case FeedItemType.photoLike:
+ return NotificationService.instance.shouldShowLikeNotifications();
+ case FeedItemType.commentLike:
+ case FeedItemType.replyLike:
+ return false; // Currently not notifying for comment/reply likes
+ }
}
_SocialNotificationGroup _notificationGroupForType(FeedItemType type) {
diff --git a/mobile/apps/photos/lib/ui/settings/notification_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/notification_settings_screen.dart
index 50be5f24d7..75af0df46f 100644
--- a/mobile/apps/photos/lib/ui/settings/notification_settings_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/notification_settings_screen.dart
@@ -80,6 +80,106 @@ class NotificationSettingsScreen extends StatelessWidget {
.copyWith(color: colorScheme.textMuted),
),
),
+ MenuItemWidgetNew(
+ title:
+ AppLocalizations.of(context).commentNotifications,
+ trailingWidget: ToggleSwitchWidget(
+ value: () =>
+ NotificationService.instance
+ .hasGrantedPermissions() &&
+ NotificationService.instance
+ .shouldShowCommentNotifications(),
+ onChanged: () async {
+ await NotificationService.instance
+ .requestPermissions();
+ await NotificationService.instance
+ .setShouldShowCommentNotifications(
+ !NotificationService.instance
+ .shouldShowCommentNotifications(),
+ );
+ },
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(
+ left: 16,
+ right: 16,
+ top: 8,
+ bottom: 16,
+ ),
+ child: Text(
+ AppLocalizations.of(context)
+ .commentNotificationsExplanation,
+ style: textTheme.mini
+ .copyWith(color: colorScheme.textMuted),
+ ),
+ ),
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).likeNotifications,
+ trailingWidget: ToggleSwitchWidget(
+ value: () =>
+ NotificationService.instance
+ .hasGrantedPermissions() &&
+ NotificationService.instance
+ .shouldShowLikeNotifications(),
+ onChanged: () async {
+ await NotificationService.instance
+ .requestPermissions();
+ await NotificationService.instance
+ .setShouldShowLikeNotifications(
+ !NotificationService.instance
+ .shouldShowLikeNotifications(),
+ );
+ },
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(
+ left: 16,
+ right: 16,
+ top: 8,
+ bottom: 16,
+ ),
+ child: Text(
+ AppLocalizations.of(context)
+ .likeNotificationsExplanation,
+ style: textTheme.mini
+ .copyWith(color: colorScheme.textMuted),
+ ),
+ ),
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).replyNotifications,
+ trailingWidget: ToggleSwitchWidget(
+ value: () =>
+ NotificationService.instance
+ .hasGrantedPermissions() &&
+ NotificationService.instance
+ .shouldShowReplyNotifications(),
+ onChanged: () async {
+ await NotificationService.instance
+ .requestPermissions();
+ await NotificationService.instance
+ .setShouldShowReplyNotifications(
+ !NotificationService.instance
+ .shouldShowReplyNotifications(),
+ );
+ },
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(
+ left: 16,
+ right: 16,
+ top: 8,
+ bottom: 16,
+ ),
+ child: Text(
+ AppLocalizations.of(context)
+ .replyNotificationsExplanation,
+ style: textTheme.mini
+ .copyWith(color: colorScheme.textMuted),
+ ),
+ ),
MenuItemWidgetNew(
title: AppLocalizations.of(context).onThisDayMemories,
trailingWidget: ToggleSwitchWidget(
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
index fd1e40e812..56ccbd6d04 100644
--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
@@ -448,6 +448,51 @@ class SettingsSearchRegistry {
isSubPage: true,
keywords: ["shared", "notifications", "shares"],
),
+ SettingsSearchItem(
+ title: l10n.commentNotifications,
+ subtitle: l10n.notifications,
+ sectionPath: l10n.notifications,
+ icon: HugeIcons.strokeRoundedNotification01,
+ routeBuilder: (_) => const NotificationSettingsScreen(),
+ isSubPage: true,
+ keywords: [
+ "comment",
+ "comments",
+ "social",
+ "notifications",
+ "notification",
+ ],
+ ),
+ SettingsSearchItem(
+ title: l10n.likeNotifications,
+ subtitle: l10n.notifications,
+ sectionPath: l10n.notifications,
+ icon: HugeIcons.strokeRoundedNotification01,
+ routeBuilder: (_) => const NotificationSettingsScreen(),
+ isSubPage: true,
+ keywords: [
+ "like",
+ "likes",
+ "social",
+ "notifications",
+ "notification",
+ ],
+ ),
+ SettingsSearchItem(
+ title: l10n.replyNotifications,
+ subtitle: l10n.notifications,
+ sectionPath: l10n.notifications,
+ icon: HugeIcons.strokeRoundedNotification01,
+ routeBuilder: (_) => const NotificationSettingsScreen(),
+ isSubPage: true,
+ keywords: [
+ "reply",
+ "replies",
+ "social",
+ "notifications",
+ "notification",
+ ],
+ ),
SettingsSearchItem(
title: l10n.onThisDayMemories,
subtitle: l10n.notifications,