π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Render city results for internal users
vishnukvmdfe2bc0bc975b
diff --git a/lib/core/constants.dart b/lib/core/constants.dartindex 9ae2e8b660..5c70e218f0 100644--- a/lib/core/constants.dart+++ b/lib/core/constants.dart@@ -61,6 +61,8 @@ const defaultRadiusValues = <double>[1, 2, 10, 20, 40, 80, 200, 400, 1200];const defaultRadiusValue = 40.0;+const defaultCityRadius = 10.0;+const galleryGridSpacing = 2.0;const searchSectionLimit = 7;diff --git a/lib/services/location_service.dart b/lib/services/location_service.dartindex 516adff01b..4f61e5f998 100644--- a/lib/services/location_service.dart+++ b/lib/services/location_service.dart@@ -10,6 +10,7 @@ import "package:photos/models/local_entity_data.dart";import "package:photos/models/location/location.dart";import 'package:photos/models/location_tag/location_tag.dart';import "package:photos/services/entity_service.dart";+import "package:photos/services/feature_flag_service.dart";import "package:photos/services/remote_assets_service.dart";import "package:shared_preferences/shared_preferences.dart";@@ -24,7 +25,9 @@ class LocationService {void init(SharedPreferences preferences) {prefs = preferences;- _loadCities();+ if (!FeatureFlagService.instance.isInternalUserOrDebugBuild()) {+ _loadCities();+ }}Future<Iterable<LocalEntity<LocationTag>>> _getStoredLocationTags() async {@@ -34,6 +37,10 @@ class LocationService {);}+ List<City> getAllCities() {+ return _cities;+ }+Future<Iterable<LocalEntity<LocationTag>>> getLocationTags() {return _getStoredLocationTags();}diff --git a/lib/services/search_service.dart b/lib/services/search_service.dartindex 3358648406..7b831480a6 100644--- a/lib/services/search_service.dart+++ b/lib/services/search_service.dart@@ -3,6 +3,7 @@ import "dart:math";import "package:flutter/cupertino.dart";import "package:intl/intl.dart";import 'package:logging/logging.dart';+import "package:photos/core/constants.dart";import 'package:photos/core/event_bus.dart';import 'package:photos/data/holidays.dart';import 'package:photos/data/months.dart';@@ -17,6 +18,7 @@ import "package:photos/models/file/extensions/file_props.dart";import 'package:photos/models/file/file.dart';import 'package:photos/models/file/file_type.dart';import "package:photos/models/local_entity_data.dart";+import "package:photos/models/location/location.dart";import "package:photos/models/location_tag/location_tag.dart";import 'package:photos/models/search/album_search_result.dart';import 'package:photos/models/search/generic_search_result.dart';@@ -681,6 +683,52 @@ class SearchService {return searchResults;}+ Future<List<GenericSearchResult>> getCityResults(String query) async {+ final startTime = DateTime.now().microsecondsSinceEpoch;+ final List<GenericSearchResult> searchResults = [];+ final cities = LocationService.instance.getAllCities();+ final matchingCities = <City>[];+ final queryLower = query.toLowerCase();+ for (City city in cities) {+ if (city.city.toLowerCase().startsWith(queryLower)) {+ matchingCities.add(city);+ }+ }+ final files = await getAllFiles();+ final Map<City, List<EnteFile>> results = {};+ for (final city in matchingCities) {+ final List<EnteFile> matchingFiles = [];+ final cityLocation = Location(latitude: city.lat, longitude: city.lng);+ for (final file in files) {+ if (file.hasLocation) {+ if (LocationService.instance.isFileInsideLocationTag(+ cityLocation,+ file.location!,+ defaultCityRadius,+ )) {+ matchingFiles.add(file);+ }+ }+ }+ if (matchingFiles.isNotEmpty) {+ results[city] = matchingFiles;+ }+ }+ for (final entry in results.entries) {+ searchResults.add(+ GenericSearchResult(+ ResultType.location,+ entry.key.city,+ entry.value,+ ),+ );+ }+ final endTime = DateTime.now().microsecondsSinceEpoch;+ _logger+ .info("Time taken " + ((endTime - startTime) / 1000).toString() + "ms");+ return searchResults;+ }+Future<List<GenericSearchResult>> getAllLocationTags(int? limit) async {try {final Map<LocalEntity<LocationTag>, List<EnteFile>> tagToItemsMap = {};diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dartindex de28c78dcc..daf3d9f8b1 100644--- a/lib/ui/viewer/search/search_widget.dart+++ b/lib/ui/viewer/search/search_widget.dart@@ -278,7 +278,7 @@ class SearchWidgetState extends State<SearchWidget> {String query,) {int resultCount = 0;- final maxResultCount = _isYearValid(query) ? 11 : 10;+ final maxResultCount = _isYearValid(query) ? 12 : 11;final streamController = StreamController<List<SearchResult>>();if (query.isEmpty) {@@ -346,6 +346,16 @@ class SearchWidgetState extends State<SearchWidget> {},);+ _searchService.getCityResults(query).then(+ (results) {+ streamController.sink.add(results);+ resultCount++;+ if (resultCount == maxResultCount) {+ streamController.close();+ }+ },+ );+_searchService.getCollectionSearchResults(query).then((collectionResults) {streamController.sink.add(collectionResults);