π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Create titles on main thread
laurenspriemfb15ff540ab6
diff --git a/mobile/lib/models/memories/clip_memory.dart b/mobile/lib/models/memories/clip_memory.dartindex 7ec73aa5db..ece3000dc7 100644--- a/mobile/lib/models/memories/clip_memory.dart+++ b/mobile/lib/models/memories/clip_memory.dart@@ -96,7 +96,6 @@ class ClipMemory extends SmartMemory {ClipMemory(List<Memory> memories,- String title,int firstDateToShow,int lastDateToShow,this.clipMemoryType, {@@ -105,27 +104,13 @@ class ClipMemory extends SmartMemory {}) : super(memories,MemoryType.clip,- title,+ '',firstDateToShow,lastDateToShow,);- ClipMemory copyWith({- List<Memory>? memories,- String? title,- int? firstDateToShow,- int? lastDateToShow,- int? firstCreationTime,- int? lastCreationTime,- }) {- return ClipMemory(- memories ?? this.memories,- title ?? this.title,- firstDateToShow ?? this.firstDateToShow,- lastDateToShow ?? this.lastDateToShow,- clipMemoryType,- firstCreationTime: firstCreationTime ?? this.firstCreationTime,- lastCreationTime: lastCreationTime ?? this.lastCreationTime,- );+ @override+ String createTitle() {+ return clipTitle(clipMemoryType);}}diff --git a/mobile/lib/models/memories/filler_memory.dart b/mobile/lib/models/memories/filler_memory.dartindex 3e4e02b2c2..92d83d1520 100644--- a/mobile/lib/models/memories/filler_memory.dart+++ b/mobile/lib/models/memories/filler_memory.dart@@ -2,9 +2,11 @@ import "package:photos/models/memories/memory.dart";import "package:photos/models/memories/smart_memory.dart";class FillerMemory extends SmartMemory {+ // For creating the title+ int yearsAgo;FillerMemory(List<Memory> memories,- String title,+ this.yearsAgo,int firstDateToShow,int lastDateToShow, {int? firstCreationTime,@@ -12,8 +14,13 @@ class FillerMemory extends SmartMemory {}) : super(memories,MemoryType.filler,- title,+ 'filler',firstDateToShow,lastDateToShow,);++ @override+ String createTitle() {+ return "$yearsAgo years ago";+ }}diff --git a/mobile/lib/models/memories/people_memory.dart b/mobile/lib/models/memories/people_memory.dartindex 407c8ab07b..b7da818f90 100644--- a/mobile/lib/models/memories/people_memory.dart+++ b/mobile/lib/models/memories/people_memory.dart@@ -95,6 +95,10 @@ String activityTitle(PeopleActivity activity, String personName) {class PeopleMemory extends SmartMemory {final String personID;final PeopleMemoryType peopleMemoryType;+ final PeopleActivity? activity;+ final String? personName;+ final bool? isBirthday;+ final int? newAge;PeopleMemory(List<Memory> memories,@@ -102,9 +106,13 @@ class PeopleMemory extends SmartMemory {int firstDateToShow,int lastDateToShow,this.peopleMemoryType,- this.personID, {+ this.personID,+ this.personName, {super.firstCreationTime,super.lastCreationTime,+ this.activity,+ this.isBirthday,+ this.newAge,}) : super(memories,MemoryType.people,@@ -114,24 +122,52 @@ class PeopleMemory extends SmartMemory {);PeopleMemory copyWith({- List<Memory>? memories,- String? title,int? firstDateToShow,int? lastDateToShow,- PeopleMemoryType? peopleMemoryType,- String? personID,- int? firstCreationTime,- int? lastCreationTime,+ bool? isBirthday,+ int? newAge,}) {return PeopleMemory(- memories ?? this.memories,- title ?? this.title,+ memories,+ title,firstDateToShow ?? this.firstDateToShow,lastDateToShow ?? this.lastDateToShow,- peopleMemoryType ?? this.peopleMemoryType,- personID ?? this.personID,- firstCreationTime: firstCreationTime ?? this.firstCreationTime,- lastCreationTime: lastCreationTime ?? this.lastCreationTime,+ peopleMemoryType,+ personID,+ personName,+ firstCreationTime: firstCreationTime,+ lastCreationTime: lastCreationTime,+ activity: activity,+ isBirthday: isBirthday ?? this.isBirthday,+ newAge: newAge ?? this.newAge,);}++ // TODO: extract strings below+ @override+ String createTitle() {+ switch (peopleMemoryType) {+ case PeopleMemoryType.youAndThem:+ assert(personName != null);+ return "You and $personName";+ case PeopleMemoryType.doingSomethingTogether:+ assert(activity != null);+ assert(personName != null);+ return activityTitle(activity!, personName!);+ case PeopleMemoryType.spotlight:+ if (personName == null) {+ return "Spotlight on yourself";+ } else if (newAge == null) {+ return "Spotlight on $personName";+ } else {+ if (isBirthday!) {+ return "$personName is $newAge!";+ } else {+ return "$personName turning $newAge soon";+ }+ }+ case PeopleMemoryType.lastTimeYouSawThem:+ return "Last time with $personName";+ }+ }}diff --git a/mobile/lib/models/memories/smart_memory.dart b/mobile/lib/models/memories/smart_memory.dartindex 030d4fd8a2..cbeb5cb172 100644--- a/mobile/lib/models/memories/smart_memory.dart+++ b/mobile/lib/models/memories/smart_memory.dart@@ -56,6 +56,10 @@ class SmartMemory {return now >= firstDateToShow && now <= lastDateToShow;}+ String createTitle() {+ throw UnimplementedError("createTitle must be implemented in subclass");+ }+int averageCreationTime() {if (firstCreationTime != null && lastCreationTime != null) {return (firstCreationTime! + lastCreationTime!) ~/ 2;diff --git a/mobile/lib/models/memories/time_memory.dart b/mobile/lib/models/memories/time_memory.dartindex 7dafef90ec..f9f626dd6d 100644--- a/mobile/lib/models/memories/time_memory.dart+++ b/mobile/lib/models/memories/time_memory.dart@@ -1,19 +1,52 @@+import "package:intl/intl.dart";import "package:photos/models/memories/memory.dart";import "package:photos/models/memories/smart_memory.dart";class TimeMemory extends SmartMemory {+ // For computing the title+ DateTime? day;+ DateTime? month;+ int? yearsAgo;+TimeMemory(List<Memory> memories,- String title,int firstDateToShow,int lastDateToShow, {+ this.day,+ this.month,+ this.yearsAgo,int? firstCreationTime,int? lastCreationTime,}) : super(memories,MemoryType.time,- title,+ '',firstDateToShow,lastDateToShow,);++ @override+ String createTitle() {+ if (day != null) {+ final dayFormat = DateFormat.MMMd().format(day!);+ if (yearsAgo != null) {+ return "$dayFormat, ${yearsAgo!} years ago";+ } else {+ return "$dayFormat through the years";+ }+ }+ if (month != null) {+ final monthFormat = DateFormat.MMMM().format(month!);+ if (yearsAgo != null) {+ return "$monthFormat, ${yearsAgo!} years ago";+ } else {+ return "$monthFormat through the years";+ }+ }+ if (yearsAgo != null) {+ return "This week, ${yearsAgo!} years ago";+ } else {+ return "This week through the years";+ }+ }}diff --git a/mobile/lib/models/memories/trip_memory.dart b/mobile/lib/models/memories/trip_memory.dartindex 8763d20c1e..0ba117652a 100644--- a/mobile/lib/models/memories/trip_memory.dart+++ b/mobile/lib/models/memories/trip_memory.dart@@ -5,39 +5,60 @@ import "package:photos/models/memories/smart_memory.dart";class TripMemory extends SmartMemory {final Location location;+ // Stuff for the title+ String? locationName;+ int? tripYear;+TripMemory(List<Memory> memories,- String title,int firstDateToShow,int lastDateToShow,this.location, {+ this.locationName,+ this.tripYear,super.firstCreationTime,super.lastCreationTime,}) : super(memories,MemoryType.trips,- title,+ '',firstDateToShow,lastDateToShow,);TripMemory copyWith({List<Memory>? memories,- String? title,int? firstDateToShow,int? lastDateToShow,- Location? location,- int? firstCreationTime,- int? lastCreationTime,+ String? locationName,+ int? tripYear,}) {return TripMemory(memories ?? this.memories,- title ?? this.title,firstDateToShow ?? this.firstDateToShow,lastDateToShow ?? this.lastDateToShow,- location ?? this.location,- firstCreationTime: firstCreationTime ?? this.firstCreationTime,- lastCreationTime: lastCreationTime ?? this.lastCreationTime,+ location,+ locationName: locationName ?? this.locationName,+ tripYear: tripYear ?? this.tripYear,+ firstCreationTime: firstCreationTime,+ lastCreationTime: lastCreationTime,);}++ @override+ String createTitle() {+ assert(locationName != null || tripYear != null);+ if (locationName != null) {+ if (locationName!.toLowerCase().contains("base")) return locationName!;+ return "Trip to $locationName";+ }+ if (tripYear != null) {+ if (tripYear == DateTime.now().year - 1) {+ return "Last year's trip";+ } else {+ return "Trip in $tripYear";+ }+ }+ throw ArgumentError("TripMemory must have a location name or trip year");+ }}diff --git a/mobile/lib/services/smart_memories_service.dart b/mobile/lib/services/smart_memories_service.dartindex 94d3cc3b57..7c8a8097c5 100644--- a/mobile/lib/services/smart_memories_service.dart+++ b/mobile/lib/services/smart_memories_service.dart@@ -12,6 +12,8 @@ import "package:photos/core/constants.dart";import "package:photos/db/memories_db.dart";import "package:photos/db/ml/db.dart";import "package:photos/extensions/stop_watch.dart";+// import "package:photos/generated/l10n.dart";+// import "package:photos/l10n/l10n.dart";import "package:photos/models/base_location.dart";import "package:photos/models/file/file.dart";import "package:photos/models/location/location.dart";@@ -110,11 +112,12 @@ class SmartMemoriesService {}_logger.finest('clipPositiveTextVector and clipPeopleActivityVectors $t');- // final locale = await getLocale();- // TODO: lau: locale with DateFormat is not working well in computer, fix later+ // final local = await getLocale();+ // final s = await S.load(local!);+ // _logger.finest('get locale and S $t');_logger.finest('all data fetched $t at ${DateTime.now()}, to computer');- return Computer.shared().compute(+ final memoriesResult = await Computer.shared().compute(_allMemoriesCalculations,param: <String, dynamic>{"allFiles": allFiles,@@ -132,7 +135,11 @@ class SmartMemoriesService {"clipPeopleActivityVectors": clipPeopleActivityVectors,"clipMemoryTypeVectors": clipMemoryTypeVectors,},- );+ ) as MemoriesResult;+ for (final memory in memoriesResult.memories) {+ memory.title = memory.createTitle();+ }+ return memoriesResult;} catch (e, s) {_logger.severe("Error calculating smart memories", e, s);return MemoriesResult(<SmartMemory>[], <BaseLocation>[]);@@ -209,6 +216,7 @@ class SmartMemoriesService {}dev.log('arguments from indirect data calculated $t');dev.log('starting actual memory calculations ${DateTime.now()}');+ dev.log("All files length at start: ${allFiles.length} $t");final List<SmartMemory> memories = [];@@ -388,10 +396,6 @@ class SmartMemoriesService {}}if (spotlightFiles.length > 5) {- String title = "Spotlight on $personName";- if (isMeAssigned && meID == personID) {- title = "Spotlight on yourself";- }final selectSpotlightMemories = await _bestSelectionPeople(spotlightFiles.map((f) => Memory.fromFile(f, seenTimes)).toList(),fileIDToImageEmbedding: fileIDToImageEmbedding,@@ -399,11 +403,12 @@ class SmartMemoriesService {);final spotlightMemory = PeopleMemory(selectSpotlightMemories,- title,+ '',nowInMicroseconds,windowEnd,PeopleMemoryType.spotlight,personID,+ (isMeAssigned && meID == personID) ? null : personName,);personToMemories.putIfAbsent(personID, () => {})@@ -424,7 +429,7 @@ class SmartMemoriesService {}}if (youAndThemFiles.length > 5) {- final String title = "You and $personName";+ // final String title = "You and $personName";final selectYouAndThemMemories = await _bestSelectionPeople(youAndThemFiles.map((f) => Memory.fromFile(f, seenTimes)).toList(),fileIDToImageEmbedding: fileIDToImageEmbedding,@@ -432,11 +437,12 @@ class SmartMemoriesService {);final youAndThemMemory = PeopleMemory(selectYouAndThemMemories,- title,+ '',nowInMicroseconds,windowEnd,PeopleMemoryType.youAndThem,personID,+ personName,);personToMemories.putIfAbsent(personID, () => {}).putIfAbsent(PeopleMemoryType.youAndThem,@@ -480,7 +486,7 @@ class SmartMemoriesService {}}if (activityFiles.length > 5) {- final String title = activityTitle(activity, personName);+ // final String title = activityTitle(activity, personName);final selectActivityMemories = await _bestSelectionPeople(activityFiles.map((f) => Memory.fromFile(f, seenTimes)).toList(),fileIDToImageEmbedding: fileIDToImageEmbedding,@@ -488,11 +494,13 @@ class SmartMemoriesService {);final activityMemory = PeopleMemory(selectActivityMemories,- title,+ '',nowInMicroseconds,windowEnd,PeopleMemoryType.doingSomethingTogether,personID,+ personName,+ activity: activity,);personToMemories.putIfAbsent(personID, () => {})@@ -535,16 +543,17 @@ class SmartMemoriesService {}}if (longAgo && lastTimeYouSawThemFiles.length >= 2 && meID != personID) {- final String title = "Last time with $personName";+ // final String title = "Last time with $personName";final lastTimeMemory = PeopleMemory(lastTimeYouSawThemFiles.map((f) => Memory.fromFile(f, seenTimes)).toList(),- title,+ '',nowInMicroseconds,windowEnd,PeopleMemoryType.lastTimeYouSawThem,personID,+ personName,lastCreationTime: lastCreationTime,);personToMemories.putIfAbsent(personID, () => {}).putIfAbsent(@@ -578,17 +587,17 @@ class SmartMemoriesService {DateTime(currentTime.year, birthdate.month, birthdate.day);final daysTillBirthday = thisBirthday.difference(currentTime).inDays;if (daysTillBirthday < 7 && daysTillBirthday >= 0) {- final personName = person.data.name;final int newAge = currentTime.year - birthdate.year;final spotlightMem =personMemories[PeopleMemoryType.spotlight]?.first;- if (spotlightMem != null) {- final String firstTitle = "$personName turning $newAge!";- final String secondTitle = "$personName is $newAge!";+ if (spotlightMem != null && spotlightMem.personName != null) {+ // final String firstTitle = "$personName turning $newAge!";+ // final String secondTitle = "$personName is $newAge!";final thisBirthday = birthdate.copyWith(year: currentTime.year);memoryResults.add(spotlightMem.copyWith(- title: firstTitle,+ isBirthday: false,+ newAge: newAge,firstDateToShow: thisBirthday.subtract(const Duration(days: 6)).microsecondsSinceEpoch,@@ -597,7 +606,8 @@ class SmartMemoriesService {);memoryResults.add(spotlightMem.copyWith(- title: secondTitle,+ isBirthday: true,+ newAge: newAge,firstDateToShow: thisBirthday.microsecondsSinceEpoch,lastDateToShow:thisBirthday.add(kDayItself).microsecondsSinceEpoch,@@ -741,7 +751,6 @@ class SmartMemoriesService {});clipTypeToMemory[clipMemoryType] = ClipMemory(clipFiles.take(10).map((f) => Memory.fromFile(f, seenTimes)).toList(),- clipTitle(clipMemoryType),nowInMicroseconds,windowEnd,clipMemoryType,@@ -936,7 +945,6 @@ class SmartMemoriesService {currentBlockFiles,seenTimes,),- 'Trip1',0,0,location,@@ -963,7 +971,6 @@ class SmartMemoriesService {tripLocations.add(TripMemory(Memory.fromFiles(currentBlockFiles, seenTimes),- 'Trip2',0,0,location,@@ -997,7 +1004,6 @@ class SmartMemoriesService {)) {mergedTrips[idx] = TripMemory(otherTrip.memories + trip.memories,- 'Trip3',0,0,otherTrip.location,@@ -1015,7 +1021,6 @@ class SmartMemoriesService {mergedTrips.add(TripMemory(trip.memories,- 'Trip4',0,0,trip.location,@@ -1052,10 +1057,10 @@ class SmartMemoriesService {memoryResults.add(TripMemory(Memory.fromFiles(baseLocation.files, seenTimes),- name,nowInMicroseconds,windowEnd,baseLocation.location,+ locationName: name,),);}@@ -1065,12 +1070,12 @@ class SmartMemoriesService {).year;final String? locationName =_tryFindLocationName(trip.memories, cities);- String name = "Trip in $year";- if (locationName != null) {- name = "Trip to $locationName";- } else if (year == currentTime.year - 1) {- name = "Last year's trip";- }+ // String name = "Trip in $year";+ // if (locationName != null) {+ // name = "Trip to $locationName";+ // } else if (year == currentTime.year - 1) {+ // name = "Last year's trip";+ // }final photoSelection = await _bestSelection(trip.memories,fileIdToFaces: fileIdToFaces,@@ -1081,7 +1086,8 @@ class SmartMemoriesService {memoryResults.add(trip.copyWith(memories: photoSelection,- title: name,+ tripYear: year,+ locationName: locationName,firstDateToShow: nowInMicroseconds,lastDateToShow: windowEnd,),@@ -1124,13 +1130,13 @@ class SmartMemoriesService {.year;final String? locationName =_tryFindLocationName(trip.memories, cities);- String name =- "Trip in $year"; // TODO lau: extract strings for translation- if (locationName != null) {- name = "Trip to $locationName";- } else if (year == currentTime.year - 1) {- name = "Last year's trip";- }+ // String name =+ // "Trip in $year"; // TODO lau: extract strings for translation+ // if (locationName != null) {+ // name = "Trip to $locationName";+ // } else if (year == currentTime.year - 1) {+ // name = "Last year's trip";+ // }final photoSelection = await _bestSelection(trip.memories,fileIdToFaces: fileIdToFaces,@@ -1157,7 +1163,8 @@ class SmartMemoriesService {memoryResults.add(trip.copyWith(memories: photoSelection,- title: name,+ tripYear: year,+ locationName: locationName,firstDateToShow: firstDateToShow,lastDateToShow: lastDateToShow,),@@ -1201,12 +1208,12 @@ class SmartMemoriesService {).year;final String? locationName =_tryFindLocationName(trip.memories, cities);- String name = "Trip in $year";- if (locationName != null) {- name = "Trip to $locationName";- } else if (year == currentTime.year - 1) {- name = "Last year's trip";- }+ // String name = "Trip in $year";+ // if (locationName != null) {+ // name = "Trip to $locationName";+ // } else if (year == currentTime.year - 1) {+ // name = "Last year's trip";+ // }final photoSelection = await _bestSelection(trip.memories,fileIdToFaces: fileIdToFaces,@@ -1217,7 +1224,8 @@ class SmartMemoriesService {memoryResults.add(trip.copyWith(memories: photoSelection,- title: name,+ tripYear: year,+ locationName: locationName,firstDateToShow: nowInMicroseconds,lastDateToShow: windowEnd,),@@ -1297,7 +1305,7 @@ class SmartMemoriesService {memoryResult.add(TimeMemory(photoSelection,- "${DateFormat.MMMd().format(date)} through the years",+ day: date,date.subtract(kMemoriesMargin).microsecondsSinceEpoch,date.add(kDayItself).microsecondsSinceEpoch,),@@ -1316,12 +1324,13 @@ class SmartMemoriesService {fileIDToImageEmbedding: fileIDToImageEmbedding,clipPositiveTextVector: clipPositiveTextVector,);- final name =- "${DateFormat.MMMd().format(date)}, ${currentTime.year - date.year} years ago";+ // final name =+ // "${DateFormat.MMMd().format(date)}, ${currentTime.year - date.year} years ago";memoryResult.add(TimeMemory(photoSelection,- name,+ day: date,+ yearsAgo: currentTime.year - date.year,showDate.subtract(kMemoriesMargin).microsecondsSinceEpoch,showDate.add(kDayItself).microsecondsSinceEpoch,),@@ -1365,11 +1374,10 @@ class SmartMemoriesService {fileIDToImageEmbedding: fileIDToImageEmbedding,clipPositiveTextVector: clipPositiveTextVector,);- const name = "This week through the years";+ // const name = "This week through the years";memoryResult.add(TimeMemory(photoSelection,- name,currentTime.subtract(kMemoriesMargin).microsecondsSinceEpoch,currentTime.add(kMemoriesUpdateFrequency).microsecondsSinceEpoch,),@@ -1388,12 +1396,12 @@ class SmartMemoriesService {fileIDToImageEmbedding: fileIDToImageEmbedding,clipPositiveTextVector: clipPositiveTextVector,);- final name = "This week, ${currentTime.year - date.year} years ago";+ // final name = "This week, ${currentTime.year - date.year} years ago";memoryResult.add(TimeMemory(photoSelection,- name,+ yearsAgo: currentTime.year - date.year,currentTime.subtract(kMemoriesMargin).microsecondsSinceEpoch,currentTime.add(kMemoriesUpdateFrequency)@@ -1443,14 +1451,15 @@ class SmartMemoriesService {fileIDToImageEmbedding: fileIDToImageEmbedding,clipPositiveTextVector: clipPositiveTextVector,);- final monthName = DateFormat.MMMM().format(DateTime(year, currentMonth));+ // final monthName = DateFormat.MMMM().format(DateTime(year, currentMonth));final daysLeftInMonth =DateTime(currentYear, currentMonth + 1, 0).day - currentTime.day + 1;- final name = monthName + ", ${currentTime.year - year} years ago";+ // final name = monthName + ", ${currentTime.year - year} years ago";memoryResult.add(TimeMemory(photoSelection,- name,+ month: DateTime(year, currentMonth),+ yearsAgo: currentTime.year - year,currentTime.microsecondsSinceEpoch,currentTime.add(Duration(days: daysLeftInMonth))@@ -1471,15 +1480,15 @@ class SmartMemoriesService {fileIDToImageEmbedding: fileIDToImageEmbedding,clipPositiveTextVector: clipPositiveTextVector,);- final monthName =- DateFormat.MMMM().format(DateTime(currentTime.year, currentMonth));+ // final monthName =+ // DateFormat.MMMM().format(DateTime(currentTime.year, currentMonth));final daysLeftInMonth =DateTime(currentYear, currentMonth + 1, 0).day - currentTime.day + 1;- final name = monthName + " through the years";+ // final name = monthName + " through the years";memoryResult.add(TimeMemory(photoSelection,- name,+ month: DateTime(currentYear, currentMonth),currentTime.microsecondsSinceEpoch,currentTime.add(Duration(days: daysLeftInMonth)).microsecondsSinceEpoch,),@@ -1537,7 +1546,7 @@ class SmartMemoriesService {);final fillerMemory = FillerMemory(memories,- "filler",+ yearAgo,nowInMicroseconds,windowEnd,);