π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Track Memory Lane completion per schedule
Priyanshu Dangare61632c0e5fa9
diff --git a/mobile/apps/photos/lib/models/memory_lane/memory_lane_models.dart b/mobile/apps/photos/lib/models/memory_lane/memory_lane_models.dartindex 62ec1a09de..113b738cfa 100644--- a/mobile/apps/photos/lib/models/memory_lane/memory_lane_models.dart+++ b/mobile/apps/photos/lib/models/memory_lane/memory_lane_models.dart@@ -149,17 +149,20 @@ class MemoryLaneSchedule {final String personID;final bool isCluster;final int beginShowingAt;+ final int? lastCompletelySeenAt;const MemoryLaneSchedule({required this.personID,required this.isCluster,required this.beginShowingAt,+ this.lastCompletelySeenAt,});Map<String, dynamic> toJson() => {"personID": personID,"isCluster": isCluster,"beginShowingAt": beginShowingAt,+ "lastCompletelySeenAt": lastCompletelySeenAt,};factory MemoryLaneSchedule.fromJson(Map<String, dynamic> json) {@@ -167,6 +170,7 @@ class MemoryLaneSchedule {personID: json["personID"] as String,isCluster: json["isCluster"] as bool? ?? false,beginShowingAt: json["beginShowingAt"] as int,+ lastCompletelySeenAt: json["lastCompletelySeenAt"] as int?,);}}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 81748d5c7e..4c8c5dc68e 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@@ -113,6 +113,29 @@ class MemoryLaneCacheService {});}+ Future<void> markScheduleCompletelySeen(MemoryLaneSchedule schedule) async {+ await _ensureInitialized();+ await _lock.synchronized(() async {+ final currentCache = await _loadCacheUnsafe();+ final current = currentCache.memoriesStripSchedule[schedule.personID];+ if (current == null ||+ current.beginShowingAt != schedule.beginShowingAt ||+ current.isCluster != schedule.isCluster) {+ return;+ }+ _cache = currentCache.copyWithMemoriesStripScheduleEntry(+ current.personID,+ MemoryLaneSchedule(+ personID: current.personID,+ isCluster: current.isCluster,+ beginShowingAt: current.beginShowingAt,+ lastCompletelySeenAt: DateTime.now().microsecondsSinceEpoch,+ ),+ );+ await _writeCacheUnsafe();+ });+ }+Future<void> removeMemoriesStripSchedule(String personId) async {await _ensureInitialized();await _lock.synchronized(() async {diff --git a/mobile/apps/photos/lib/ui/home/memories/all_memories_page.dart b/mobile/apps/photos/lib/ui/home/memories/all_memories_page.dartindex e8690c6fcc..42ebcc467b 100644--- a/mobile/apps/photos/lib/ui/home/memories/all_memories_page.dart+++ b/mobile/apps/photos/lib/ui/home/memories/all_memories_page.dart@@ -18,6 +18,8 @@ Future<void> openAllMemoriesPage({required int initialPageIndex,MemoryLanePersonTimeline? memoryLane,PersonEntity? memoryLanePerson,+ bool isFromMemoriesStrip = false,+ bool isMemoryLaneSeen = false,BuildContext? context,int initialFileIndex = 0,bool isFromWidgetOrNotifications = false,@@ -26,6 +28,8 @@ Future<void> openAllMemoriesPage({allMemories: allMemories,memoryLane: memoryLane,memoryLanePerson: memoryLanePerson,+ isFromMemoriesStrip: isFromMemoriesStrip,+ isMemoryLaneSeen: isMemoryLaneSeen,initialPageIndex: initialPageIndex,initialFileIndex: initialFileIndex,isFromWidgetOrNotifications: isFromWidgetOrNotifications,@@ -57,6 +61,8 @@ class AllMemoriesPage extends StatefulWidget {final List<SmartMemory> allMemories;final MemoryLanePersonTimeline? memoryLane;final PersonEntity? memoryLanePerson;+ final bool isFromMemoriesStrip;+ final bool isMemoryLaneSeen;final bool isFromWidgetOrNotifications;const AllMemoriesPage({@@ -65,6 +71,8 @@ class AllMemoriesPage extends StatefulWidget {required this.initialPageIndex,this.memoryLane,this.memoryLanePerson,+ this.isFromMemoriesStrip = false,+ this.isMemoryLaneSeen = false,this.initialFileIndex = 0,this.isFromWidgetOrNotifications = false,});@@ -102,7 +110,9 @@ class _AllMemoriesPageState extends State<AllMemoriesPage> {final memoryLane = widget.memoryLane;final hasSeenMemoryLane =memoryLane != null &&- localSettings.hasSeenMemoryLane(memoryLane.personId);+ (widget.isFromMemoriesStrip+ ? widget.isMemoryLaneSeen+ : localSettings.hasSeenMemoryLane(memoryLane.personId));final pages = <MemoryPageWrapper>[];for (final smartMemory in widget.allMemories) {if (smartMemory.memories.isEmpty) continue;@@ -151,6 +161,7 @@ class _AllMemoriesPageState extends State<AllMemoriesPage> {personId: memoryLane.personId,isCluster: memoryLane.isCluster,person: widget.memoryLanePerson,+ isFromMemoriesStrip: widget.isFromMemoriesStrip,isActive:_pages[_activePageIndex].id =="memoryLane_${memoryLane.personId}",diff --git a/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart b/mobile/apps/photos/lib/ui/home/memories/memories_strip.dartindex 14376c69d2..e8777e7eb9 100644--- a/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart+++ b/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart@@ -24,6 +24,7 @@ import "package:photos/models/ml/face/person.dart";import "package:photos/service_locator.dart";import "package:photos/services/collections_service.dart";import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/memory_lane/memory_lane_cache_service.dart";import "package:photos/services/memory_lane/memory_lane_service.dart";import "package:photos/ui/home/memories/all_memories_page.dart";import "package:photos/ui/home/memories/crafting_memories_card.dart";@@ -66,6 +67,7 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {int _fetchMemoriesGeneration = 0;String? _lastWarmSignature;MemoryLanePersonTimeline? _memoryLane;+ MemoryLaneSchedule? _memoryLaneSchedule;Uint8List? _oldestMemoryLaneFace;Uint8List? _newestMemoryLaneFace;PersonEntity? _memoryLanePerson;@@ -222,6 +224,8 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {(memoryLane.isCluster || memoryLanePerson != null) &&oldestMemoryLaneFace != null &&newestMemoryLaneFace != null;+ final hasSeenMemoryLane =+ hasMemoryLane && _memoryLaneSchedule?.lastCompletelySeenAt != null;final hasContent = memories.isNotEmpty || memoryLane != null;final cardBuilders = <MemoryCardWrapper Function(VoidCallback onTap)>[if (hasMemoryLane)@@ -229,6 +233,7 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {id: "memoryLane_${memoryLane.personId}",widget: () => MemoryLaneCardWidget(personId: memoryLane.personId,+ isSeen: hasSeenMemoryLane,oldestFace: oldestMemoryLaneFace,face: newestMemoryLaneFace,personName: memoryLanePerson?.data.name ?? "",@@ -255,16 +260,25 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {allMemories: memories,memoryLane: hasMemoryLane ? memoryLane : null,memoryLanePerson: hasMemoryLane ? memoryLanePerson : null,+ isFromMemoriesStrip: true,+ isMemoryLaneSeen: hasSeenMemoryLane,initialPageIndex: entry.$1,);if (!mounted) return;- setState(() {});+ final schedule = await MemoryLaneCacheService.instance+ .getCurrentMemoriesStripSchedule();+ if (!mounted) return;+ setState(() {+ _memoryLaneSchedule =+ schedule?.personID == _memoryLane?.personId &&+ schedule?.isCluster == _memoryLane?.isCluster+ ? schedule+ : null;+ });}),).toList();final memoryLaneCard = hasMemoryLane ? cards.first : null;- final hasSeenMemoryLane =- hasMemoryLane && localSettings.hasSeenMemoryLane(memoryLane.personId);return [if (_shouldShowCraftingMemories && hasContent)MemoryCardWrapper(@@ -392,6 +406,14 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {if (!mounted || faceCrops == null || !hasGrantedMLConsent) {return;}+ final schedule = await MemoryLaneCacheService.instance+ .getCurrentMemoriesStripSchedule();+ if (!mounted || !hasGrantedMLConsent) return;+ _memoryLaneSchedule =+ schedule?.personID == timeline.personId &&+ schedule?.isCluster == timeline.isCluster+ ? schedule+ : null;_memoryLane = timeline;_oldestMemoryLaneFace = faceCrops.oldest;_newestMemoryLaneFace = faceCrops.newest;@@ -401,6 +423,7 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {void _hideMemoryLane() {setState(() {_memoryLane = null;+ _memoryLaneSchedule = null;_oldestMemoryLaneFace = null;_newestMemoryLaneFace = null;_memoryLanePerson = null;diff --git a/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dart b/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dartindex 46a13474b7..8827db4de9 100644--- a/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dart+++ b/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dart@@ -4,11 +4,11 @@ import "package:ente_components/ente_components.dart";import "package:ente_strings/ente_strings.dart";import "package:ente_ui/theme/colors.dart";import "package:flutter/material.dart";-import "package:photos/service_locator.dart";import "package:photos/ui/home/memories/memory_card_constants.dart";class MemoryLaneCardWidget extends StatelessWidget {final String personId;+ final bool isSeen;final Uint8List oldestFace;final Uint8List face;final String personName;@@ -17,6 +17,7 @@ class MemoryLaneCardWidget extends StatelessWidget {const MemoryLaneCardWidget({required this.personId,+ required this.isSeen,required this.oldestFace,required this.face,required this.personName,@@ -42,7 +43,7 @@ class MemoryLaneCardWidget extends StatelessWidget {child: Container(width: size.width,height: size.height,- foregroundDecoration: localSettings.hasSeenMemoryLane(personId)+ foregroundDecoration: isSeen? const BoxDecoration(color: Color(0xFFBFBFBF),backgroundBlendMode: BlendMode.saturation,@@ -102,9 +103,7 @@ class MemoryLaneCardWidget extends StatelessWidget {inherit: false,height: 16 / 14,fontFamily: TextStyles.outfitFontFamily,- color: localSettings.hasSeenMemoryLane(personId)- ? textFaintDark- : Colors.white,+ color: isSeen ? textFaintDark : Colors.white,fontWeight: FontWeight.w700,),textAlign: TextAlign.left,diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dartindex 547ea5fedb..3fb40e977d 100644--- a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart@@ -17,6 +17,7 @@ import "package:photos/models/memory_lane/memory_lane_models.dart";import "package:photos/models/ml/face/face.dart";import "package:photos/models/ml/face/person.dart";import "package:photos/service_locator.dart";+import "package:photos/services/memory_lane/memory_lane_cache_service.dart";import "package:photos/services/memory_lane/memory_lane_service.dart";import "package:photos/services/memory_share_service.dart";import "package:photos/theme/ente_theme.dart";@@ -59,6 +60,7 @@ class MemoryLanePageV2 extends StatefulWidget {final bool isActive;final VoidCallback? onNextMemory;final VoidCallback? onPreviousMemory;+ final bool isFromMemoriesStrip;const MemoryLanePageV2({required this.personId,@@ -67,6 +69,7 @@ class MemoryLanePageV2 extends StatefulWidget {this.isActive = true,this.onNextMemory,this.onPreviousMemory,+ this.isFromMemoriesStrip = false,super.key,});@@ -91,6 +94,8 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {_decodedEntries = {};final List<EnteFile> _files = [];int i = 0;+ bool _hasMarkedScheduleSeen = false;+ MemoryLaneSchedule? _schedule;@overridevoid initState() {@@ -133,6 +138,15 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {Future<void> _loadMemoryLane() async {try {+ if (widget.isFromMemoriesStrip) {+ final schedule = await MemoryLaneCacheService.instance+ .getCurrentMemoriesStripSchedule();+ if (!mounted) return;+ if (schedule?.personID == widget.personId &&+ schedule?.isCluster == widget.isCluster) {+ _schedule = schedule;+ }+ }final timeline = await MemoryLaneService.instance.getTimeline(widget.personId,isCluster: widget.isCluster,@@ -302,7 +316,10 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {_useFastTransition = fastTransition;}i = index;- if (index != _entries.length - 1) return;+ if (index != _entries.length - 1) {+ _hasMarkedScheduleSeen = false;+ return;+ }final entryKey = _currentEntryKey;unawaited(_chunkinator!.get(_entries[index]).then((bytes) async {@@ -310,11 +327,20 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {!mounted ||!widget.isActive ||_currentEntryKey != entryKey ||- ModalRoute.of(context)?.isCurrent != true ||- localSettings.hasSeenMemoryLane(widget.personId)) {+ ModalRoute.of(context)?.isCurrent != true) {return;}- await localSettings.markMemoryLaneSeen(widget.personId);+ final markScheduleSeen = !_hasMarkedScheduleSeen;+ _hasMarkedScheduleSeen = true;+ if (!localSettings.hasSeenMemoryLane(widget.personId)) {+ await localSettings.markMemoryLaneSeen(widget.personId);+ }+ final schedule = _schedule;+ if (markScheduleSeen && schedule != null) {+ await MemoryLaneCacheService.instance.markScheduleCompletelySeen(+ schedule,+ );+ }}),);}