π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] fix memories strip schedule validation
Priyanshu Dangaree4551c79bdc6
diff --git a/mobile/apps/photos/lib/services/memory_lane/memory_lane_cache_service.dart b/mobile/apps/photos/lib/services/memory_lane/memory_lane_cache_service.dartindex 4b9c9c5163..c949df6c4f 100644--- a/mobile/apps/photos/lib/services/memory_lane/memory_lane_cache_service.dart+++ b/mobile/apps/photos/lib/services/memory_lane/memory_lane_cache_service.dart@@ -6,7 +6,6 @@ import "package:logging/logging.dart";import "package:path/path.dart" as p;import "package:path_provider/path_provider.dart";import "package:photos/models/memory_lane/memory_lane_models.dart";-import "package:photos/services/search_service.dart";import "package:synchronized/synchronized.dart";class MemoryLaneCacheService {@@ -62,35 +61,23 @@ class MemoryLaneCacheService {return cache[personId];}- Future<MemoryLanePersonTimeline?> getScheduledMemoriesStripTimeline() async {+ Future<MemoryLaneSchedule?> getCurrentMemoriesStripSchedule() async {final cache = await getCache();final nowMicros = DateTime.now().microsecondsSinceEpoch;- final timelineKey = maxBy(- cache.memoriesStripSchedule.entries.where((e) {- final timeline = cache.timelines[e.key];- final schedule = e.value;+ return maxBy(+ cache.memoriesStripSchedule.entries.where((entry) {+ final timeline = cache.timelines[entry.key];final endShowingAt =- schedule.beginShowingAt ++ entry.value.beginShowingAt +MemoryLaneSchedule.displayDuration.inMicroseconds;- final inWindow =- schedule.beginShowingAt <= nowMicros && nowMicros < endShowingAt;- return inWindow &&+ return entry.value.beginShowingAt <= nowMicros &&+ nowMicros < endShowingAt &&timeline != null &&timeline.isEligible &&timeline.entries.isNotEmpty;}),(entry) => entry.value.beginShowingAt,- )?.key;- final currentTimeline = cache.timelines[timelineKey];- if (currentTimeline == null) return null;- final hiddenFileIds = (await SearchService.instance.getHiddenFiles())- .map((f) => f.uploadedFileID)- .whereType<int>()- .toSet();- if (currentTimeline.entries.any((e) => hiddenFileIds.contains(e.fileId))) {- return null;- }- return currentTimeline;+ )?.value;}Future<MemoryLaneComputeLogEntry?> getComputeLogEntry(String personId) async {diff --git a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dartindex 4ac9956d37..6131f9421b 100644--- a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart+++ b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart@@ -109,6 +109,10 @@ class MemoryLaneService {}persons.addAll(await PersonService.instance.getPersons());}+ final hiddenFromMemoriesPersonIds = persons+ .where((person) => person.data.hideFromMemories)+ .map((person) => person.remoteID)+ .toSet();if (flagService.internalUser) {final assigned = <String>{};for (final person in persons) {@@ -124,7 +128,7 @@ class MemoryLaneService {}if (flagService.internalUser) {try {- await _scheduleTimelinesForMemoriesStrip();+ await _scheduleTimelinesForMemoriesStrip(hiddenFromMemoriesPersonIds);} catch (e, s) {_logger.severe("_scheduleTimelinesForMemoriesStrip failed:", e, s);}@@ -259,6 +263,27 @@ class MemoryLaneService {return null;}+ Future<MemoryLanePersonTimeline?> getScheduledMemoriesStripTimeline() async {+ if (!isFeatureEnabled) {+ return null;+ }+ final schedule = await _cacheService.getCurrentMemoriesStripSchedule();+ if (schedule == null) {+ return null;+ }+ if (schedule.isCluster) {+ return getTimeline(schedule.personID, isCluster: schedule.isCluster);+ }+ if (!PersonService.isInitialized) {+ return null;+ }+ final person = await PersonService.instance.getPerson(schedule.personID);+ if (person?.data.hideFromMemories ?? false) {+ return null;+ }+ return getTimeline(schedule.personID, isCluster: schedule.isCluster);+ }+bool hasReadyTimelineSync(String personId, {bool isCluster = false}) {if (!isFeatureEnabled) {return false;@@ -914,7 +939,9 @@ class MemoryLaneService {);}- Future<void> _scheduleTimelinesForMemoriesStrip() async {+ Future<void> _scheduleTimelinesForMemoriesStrip(+ Set<String> hiddenFromMemoriesPersonIds,+ ) async {if (!isFeatureEnabled) {return;}@@ -931,6 +958,8 @@ class MemoryLaneService {nowMicros - entry.value.beginShowingAt < cooldownMicros;if (timeline == null ||(timeline.isCluster && !_topNClusters.contains(timeline.personId)) ||+ (!timeline.isCluster &&+ hiddenFromMemoriesPersonIds.contains(timeline.personId)) ||!timeline.isEligible ||timeline.entries.isEmpty ||!isInCooldown) {@@ -941,10 +970,15 @@ class MemoryLaneService {final valid = cache.memoriesStripSchedule.entries.where((entry) => !invalid.contains(entry.key)).toList();+ final hasCurrentSchedule = valid.any((entry) {+ final endShowingAt = entry.value.beginShowingAt + scheduleWindowMicros;+ return entry.value.beginShowingAt <= nowMicros &&+ nowMicros < endShowingAt;+ });final alreadyScheduledAhead = valid.any((s) => s.value.beginShowingAt >= nowMicros + scheduleWindowMicros,);- if (alreadyScheduledAhead) {+ if (hasCurrentSchedule && alreadyScheduledAhead) {await _cacheService.updateMemoriesStripSchedule(invalid, null);return;}@@ -955,6 +989,7 @@ class MemoryLaneService {t.isEligible &&t.entries.isNotEmpty &&(!t.isCluster || _topNClusters.contains(t.personId)) &&+ (t.isCluster || !hiddenFromMemoriesPersonIds.contains(t.personId)) &&(!cache.memoriesStripSchedule.containsKey(t.personId) ||invalid.contains(t.personId)),);@@ -963,10 +998,15 @@ class MemoryLaneService {return;}- final newBeginShowingAt = valid- .map((entry) => entry.value.beginShowingAt + scheduleWindowMicros)- .followedBy([nowMicros])- .max;+ final int newBeginShowingAt;+ if (hasCurrentSchedule) {+ newBeginShowingAt = valid+ .map((entry) => entry.value.beginShowingAt + scheduleWindowMicros)+ .followedBy([nowMicros])+ .max;+ } else {+ newBeginShowingAt = nowMicros;+ }await _cacheService.updateMemoriesStripSchedule(invalid,MemoryLaneSchedule(