Ensure that events are generated on file deletion

This commit is contained in:
Vishnu Mohandas 2020-11-01 12:15:10 +05:30
parent 568947fbf6
commit 2b2db78d67
4 changed files with 9 additions and 5 deletions

View file

@ -46,10 +46,10 @@ class CollectionsService {
Future<void> sync() async {
_logger.info("Syncing");
final lastCollectionCreationTime =
final lastCollectionUpdationTime =
await _db.getLastCollectionUpdationTime();
final fetchedCollections =
await _fetchCollections(lastCollectionCreationTime ?? 0);
await _fetchCollections(lastCollectionUpdationTime ?? 0);
final updatedCollections = List<Collection>();
for (final collection in fetchedCollections) {
if (collection.isDeleted) {

View file

@ -166,7 +166,7 @@ class SyncService {
await _fetchEncryptedFilesDiff(collection.id);
}
await _uploadDiff();
await _deletePhotosOnServer();
await deleteFilesOnServer();
}
Future<void> _fetchEncryptedFilesDiff(int collectionID) async {
@ -284,7 +284,7 @@ class SyncService {
}
}
Future<void> _deletePhotosOnServer() async {
Future<void> deleteFilesOnServer() async {
return _db.getDeletedFileIDs().then((ids) async {
for (int id in ids) {
await _deleteFileOnServer(id);

View file

@ -6,6 +6,7 @@ import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
import 'package:photos/events/collection_updated_event.dart';
import 'package:photos/events/remote_sync_event.dart';
import 'package:photos/models/file.dart';
import 'package:photos/utils/crypto_util.dart';
@ -41,6 +42,8 @@ class DiffFetcher {
if (item["isDeleted"]) {
await FilesDB.instance.deleteFromCollection(
file.uploadedFileID, file.collectionID);
Bus.instance.fire(
CollectionUpdatedEvent(collectionID: file.collectionID));
continue;
}
file.ownerID = item["ownerID"];

View file

@ -43,8 +43,9 @@ Future<void> deleteFiles(List<File> files) async {
await FileRepository.instance.reloadFiles();
if (hasUploadedFiles) {
Bus.instance.fire(CollectionUpdatedEvent());
// TODO: Blocking call?
SyncService.instance.deleteFilesOnServer();
}
SyncService.instance.sync();
}
void preloadFile(File file) {