moved getFilteredCollectionsWithThumbnail to search_service.dart
This commit is contained in:
parent
260cbb22a5
commit
a0a4e3d1f3
|
@ -159,7 +159,7 @@ class Configuration {
|
|||
FavoritesService.instance.clearCache();
|
||||
MemoriesService.instance.clearCache();
|
||||
BillingService.instance.clearCache();
|
||||
SearchService.instance.clearCachedFiles();
|
||||
SearchService.instance.clearCache();
|
||||
Bus.instance.fire(UserLoggedOutEvent());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import 'package:photos/events/force_reload_home_gallery_event.dart';
|
|||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/collection_file_item.dart';
|
||||
import 'package:photos/models/collection_items.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/magic_metadata.dart';
|
||||
import 'package:photos/services/app_lifecycle_service.dart';
|
||||
|
@ -73,6 +72,10 @@ class CollectionsService {
|
|||
});
|
||||
}
|
||||
|
||||
Map<int, Collection> getCollectionIDtoCollections() {
|
||||
return _collectionIDToCollections;
|
||||
}
|
||||
|
||||
Future<List<Collection>> sync() async {
|
||||
_logger.info("Syncing collections");
|
||||
final lastCollectionUpdationTime =
|
||||
|
@ -171,50 +174,6 @@ class CollectionsService {
|
|||
.toList();
|
||||
}
|
||||
|
||||
// getFilteredCollectionsWithThumbnail removes deleted or archived or
|
||||
// collections which don't have a file from search result
|
||||
Future<List<CollectionWithThumbnail>> getFilteredCollectionsWithThumbnail(
|
||||
String query,
|
||||
) async {
|
||||
// identify collections which have at least one file as we don't display
|
||||
// empty collection
|
||||
|
||||
List<File> latestCollectionFiles = await getLatestCollectionFiles();
|
||||
Map<int, File> collectionIDToLatestFileMap = {
|
||||
for (File file in latestCollectionFiles) file.collectionID: file
|
||||
};
|
||||
|
||||
/* Identify collections whose name matches the search query
|
||||
and is not archived
|
||||
and is not deleted
|
||||
and has at-least one file
|
||||
*/
|
||||
|
||||
List<Collection> matchedCollection = _collectionIDToCollections.values
|
||||
.where(
|
||||
(c) =>
|
||||
!c.isDeleted && // not deleted
|
||||
!c.isArchived() // not archived
|
||||
&&
|
||||
collectionIDToLatestFileMap.containsKey(c.id) && // the
|
||||
// collection is not empty
|
||||
c.name.contains(RegExp(query, caseSensitive: false)),
|
||||
)
|
||||
.toList();
|
||||
List<CollectionWithThumbnail> result = [];
|
||||
final limit = matchedCollection.length < 20 ? matchedCollection.length : 20;
|
||||
for (int i = 0; i < limit; i++) {
|
||||
Collection collection = matchedCollection[i];
|
||||
result.add(
|
||||
CollectionWithThumbnail(
|
||||
collection,
|
||||
collectionIDToLatestFileMap[collection.id],
|
||||
),
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<User>> getSharees(int collectionID) {
|
||||
return _dio
|
||||
.get(
|
||||
|
|
|
@ -5,11 +5,14 @@ import 'package:photos/core/event_bus.dart';
|
|||
import 'package:photos/core/network.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/collection_items.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/location.dart';
|
||||
import 'package:photos/models/search/location_misc./place_and_bbox.dart';
|
||||
import 'package:photos/models/search/location_misc./results_to_list_of_place_and_bbox.dart';
|
||||
import 'package:photos/models/search/location_search_result.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/services/user_service.dart';
|
||||
|
||||
class SearchService {
|
||||
|
@ -18,6 +21,7 @@ class SearchService {
|
|||
final _dio = Network.instance.getDio();
|
||||
final _config = Configuration.instance;
|
||||
final _logger = Logger((UserService).toString());
|
||||
final _collectionService = CollectionsService.instance;
|
||||
|
||||
SearchService._privateConstructor();
|
||||
static final SearchService instance = SearchService._privateConstructor();
|
||||
|
@ -68,7 +72,7 @@ class SearchService {
|
|||
return matchedFiles;
|
||||
}
|
||||
|
||||
void clearCachedFiles() {
|
||||
void clearCache() {
|
||||
_cachedFiles.clear();
|
||||
}
|
||||
|
||||
|
@ -122,4 +126,51 @@ class SearchService {
|
|||
location.longitude != null &&
|
||||
location.longitude != 0;
|
||||
}
|
||||
|
||||
// getFilteredCollectionsWithThumbnail removes deleted or archived or
|
||||
// collections which don't have a file from search result
|
||||
Future<List<CollectionWithThumbnail>> getFilteredCollectionsWithThumbnail(
|
||||
String query,
|
||||
) async {
|
||||
// identify collections which have at least one file as we don't display
|
||||
// empty collection
|
||||
|
||||
List<File> latestCollectionFiles =
|
||||
await _collectionService.getLatestCollectionFiles();
|
||||
Map<int, File> collectionIDToLatestFileMap = {
|
||||
for (File file in latestCollectionFiles) file.collectionID: file
|
||||
};
|
||||
|
||||
/* Identify collections whose name matches the search query
|
||||
and is not archived
|
||||
and is not deleted
|
||||
and has at-least one file
|
||||
*/
|
||||
|
||||
List<Collection> matchedCollection = _collectionService
|
||||
.getCollectionIDtoCollections()
|
||||
.values
|
||||
.where(
|
||||
(c) =>
|
||||
!c.isDeleted && // not deleted
|
||||
!c.isArchived() // not archived
|
||||
&&
|
||||
collectionIDToLatestFileMap.containsKey(c.id) && // the
|
||||
// collection is not empty
|
||||
c.name.contains(RegExp(query, caseSensitive: false)),
|
||||
)
|
||||
.toList();
|
||||
List<CollectionWithThumbnail> result = [];
|
||||
final limit = matchedCollection.length < 20 ? matchedCollection.length : 20;
|
||||
for (int i = 0; i < limit; i++) {
|
||||
Collection collection = matchedCollection[i];
|
||||
result.add(
|
||||
CollectionWithThumbnail(
|
||||
collection,
|
||||
collectionIDToLatestFileMap[collection.id],
|
||||
),
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import 'package:photos/models/search/album_search_result.dart';
|
|||
import 'package:photos/models/search/file_search_result.dart';
|
||||
import 'package:photos/models/search/location_search_result.dart';
|
||||
import 'package:photos/models/search/search_results.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/services/search_service.dart';
|
||||
import 'package:photos/ui/viewer/search/search_results_suggestions.dart';
|
||||
|
||||
|
@ -110,8 +109,7 @@ class _SearchWidgetState extends State<SearchWidget> {
|
|||
onChanged: (value) async {
|
||||
final List<SearchResult> allResults = [];
|
||||
|
||||
final collectionResults = await CollectionsService
|
||||
.instance
|
||||
final collectionResults = await SearchService.instance
|
||||
.getFilteredCollectionsWithThumbnail(value);
|
||||
for (CollectionWithThumbnail collectionResult
|
||||
in collectionResults) {
|
||||
|
|
Loading…
Reference in a new issue