[mob][photos] Hide incoming file from home screen is saved

This commit is contained in:
Neeraj Gupta 2024-04-19 13:34:25 +05:30
parent 398e66a0eb
commit 7f879aaf57
3 changed files with 48 additions and 15 deletions

View file

@ -1,26 +1,38 @@
import 'package:photos/models/file/file.dart';
import "package:photos/services/filter/filter.dart";
// CollectionsIgnoreFilter will filter out files that are in present in the
// given collections. This is useful for filtering out files that are in archive
// or hidden collections from home page and other places
class CollectionsIgnoreFilter extends Filter {
// CollectionsOrHashIgnoreFilter will filter out all files that are in present in the
// given collections collectionIDs. This is useful for filtering out files that are in archive
// or hidden collections from home page and other places. Based on flag, it will also filter out
// shared files if the user already as another file with the same hash.
class CollectionsAndSavedFileFilter extends Filter {
final Set<int> collectionIDs;
final bool ignoreSavedFiles;
final int ownerID;
Set<int>? _ignoredUploadIDs;
Set<String> ownedFileHashes = {};
CollectionsIgnoreFilter(this.collectionIDs, List<EnteFile> files) : super() {
CollectionsAndSavedFileFilter(
this.collectionIDs,
this.ownerID,
List<EnteFile> files,
this.ignoreSavedFiles,
) : super() {
init(files);
}
void init(List<EnteFile> files) {
_ignoredUploadIDs = {};
if (collectionIDs.isEmpty) return;
for (var file in files) {
if (file.collectionID != null &&
file.isUploaded &&
collectionIDs.contains(file.collectionID!)) {
_ignoredUploadIDs!.add(file.uploadedFileID!);
if (file.collectionID != null && file.isUploaded) {
if (collectionIDs.contains(file.collectionID!)) {
_ignoredUploadIDs!.add(file.uploadedFileID!);
} else if (ignoreSavedFiles &&
file.ownerID == ownerID &&
(file.hash ?? '').isNotEmpty) {
ownedFileHashes.add(file.hash!);
}
}
}
}
@ -37,6 +49,16 @@ class CollectionsIgnoreFilter extends Filter {
}
return true;
}
return !_ignoredUploadIDs!.contains(file.uploadedFileID!);
if (_ignoredUploadIDs!.contains(file.uploadedFileID!)) {
return false; // this file should be filtered out
}
if (ignoreSavedFiles &&
file.ownerID != ownerID &&
(file.hash ?? '').isNotEmpty) {
// if the file is shared and the user already has a file with the same hash
// then filter it out by returning false
return !ownedFileHashes.contains(file.hash!);
}
return true;
}
}

View file

@ -1,3 +1,4 @@
import "package:photos/core/configuration.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/services/filter/collection_ignore.dart";
import "package:photos/services/filter/dedupe_by_upload_id.dart";
@ -12,11 +13,14 @@ class DBFilterOptions {
Set<int>? ignoredCollectionIDs;
bool dedupeUploadID;
bool hideIgnoredForUpload;
// If true, shared files that are already saved in the users account will be ignored.
bool ignoreSavedFiles;
DBFilterOptions({
this.ignoredCollectionIDs,
this.hideIgnoredForUpload = false,
this.dedupeUploadID = true,
this.ignoreSavedFiles = false,
});
static DBFilterOptions dedupeOption = DBFilterOptions(
@ -42,12 +46,18 @@ Future<List<EnteFile>> applyDBFilters(
if (options.dedupeUploadID) {
filters.add(DedupeUploadIDFilter());
}
if (options.ignoredCollectionIDs != null &&
options.ignoredCollectionIDs!.isNotEmpty) {
final collectionIgnoreFilter =
CollectionsIgnoreFilter(options.ignoredCollectionIDs!, files);
if ((options.ignoredCollectionIDs ?? <int>{}).isNotEmpty ||
options.ignoreSavedFiles) {
final collectionIgnoreFilter = CollectionsAndSavedFileFilter(
options.ignoredCollectionIDs ?? <int>{},
Configuration.instance.getUserID() ?? 0,
files,
options.ignoreSavedFiles,
);
filters.add(collectionIgnoreFilter);
}
final List<EnteFile> filterFiles = [];
for (final file in files) {
if (filters.every((f) => f.filter(file))) {

View file

@ -41,6 +41,7 @@ class HomeGalleryWidget extends StatelessWidget {
hideIgnoredForUpload: true,
dedupeUploadID: true,
ignoredCollectionIDs: collectionsToHide,
ignoreSavedFiles: true,
);
if (hasSelectedAllForBackup) {
result = await FilesDB.instance.getAllLocalAndUploadedFiles(