chore: update addFiles logic
This commit is contained in:
@@ -43,16 +43,25 @@ class SmartAlbumConfig {
|
||||
);
|
||||
}
|
||||
|
||||
SmartAlbumConfig addFiles(String personId, int updatedAt, Set<int> fileId) {
|
||||
if (!infoMap.containsKey(personId)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
SmartAlbumConfig addFiles(
|
||||
Map<String, int> personUpdatedAt,
|
||||
Map<String, Set<int>> personMappedFiles,
|
||||
) {
|
||||
final newInfoMap = Map<String, PersonInfo>.from(infoMap);
|
||||
newInfoMap[personId] = (
|
||||
updatedAt: updatedAt,
|
||||
addedFiles: newInfoMap[personId]!.addedFiles.union(fileId),
|
||||
);
|
||||
var isUpdated = false;
|
||||
|
||||
personMappedFiles.forEach((personId, fileIds) {
|
||||
if (newInfoMap.containsKey(personId)) {
|
||||
isUpdated = true;
|
||||
newInfoMap[personId] = (
|
||||
updatedAt: personUpdatedAt[personId] ??
|
||||
DateTime.now().millisecondsSinceEpoch,
|
||||
addedFiles: {...?newInfoMap[personId]?.addedFiles, ...fileIds},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (!isUpdated) return this;
|
||||
|
||||
return SmartAlbumConfig(
|
||||
id: id,
|
||||
|
||||
@@ -113,7 +113,7 @@ class SmartAlbumsService {
|
||||
config.personIDs.toList(),
|
||||
);
|
||||
|
||||
Set<EnteFile> toBeSynced = {};
|
||||
Map<String, List<EnteFile>> toBeSynced = {};
|
||||
|
||||
var newConfig = config;
|
||||
for (final personId in config.personIDs) {
|
||||
@@ -137,13 +137,7 @@ class SmartAlbumsService {
|
||||
e.ownerID != userId,
|
||||
);
|
||||
|
||||
toBeSynced = {...toBeSynced, ...fileIds};
|
||||
|
||||
newConfig = newConfig.addFiles(
|
||||
personId,
|
||||
updatedAtMap[personId]!,
|
||||
toBeSynced.map((e) => e.uploadedFileID!).toSet(),
|
||||
);
|
||||
toBeSynced = {...toBeSynced, personId: fileIds};
|
||||
}
|
||||
|
||||
syncingCollection = (collectionId, true);
|
||||
@@ -154,9 +148,16 @@ class SmartAlbumsService {
|
||||
if (toBeSynced.isNotEmpty) {
|
||||
try {
|
||||
await CollectionsService.instance.addOrCopyToCollection(
|
||||
toCopy: false,
|
||||
collectionId,
|
||||
toBeSynced.toList(),
|
||||
toBeSynced.entries.map((e) => e.value).expand((e) => e).toList(),
|
||||
toCopy: false,
|
||||
);
|
||||
newConfig = newConfig.addFiles(
|
||||
updatedAtMap,
|
||||
toBeSynced.map(
|
||||
(key, value) =>
|
||||
MapEntry(key, value.map((e) => e.uploadedFileID!).toSet()),
|
||||
),
|
||||
);
|
||||
|
||||
await saveConfig(newConfig);
|
||||
|
||||
Reference in New Issue
Block a user