Przeglądaj źródła

Log source for all CollectionUpdate events

Neeraj Gupta 2 lat temu
rodzic
commit
9faeb511db

+ 6 - 2
lib/events/collection_updated_event.dart

@@ -5,6 +5,10 @@ import 'package:photos/events/files_updated_event.dart';
 class CollectionUpdatedEvent extends FilesUpdatedEvent {
   final int collectionID;
 
-  CollectionUpdatedEvent(this.collectionID, updatedFiles, {type})
-      : super(updatedFiles, type: type ?? EventType.addedOrUpdated);
+  CollectionUpdatedEvent(this.collectionID, updatedFiles, source, {type})
+      : super(
+          updatedFiles,
+          type: type ?? EventType.addedOrUpdated,
+          source: source ?? "",
+        );
 }

+ 5 - 0
lib/events/files_updated_event.dart

@@ -6,11 +6,16 @@ import 'package:photos/models/file.dart';
 class FilesUpdatedEvent extends Event {
   final List<File> updatedFiles;
   final EventType type;
+  final String source;
 
   FilesUpdatedEvent(
     this.updatedFiles, {
     this.type = EventType.addedOrUpdated,
+    this.source = "",
   });
+
+  @override
+  String get reason => '${toString()}{type: ${type.name}, "via": $source}';
 }
 
 enum EventType {

+ 1 - 3
lib/events/force_reload_home_gallery_event.dart

@@ -6,7 +6,5 @@ class ForceReloadHomeGalleryEvent extends Event {
   ForceReloadHomeGalleryEvent(this.message);
 
   @override
-  String toString() {
-    return 'ForceReloadHomeGalleryEvent{message: $message}';
-  }
+  String get reason => 'ForceReloadHomeGalleryEvent - $message';
 }

+ 6 - 4
lib/events/local_photos_updated_event.dart

@@ -1,8 +1,10 @@
-
-
 import 'package:photos/events/files_updated_event.dart';
 
 class LocalPhotosUpdatedEvent extends FilesUpdatedEvent {
-  LocalPhotosUpdatedEvent(updatedFiles, {type})
-      : super(updatedFiles, type: type ?? EventType.addedOrUpdated);
+  LocalPhotosUpdatedEvent(updatedFiles, {type, source})
+      : super(
+          updatedFiles,
+          type: type ?? EventType.addedOrUpdated,
+          source: source ?? "",
+        );
 }

+ 30 - 10
lib/services/collections_service.dart

@@ -124,8 +124,13 @@ class CollectionsService {
       _cacheCollectionAttributes(collection);
     }
     if (fetchedCollections.isNotEmpty) {
-      _logger.info("Collections updated");
-      Bus.instance.fire(CollectionUpdatedEvent(null, List<File>.empty()));
+      Bus.instance.fire(
+        CollectionUpdatedEvent(
+          null,
+          List<File>.empty(),
+          "collections_updated",
+        ),
+      );
     }
     return collections;
   }
