π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] add memories ready notif
Priyanshu Dangared2b0859d6fcc
diff --git a/mobile/apps/photos/lib/services/memories_cache_service.dart b/mobile/apps/photos/lib/services/memories_cache_service.dartindex 21aa0e9de1..9c2ac0610b 100644--- a/mobile/apps/photos/lib/services/memories_cache_service.dart+++ b/mobile/apps/photos/lib/services/memories_cache_service.dart@@ -25,6 +25,7 @@ import "package:photos/models/memories/people_memory.dart";import "package:photos/models/memories/smart_memory.dart";import "package:photos/models/memories/smart_memory_constants.dart";import "package:photos/service_locator.dart";+import "package:photos/services/app_lifecycle_service.dart";import "package:photos/services/app_navigation_service.dart";import "package:photos/services/language_service.dart";import "package:photos/services/machine_learning/face_ml/person/person_service.dart";@@ -41,6 +42,7 @@ import "package:photos/ui/home/memories/memory_music_session.dart";import "package:photos/ui/viewer/file/detail_page.dart";import "package:photos/ui/viewer/people/people_page.dart";import "package:photos/utils/cache_util.dart";+import "package:photos/utils/ml_util.dart";import "package:shared_preferences/shared_preferences.dart";import "package:synchronized/synchronized.dart";@@ -824,6 +826,63 @@ class MemoriesCacheService {}}+ Future<bool> _shouldForceInitialMemoriesRefresh() async {+ if (!flagService.internalUser ||+ localSettings.hasForcedInitialMemoriesRefresh() ||+ DateTime.now().difference(localSettings.getInstallDateTime()).inDays >=+ 21) {+ return false;+ }+ try {+ final indexStatus = await getIndexStatus();+ final totalItems = indexStatus.indexedItems + indexStatus.pendingItems;+ final indexPercent = totalItems > 0+ ? 100 * indexStatus.indexedItems / totalItems+ : 0.0;+ return indexPercent > 90;+ } catch (e, s) {+ _logger.warning(+ "Failed to check ML status for initial memories refresh",+ e,+ s,+ );+ return false;+ }+ }++ Future<void> _scheduleMemoriesNotification(List<SmartMemory> memories) async {+ if (!flagService.internalUser ||+ !memories.any(+ (m) =>+ (m.type == .people || m.type == .clip) &&+ m.memories.isNotEmpty &&+ m.shouldShowNow(),+ )) {+ return;+ }+ if (localSettings.initialMemoriesNotificationScheduledAt() != null) return;+ if (DateTime.now().difference(localSettings.getInstallDateTime()).inDays >=+ 21) {+ await localSettings.markInitialMemoriesNotificationScheduled();+ return;+ }+ final notifications = NotificationService.instance;+ if (!await notifications.hasGrantedPermissions()) return;+ final strings = await LanguageService.locals;+ if (AppLifecycleService.instance.isForeground) {+ await localSettings.markInitialMemoriesNotificationScheduled();+ return;+ }+ await notifications.showNotification(+ strings.memoriesReadyNotificationTitle,+ strings.memoriesReadyNotificationBody,+ id: 314159265,+ channelID: "memoriesReady",+ channelName: strings.memories,+ );+ await localSettings.markInitialMemoriesNotificationScheduled();+ }+Future<void> updateCache({bool forced = false}) async {if (!showAnyMemories) {return;@@ -835,7 +894,11 @@ class MemoriesCacheService {_checkIfTimeToUpdateCache();return _memoriesUpdateLock.synchronized(() async {- if ((!_shouldUpdate && !forced)) {+ final forceInitialMemoriesRefresh =+ await _shouldForceInitialMemoriesRefresh();+ final shouldUpdate =+ _shouldUpdate || forced || forceInitialMemoriesRefresh;+ if (!shouldUpdate) {_logger.info("No update needed (shouldUpdate: $_shouldUpdate, forced: $forced)",);@@ -938,6 +1001,10 @@ class MemoriesCacheService {);w?.log("cacheWritten");await _cacheUpdated();+ if (forceInitialMemoriesRefresh) {+ await localSettings.markForcedInitialMemoriesRefresh();+ }+ await _scheduleMemoriesNotification(_cachedMemories!);w?.logAndReset('_cacheUpdated method done');} catch (e, s) {_logger.severe("Error updating memories cache", e, s);diff --git a/mobile/apps/photos/lib/settings/local_settings.dart b/mobile/apps/photos/lib/settings/local_settings.dartindex aac7f3e09b..38a7c8e981 100644--- a/mobile/apps/photos/lib/settings/local_settings.dart+++ b/mobile/apps/photos/lib/settings/local_settings.dart@@ -151,6 +151,10 @@ class LocalSettings {);static const _kCraftingMemoriesBannerDismissed ='is_crafting_memories_banner_dismissed';+ static const _kInitialMemoriesNotificationScheduledAt =+ "memories.initial_notification_scheduled_at";+ static const _kForcedInitialMemoriesRefresh =+ "memories.forced_initial_memories_refresh";final SharedPreferences _prefs;@@ -897,6 +901,25 @@ class LocalSettings {await _prefs.setBool(_kCraftingMemoriesBannerDismissed, true);}+ int? initialMemoriesNotificationScheduledAt() {+ return _prefs.getInt(_kInitialMemoriesNotificationScheduledAt);+ }++ Future<void> markInitialMemoriesNotificationScheduled() async {+ await _prefs.setInt(+ _kInitialMemoriesNotificationScheduledAt,+ DateTime.now().millisecondsSinceEpoch,+ );+ }++ bool hasForcedInitialMemoriesRefresh() {+ return _prefs.getBool(_kForcedInitialMemoriesRefresh) ?? false;+ }++ Future<void> markForcedInitialMemoriesRefresh() async {+ await _prefs.setBool(_kForcedInitialMemoriesRefresh, true);+ }+Future<bool> getCraftingMemoriesBannerDismissed() async {return _prefs.getBool(_kCraftingMemoriesBannerDismissed) ?? false;}diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex 88bfd52157..ed30748005 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -2531,6 +2531,8 @@}},"memories": "Memories",+ "memoriesReadyNotificationTitle": "Rediscover your memories β¨",+ "memoriesReadyNotificationBody": "Your first ones are ready, made on your phone.","memoriesWidgetDesc": "Select the kinds of memories you want to see on your home screen.","memoryCount": "{count, plural, =0{no memories} one{{formattedCount} memory} other{{formattedCount} memories}}","@memoryCount": {