π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Split no-location search results
Neeraj Gupta608ed9177388
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex 5b1d4a40c1..faad7aefac 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -1322,6 +1322,14 @@"searchCaptionEmptySection": "Add descriptions like \"#trip\" in photo info to quickly find them here","language": "Language","selectLanguage": "Select Language",+ "noLocation": "No location",+ "@noLocation": {+ "description": "Search result label for files owned by the user with missing location metadata"+ },+ "noLocationTag": "No location tag",+ "@noLocationTag": {+ "description": "Search result label for files that do not have a manual location tag"+ },"locationName": "Location name","addLocation": "Add location","groupNearbyPhotos": "Group nearby photos",diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dartindex 9565711c9d..6cfc41aed8 100644--- a/mobile/apps/photos/lib/services/search_service.dart+++ b/mobile/apps/photos/lib/services/search_service.dart@@ -18,6 +18,7 @@ import "package:photos/db/ml/db.dart";import "package:photos/db/offline_files_db.dart";import 'package:photos/events/local_photos_updated_event.dart';import "package:photos/extensions/user_extension.dart";+import "package:photos/generated/l10n.dart";import "package:photos/models/api/collection/user.dart";import 'package:photos/models/collection/collection.dart';import 'package:photos/models/collection/collection_items.dart';@@ -114,12 +115,7 @@ class SearchService {}_cachedFilesForSearch = _cachedFilesFuture!.then((files) {- return applyDBFilters(- files,- DBFilterOptions(- dedupeUploadID: true,- ),- );+ return applyDBFilters(files, DBFilterOptions(dedupeUploadID: true));});return _cachedFilesForSearch!;@@ -142,10 +138,7 @@ class SearchService {_cachedFilesForHierarchicalSearch = _cachedFilesFuture!.then((files) {return applyDBFilters(files,- DBFilterOptions(- dedupeUploadID: false,- onlyUploadedFiles: true,- ),+ DBFilterOptions(dedupeUploadID: false, onlyUploadedFiles: true),);});@@ -198,8 +191,9 @@ class SearchService {_logger.info("Reading hidden files from db");final hiddenCollections =CollectionsService.instance.getHiddenCollectionIds();- _cachedHiddenFilesFuture =- FilesDB.instance.getAllFilesFromCollections(hiddenCollections);+ _cachedHiddenFilesFuture = FilesDB.instance.getAllFilesFromCollections(+ hiddenCollections,+ );return _cachedHiddenFilesFuture!;}@@ -234,12 +228,11 @@ class SearchService {if (!c.isHidden() &&c.type != CollectionType.uncategorized &&- c.displayName.toLowerCase().contains(- query.toLowerCase(),- )) {+ c.displayName.toLowerCase().contains(query.toLowerCase())) {final EnteFile? thumbnail = await _collectionService.getCover(c);- collectionSearchResults- .add(AlbumSearchResult(CollectionWithThumbnail(c, thumbnail)));+ collectionSearchResults.add(+ AlbumSearchResult(CollectionWithThumbnail(c, thumbnail)),+ );}}@@ -254,9 +247,7 @@ class SearchService {return <AlbumSearchResult>[];}final List<Collection> collections =- _collectionService.getCollectionsForUI(- includedShared: true,- );+ _collectionService.getCollectionsForUI(includedShared: true);final List<AlbumSearchResult> collectionSearchResults = [];@@ -267,8 +258,9 @@ class SearchService {if (!c.isHidden() && c.type != CollectionType.uncategorized) {final EnteFile? thumbnail = await _collectionService.getCover(c);- collectionSearchResults- .add(AlbumSearchResult(CollectionWithThumbnail(c, thumbnail)));+ collectionSearchResults.add(+ AlbumSearchResult(CollectionWithThumbnail(c, thumbnail)),+ );}}@@ -283,10 +275,8 @@ class SearchService {String query,) async {try {- final List<DeviceCollection> deviceCollections =- await FilesDB.instance.getDeviceCollections(- includeCoverThumbnail: true,- );+ final List<DeviceCollection> deviceCollections = await FilesDB.instance+ .getDeviceCollections(includeCoverThumbnail: true);final List<DeviceAlbumSearchResult> results = [];@@ -313,8 +303,9 @@ class SearchService {final List<GenericSearchResult> searchResults = [];for (var yearData in YearsData.instance.yearsData) {if (yearData.year.startsWith(yearFromQuery)) {- final List<EnteFile> filesInYear =- await _getFilesInYear(yearData.duration);+ final List<EnteFile> filesInYear = await _getFilesInYear(+ yearData.duration,+ );if (filesInYear.isNotEmpty) {searchResults.add(GenericSearchResult(@@ -392,7 +383,10 @@ class SearchService {if (holiday.name.toLowerCase().contains(query.toLowerCase())) {final matchedFiles =await FilesDB.instance.getFilesCreatedWithinDurations(- _getDurationsForCalendarDateInEveryYear(holiday.day, holiday.month),+ _getDurationsForCalendarDateInEveryYear(+ holiday.day,+ holiday.month,+ ),ignoreCollections(),order: 'DESC',);@@ -697,11 +691,32 @@ class SearchService {.toList();}- Future<List<GenericSearchResult>> getLocationResults(String query) async {+ Future<List<GenericSearchResult>> getLocationResults(+ BuildContext context,+ String query,+ ) async {final locationTagEntities = (await locationService.getLocationTags());final Map<LocalEntity<LocationTag>, List<EnteFile>> result = {};- final bool showNoLocationTag = query.length > 2 &&- "No Location Tag".toLowerCase().startsWith(query.toLowerCase());+ final normalizedQuery = query.toLowerCase();+ final noLocationName = AppLocalizations.of(context).noLocation;+ final noLocationTagName = AppLocalizations.of(context).noLocationTag;+ final normalizedNoLocationName = noLocationName.toLowerCase();+ final normalizedNoLocationTagName = noLocationTagName.toLowerCase();+ final disambiguationPrefixLength = min(+ normalizedNoLocationName.length,+ normalizedNoLocationTagName.length,+ );+ var sharedPrefixLength = 0;+ while (sharedPrefixLength < disambiguationPrefixLength &&+ normalizedNoLocationName.codeUnitAt(sharedPrefixLength) ==+ normalizedNoLocationTagName.codeUnitAt(sharedPrefixLength)) {+ sharedPrefixLength++;+ }+ final bool showNoLocation = normalizedQuery.length > 2 &&+ normalizedNoLocationName.startsWith(normalizedQuery);+ final bool showNoLocationTag =+ normalizedQuery.length > sharedPrefixLength &&+ normalizedNoLocationTagName.startsWith(normalizedQuery);final List<GenericSearchResult> searchResults = [];@@ -724,8 +739,31 @@ class SearchService {}}}+ if (showNoLocation) {+ final noLocationFiles = allFiles.where((file) {+ return file.isOwner &&+ file.location?.latitude == null &&+ file.location?.longitude == null;+ }).toList();+ if (noLocationFiles.isNotEmpty) {+ searchResults.add(+ GenericSearchResult(+ ResultType.fileType,+ noLocationName,+ noLocationFiles,+ hierarchicalSearchFilter: TopLevelGenericFilter(+ filterName: noLocationName,+ occurrence: kMostRelevantFilter,+ filterResultType: ResultType.fileType,+ matchedUploadedIDs: filesToUploadedFileIDs(noLocationFiles),+ filterIcon: Icons.not_listed_location_outlined,+ ),+ ),+ );+ }+ }if (showNoLocationTag) {- _logger.info("finding photos with no location");+ _logger.info("finding photos with no location tag");// find files that have location but the file's location is not inside// any location tagfinal noLocationTagFiles = allFiles.where((file) {@@ -747,10 +785,10 @@ class SearchService {searchResults.add(GenericSearchResult(ResultType.fileType,- "No Location Tag",+ noLocationTagName,noLocationTagFiles,hierarchicalSearchFilter: TopLevelGenericFilter(- filterName: "No Location Tag",+ filterName: noLocationTagName,occurrence: kMostRelevantFilter,filterResultType: ResultType.fileType,matchedUploadedIDs: filesToUploadedFileIDs(noLocationTagFiles),@@ -774,10 +812,7 @@ class SearchService {onResultTap: (ctx) {routeToPage(ctx,- LocationScreenStateProvider(- entry.key,- const LocationScreen(),- ),+ LocationScreenStateProvider(entry.key, const LocationScreen()),);},hierarchicalSearchFilter: LocationFilter(@@ -925,8 +960,9 @@ class SearchService {return [];}final localIntIds = fileIdToClusterID.keys.toSet();- final localIdMap =- await OfflineFilesDB.instance.getLocalIdsForIntIds(localIntIds);+ final localIdMap = await OfflineFilesDB.instance.getLocalIdsForIntIds(+ localIntIds,+ );final allFiles = await getAllFilesForSearch();final localIdToFile = <String, EnteFile>{};for (final file in allFiles) {@@ -948,9 +984,9 @@ class SearchService {final List<GenericSearchResult> facesResult = [];final sortedClusterIds = clusterIdToFiles.keys.toList()..sort(- (a, b) => clusterIdToFiles[b]!- .length- .compareTo(clusterIdToFiles[a]!.length),+ (a, b) => clusterIdToFiles[b]!.length.compareTo(+ clusterIdToFiles[a]!.length,+ ),);for (final clusterId in sortedClusterIds) {final files = clusterIdToFiles[clusterId]!;@@ -960,9 +996,7 @@ class SearchService {ResultType.faces,"",files,- params: {- kClusterParamId: clusterId,- },+ params: {kClusterParamId: clusterId},onResultTap: (ctx) {routeToPage(ctx,@@ -1030,11 +1064,15 @@ class SearchService {final PersonEntity? p =personIdToPerson[clusterIDToPersonID[cluster] ?? ""];if (p != null) {- final filesForPerson =- personIdToFiles.putIfAbsent(p.remoteID, () => []);+ final filesForPerson = personIdToFiles.putIfAbsent(+ p.remoteID,+ () => [],+ );filesForPerson.add(file);- final fileIdsForPerson =- personIdToFileIds.putIfAbsent(p.remoteID, () => <int>{});+ final fileIdsForPerson = personIdToFileIds.putIfAbsent(+ p.remoteID,+ () => <int>{},+ );fileIdsForPerson.add(entry.key);} else {if (clusterIdToFiles.containsKey(cluster)) {@@ -1051,8 +1089,10 @@ class SearchService {final manualIDs = entry.value.data.manuallyAssigned.toSet();if (manualIDs.isEmpty) continue;- final filesForPerson =- personIdToFiles.putIfAbsent(personID, () => <EnteFile>[]);+ final filesForPerson = personIdToFiles.putIfAbsent(+ personID,+ () => <EnteFile>[],+ );final idSet = personIdToFileIds.putIfAbsent(personID, () => <int>{});for (final manualID in manualIDs) {@@ -1070,9 +1110,8 @@ class SearchService {// get sorted personId by files countfinal sortedPersonIds = personIdToFiles.keys.toList()..sort(- (a, b) => personIdToFiles[b]!.length.compareTo(- personIdToFiles[a]!.length,- ),+ (a, b) =>+ personIdToFiles[b]!.length.compareTo(personIdToFiles[a]!.length),);final pinnedPersonIds = <String>[];final unpinnedPersonIds = <String>[];@@ -1144,9 +1183,9 @@ class SearchService {}final sortedClusterIds = clusterIdToFiles.keys.toList()..sort(- (a, b) => clusterIdToFiles[b]!- .length- .compareTo(clusterIdToFiles[a]!.length),+ (a, b) => clusterIdToFiles[b]!.length.compareTo(+ clusterIdToFiles[a]!.length,+ ),);if (!showIgnoredOnly) {@@ -1334,8 +1373,10 @@ class SearchService {// }if (limit == null || tagSearchResults.length < limit) {- final results =- await locationService.getFilesInCity(filesWithNoLocTag, '');+ final results = await locationService.getFilesInCity(+ filesWithNoLocTag,+ '',+ );final List<City> sortedByResultCount = results.keys.toList()..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));for (final city in sortedByResultCount) {@@ -1360,8 +1401,10 @@ class SearchService {locationTag: LocationTag(name: city.city,radius: defaultCityRadius,- centerPoint:- Location(latitude: city.lat, longitude: city.lng),+ centerPoint: Location(+ latitude: city.lat,+ longitude: city.lng,+ ),aSquare: a * a,bSquare: b * b,),@@ -1533,12 +1576,16 @@ class SearchService {if (pickedTime != null) calcTime = pickedTime;final cache = await memoriesCacheService.debugCacheForTesting();- final memoriesResult = await smartMemoriesService- .calcSmartMemories(calcTime, cache, debugSurfaceAll: true);+ final memoriesResult = await smartMemoriesService.calcSmartMemories(+ calcTime,+ cache,+ debugSurfaceAll: true,+ );locationService.baseLocations = memoriesResult.baseLocations;for (final nowMemory in memoriesResult.memories) {- cache.toShowMemories- .add(ToShowMemory.fromSmartMemory(nowMemory, calcTime));+ cache.toShowMemories.add(+ ToShowMemory.fromSmartMemory(nowMemory, calcTime),+ );}cache.baseLocations.addAll(memoriesResult.baseLocations);// memories = memoriesResult.memories;@@ -1549,20 +1596,14 @@ class SearchService {cache,MemoriesCache.encodeToJsonString,);- _logger.info(- "Smart memories cache written to $tempCachePath",- );+ _logger.info("Smart memories cache written to $tempCachePath");final decodedCache = await decodeJsonFile(tempCachePath,MemoriesCache.decodeFromJsonString,);- _logger.info(- "Smart memories cache decoded from $tempCachePath",- );+ _logger.info("Smart memories cache decoded from $tempCachePath");memories = await MemoriesCacheService.fromCacheToMemories(decodedCache!);- _logger.info(- "Smart memories cache converted to memories",- );+ _logger.info("Smart memories cache converted to memories");}final searchResults = <GenericSearchResult>[];for (final memory in memories) {@@ -1606,8 +1647,10 @@ class SearchService {for (EnteFile file in allFiles) {if (file.isOwner) continue;- final fileOwner = CollectionsService.instance- .getFileOwner(file.ownerID!, file.collectionID);+ final fileOwner = CollectionsService.instance.getFileOwner(+ file.ownerID!,+ file.collectionID,+ );if (fileOwner.email.toLowerCase().contains(lowerCaseQuery) ||((fileOwner.displayName?.toLowerCase().contains(lowerCaseQuery)) ??@@ -1703,8 +1746,10 @@ class SearchService {for (EnteFile file in allFiles) {if (file.isOwner) continue;- final fileOwner = CollectionsService.instance- .getFileOwner(file.ownerID!, file.collectionID);+ final fileOwner = CollectionsService.instance.getFileOwner(+ file.ownerID!,+ file.collectionID,+ );if (peopleToSharedFiles.containsKey(fileOwner)) {peopleToSharedFiles[fileOwner]!.add(file);} else {@@ -1716,8 +1761,9 @@ class SearchService {final allRelevantEmails =UserService.instance.getEmailIDsOfRelevantContacts();- final emailsWithNoSharedFiles =- allRelevantEmails.difference(existingEmails);+ final emailsWithNoSharedFiles = allRelevantEmails.difference(+ existingEmails,+ );for (final email in emailsWithNoSharedFiles) {final user = User(email: email);diff --git a/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/search_widget.dartindex 82830bd339..0f09ab27c5 100644--- a/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart@@ -63,8 +63,9 @@ class SearchWidgetState extends State<SearchWidget> {focusNode.unfocus();}});- _tabDoubleTapEvent =- Bus.instance.on<TabDoubleTapEvent>().listen((event) async {+ _tabDoubleTapEvent = Bus.instance.on<TabDoubleTapEvent>().listen((+ event,+ ) async {debugPrint("Firing now ${event.selectedIndex}");if (mounted && event.selectedIndex == 3) {focusNode.requestFocus();@@ -131,8 +132,10 @@ class SearchWidgetState extends State<SearchWidget> {if (mounted) {query = textController.text.trim();IndexOfStackNotifier().isSearchQueryEmpty = query.isEmpty;- searchResultsStreamNotifier.value =- _getSearchResultsStream(context, query);+ searchResultsStreamNotifier.value = _getSearchResultsStream(+ context,+ query,+ );}});}@@ -247,83 +250,67 @@ class SearchWidgetState extends State<SearchWidget> {});}- _searchService.getHolidaySearchResults(context, query).then(- (holidayResults) {- onResultsReceived(holidayResults);- },- );+ _searchService.getHolidaySearchResults(context, query).then((+ holidayResults,+ ) {+ onResultsReceived(holidayResults);+ });- _searchService.getFileTypeResults(context, query).then(- (fileTypeSearchResults) {- onResultsReceived(fileTypeSearchResults);- },- );+ _searchService.getFileTypeResults(context, query).then((+ fileTypeSearchResults,+ ) {+ onResultsReceived(fileTypeSearchResults);+ });- _searchService.getCaptionAndNameResults(query).then(- (captionAndDisplayNameResult) {- onResultsReceived(captionAndDisplayNameResult);- },- );+ _searchService.getCaptionAndNameResults(query).then((+ captionAndDisplayNameResult,+ ) {+ onResultsReceived(captionAndDisplayNameResult);+ });- _searchService.getFileExtensionResults(query).then(- (fileExtnResult) {- onResultsReceived(fileExtnResult);- },- );+ _searchService.getFileExtensionResults(query).then((fileExtnResult) {+ onResultsReceived(fileExtnResult);+ });- _searchService.getLocationResults(query).then(- (locationResult) {- onResultsReceived(locationResult);- },- );+ _searchService.getLocationResults(context, query).then((locationResult) {+ onResultsReceived(locationResult);+ });- _searchService.getAllFace(null, minClusterSize: 10).then(- (faceResult) {- final List<GenericSearchResult> filteredResults = [];- for (final result in faceResult) {- if (result.name().toLowerCase().contains(query.toLowerCase())) {- filteredResults.add(result);- }+ _searchService.getAllFace(null, minClusterSize: 10).then((faceResult) {+ final List<GenericSearchResult> filteredResults = [];+ for (final result in faceResult) {+ if (result.name().toLowerCase().contains(query.toLowerCase())) {+ filteredResults.add(result);}- onResultsReceived(filteredResults);- },- );+ }+ onResultsReceived(filteredResults);+ });- _searchService.getCollectionSearchResults(query).then(- (collectionResults) {- onResultsReceived(collectionResults);- },- );+ _searchService.getCollectionSearchResults(query).then((collectionResults) {+ onResultsReceived(collectionResults);+ });- _searchService.getDeviceCollectionSearchResults(query).then(- (deviceCollectionResults) {- onResultsReceived(deviceCollectionResults);- },- );+ _searchService.getDeviceCollectionSearchResults(query).then((+ deviceCollectionResults,+ ) {+ onResultsReceived(deviceCollectionResults);+ });- _searchService.getMonthSearchResults(context, query).then(- (monthResults) {- onResultsReceived(monthResults);- },- );+ _searchService.getMonthSearchResults(context, query).then((monthResults) {+ onResultsReceived(monthResults);+ });- _searchService.getDateResults(context, query).then(- (possibleEvents) {- onResultsReceived(possibleEvents);- },- );+ _searchService.getDateResults(context, query).then((possibleEvents) {+ onResultsReceived(possibleEvents);+ });- _searchService.getMagicSearchResults(context, query).then(- (magicResults) {- onResultsReceived(magicResults);- },- );+ _searchService.getMagicSearchResults(context, query).then((magicResults) {+ onResultsReceived(magicResults);+ });- _searchService.getContactSearchResults(query).then(- (contactResults) {- onResultsReceived(contactResults);- },- );+ _searchService.getContactSearchResults(query).then((contactResults) {+ onResultsReceived(contactResults);+ });return streamController.stream;}