@@ -428,7 +433,9 @@ class CollectionsService {
       collection.publicURLs?.add(PublicURL.fromMap(response.data["result"]));
       await _db.insert(List.from([collection]));
       _cacheCollectionAttributes(collection);
-      Bus.instance.fire(CollectionUpdatedEvent(collection.id, <File>[]));
+      Bus.instance.fire(
+        CollectionUpdatedEvent(collection.id, <File>[], "shareUrL"),
+      );
     } on DioError catch (e) {
       if (e.response.statusCode == 402) {
         throw SharingNotPermittedForFreeAccountsError();
@@ -455,7 +462,8 @@ class CollectionsService {
       collection.publicURLs?.add(PublicURL.fromMap(response.data["result"]));
       await _db.insert(List.from([collection]));
       _cacheCollectionAttributes(collection);
-      Bus.instance.fire(CollectionUpdatedEvent(collection.id, <File>[]));
+      Bus.instance
+          .fire(CollectionUpdatedEvent(collection.id, <File>[], "updateUrl"));
     } on DioError catch (e) {
       if (e.response.statusCode == 402) {
         throw SharingNotPermittedForFreeAccountsError();
@@ -475,7 +483,13 @@ class CollectionsService {
       collection.publicURLs.clear();
       await _db.insert(List.from([collection]));
       _cacheCollectionAttributes(collection);
-      Bus.instance.fire(CollectionUpdatedEvent(collection.id, <File>[]));
+      Bus.instance.fire(
+        CollectionUpdatedEvent(
+          collection.id,
+          <File>[],
+          "disableShareUrl",
+        ),
+      );
     } on DioError catch (e) {
       _logger.info(e);
       rethrow;
@@ -665,7 +679,7 @@ class CollectionsService {
         data: params,
       );
       await _filesDB.insertMultiple(files);
-      Bus.instance.fire(CollectionUpdatedEvent(collectionID, files));
+      Bus.instance.fire(CollectionUpdatedEvent(collectionID, files, "addTo"));
     } catch (e) {
       rethrow;
     }
@@ -741,8 +755,10 @@ class CollectionsService {
       await _filesDB.insertMultiple(files);
       await TrashDB.instance
           .delete(files.map((e) => e.uploadedFileID).toList());
-      Bus.instance.fire(CollectionUpdatedEvent(toCollectionID, files));
-      Bus.instance.fire(FilesUpdatedEvent(files));
+      Bus.instance.fire(
+        CollectionUpdatedEvent(toCollectionID, files, "restore"),
+      );
+      Bus.instance.fire(FilesUpdatedEvent(files, source: "restore"));
       // Remove imported local files which are imported but not uploaded.
       // This handles the case where local file was trashed -> imported again
       // but not uploaded automatically as it was trashed.
@@ -807,6 +823,7 @@ class CollectionsService {
       CollectionUpdatedEvent(
         fromCollectionID,
         files,
+        "moveFrom",
         type: EventType.deletedFromRemote,
       ),
     );
@@ -817,7 +834,9 @@ class CollectionsService {
       (element) => existingUploadedIDs.contains(element.uploadedFileID),
     );
     await _filesDB.insertMultiple(files);
-    Bus.instance.fire(CollectionUpdatedEvent(toCollectionID, files));
+    Bus.instance.fire(
+      CollectionUpdatedEvent(toCollectionID, files, "moveTo"),
+    );
   }
 
   void _validateMoveRequest(
@@ -855,7 +874,8 @@ class CollectionsService {
       data: params,
     );
     await _filesDB.removeFromCollection(collectionID, params["fileIDs"]);
-    Bus.instance.fire(CollectionUpdatedEvent(collectionID, files));
+    Bus.instance
+        .fire(CollectionUpdatedEvent(collectionID, files, "removeFrom"));
     Bus.instance.fire(LocalPhotosUpdatedEvent(files));
     RemoteSyncService.instance.sync(silently: true).ignore();
   }

+ 2 - 1
lib/services/favorites_service.dart

@@ -46,7 +46,8 @@ class FavoritesService {
     if (file.uploadedFileID == null) {
       file.collectionID = collectionID;
       await _filesDB.insert(file);
-      Bus.instance.fire(CollectionUpdatedEvent(collectionID, [file]));
+      Bus.instance
+          .fire(CollectionUpdatedEvent(collectionID, [file], "addTFav"));
     } else {
       await _collectionsService.addToCollection(collectionID, [file]);
     }

+ 5 - 1
lib/services/hidden_service.dart

@@ -77,7 +77,11 @@ extension HiddenService on CollectionsService {
       }
       Bus.instance.fire(ForceReloadHomeGalleryEvent("hideFiles"));
       Bus.instance.fire(
-        LocalPhotosUpdatedEvent(filesToHide, type: EventType.unarchived),
+        LocalPhotosUpdatedEvent(
+          filesToHide,
+          type: EventType.hide,
+          source: "hideFiles",
+        ),
       );
 
       await dialog.hide();

+ 18 - 4
lib/services/remote_sync_service.dart

@@ -209,6 +209,7 @@ class RemoteSyncService {
         CollectionUpdatedEvent(
           collectionID,
           deletedFiles,
+          "syncDeleteFromRemote",
           type: EventType.deletedFromRemote,
         ),
       );
@@ -216,6 +217,7 @@ class RemoteSyncService {
         LocalPhotosUpdatedEvent(
           deletedFiles,
           type: EventType.deletedFromRemote,
+          source: "syncDeleteFromRemote",
         ),
       );
     }
@@ -227,9 +229,19 @@ class RemoteSyncService {
             " files in collection " +
             collectionID.toString(),
       );
-      Bus.instance.fire(LocalPhotosUpdatedEvent(diff.updatedFiles));
-      Bus.instance
-          .fire(CollectionUpdatedEvent(collectionID, diff.updatedFiles));
+      Bus.instance.fire(
+        LocalPhotosUpdatedEvent(
+          diff.updatedFiles,
+          source: "syncUpdateFromRemote",
+        ),
+      );
+      Bus.instance.fire(
+        CollectionUpdatedEvent(
+          collectionID,
+          diff.updatedFiles,
+          "syncUpdateFromRemote",
+        ),
+      );
     }
 
     if (diff.latestUpdatedAtTime > 0) {
@@ -516,7 +528,9 @@ class RemoteSyncService {
   }
 
   Future<void> _onFileUploaded(File file) async {
-    Bus.instance.fire(CollectionUpdatedEvent(file.collectionID, [file]));
+    Bus.instance.fire(
+      CollectionUpdatedEvent(file.collectionID, [file], "fileUpload"),
+    );
     _completedUploads++;
     final toBeUploadedInThisSession = _uploader.getCurrentSessionUploadCount();
     if (toBeUploadedInThisSession == 0) {

+ 7 - 2
lib/services/trash_sync_service.dart

@@ -72,8 +72,13 @@ class TrashSyncService {
       return await syncTrash();
     } else if (diff.trashedFiles.isNotEmpty ||
         diff.deletedUploadIDs.isNotEmpty) {
-      _logger.fine('refresh gallery');
-      Bus.instance.fire(CollectionUpdatedEvent(0, <File>[]));
+      Bus.instance.fire(
+        CollectionUpdatedEvent(
+          0,
+          <File>[],
+          "trash_change",
+        ),
+      );
     }
   }
 

+ 2 - 2
lib/ui/shared_collections_gallery.dart

@@ -45,12 +45,12 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery>
   void initState() {
     _localFilesSubscription =
         Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
-      debugPrint("SetState Shared Collections on LocalPhotosUpdatedEvent");
+      debugPrint("SetState Shared Collections on ${event.reason}");
       setState(() {});
     });
     _collectionUpdatesSubscription =
         Bus.instance.on<CollectionUpdatedEvent>().listen((event) {
-      debugPrint("SetState Shared Collections on CollectionUpdatedEvent");
+      debugPrint("SetState Shared Collections on ${event.reason}");
       setState(() {});
     });
     _loggedOutEvent = Bus.instance.on<UserLoggedOutEvent>().listen((event) {

+ 2 - 1
lib/ui/viewer/gallery/gallery.dart

@@ -109,7 +109,8 @@ class _GalleryState extends State<Gallery> {
       for (final event in widget.forceReloadEvents) {
         _forceReloadEventSubscriptions.add(
           event.listen((event) async {
-            _logger.info("Force reload $event");
+            _logger.info(event.reason);
+
             final result = await _loadFiles();
             _setFilesAndReload(result.files);
           }),

+ 9 - 2
lib/utils/delete_file_util.dart

@@ -115,6 +115,7 @@ Future<void> deleteFilesFromEverywhere(
           deletedFiles
               .where((file) => file.collectionID == collectionID)
               .toList(),
+          "deleteFilesEverywhere",
           type: EventType.deletedFromEverywhere,
         ),
       );
@@ -176,6 +177,7 @@ Future<void> deleteFilesFromRemoteOnly(
       CollectionUpdatedEvent(
         collectionID,
         files.where((file) => file.collectionID == collectionID).toList(),
+        "deleteFromRemoteOnly",
         type: EventType.deletedFromRemote,
       ),
     );
@@ -266,8 +268,13 @@ Future<bool> deleteFromTrash(BuildContext context, List<File> files) async {
     await TrashSyncService.instance.deleteFromTrash(files);
     showShortToast(context, "Successfully deleted");
     await dialog.hide();
-    Bus.instance
-        .fire(FilesUpdatedEvent(files, type: EventType.deletedFromEverywhere));
+    Bus.instance.fire(
+      FilesUpdatedEvent(
+        files,
+        type: EventType.deletedFromEverywhere,
+        source: "deleteFromTrash",
+      ),
+    );
     return true;
   } catch (e, s) {
     _logger.info("failed to delete from trash", e, s);