Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix: refresh app bar on add files + delete config if no person selected

Prateek Sunal435a803eab04
diff --git a/mobile/apps/photos/lib/events/collection_meta_event.dart b/mobile/apps/photos/lib/events/collection_meta_event.dart
index ac5288f741..4b416b0dfa 100644
--- a/mobile/apps/photos/lib/events/collection_meta_event.dart
+++ b/mobile/apps/photos/lib/events/collection_meta_event.dart
@@ -14,4 +14,5 @@ enum CollectionMetaEventType {
sortChanged,
orderChanged,
thumbnailChanged,
+ autoAddPeople,
}
diff --git a/mobile/apps/photos/lib/services/smart_albums_service.dart b/mobile/apps/photos/lib/services/smart_albums_service.dart
index 0c1b2856be..8dda828db3 100644
--- a/mobile/apps/photos/lib/services/smart_albums_service.dart
+++ b/mobile/apps/photos/lib/services/smart_albums_service.dart
@@ -176,13 +176,20 @@ class SmartAlbumsService {
Future<void> saveConfig(SmartAlbumConfig config) async {
final userId = Configuration.instance.getUserID()!;
- await _addOrUpdateEntity(
- EntityType.smartAlbum,
- config.toJson(),
- collectionId: config.collectionId,
- addWithCustomID: config.id == null,
- userId: userId,
- );
+ if (config.personIDs.isNotEmpty) {
+ await _addOrUpdateEntity(
+ EntityType.smartAlbum,
+ config.toJson(),
+ collectionId: config.collectionId,
+ addWithCustomID: config.id == null,
+ userId: userId,
+ );
+ } else if (config.id != null) {
+ await _deleteEntry(
+ userId: userId,
+ collectionId: config.collectionId,
+ );
+ }
}
Future<SmartAlbumConfig?> getConfig(int collectionId) async {
@@ -201,10 +208,7 @@ class SmartAlbumsService {
bool addWithCustomID = false,
required int userId,
}) async {
- final id = getId(
- collectionId: collectionId,
- userId: userId,
- );
+ final id = getId(collectionId: collectionId, userId: userId);
final result = await entityService.addOrUpdate(
type,
jsonMap,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
index 5d98bf26e2..303a98192f 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
@@ -100,6 +100,14 @@ class CollectionPage extends StatelessWidget {
? EmptyAlbumState(
c.collection,
isFromCollectPhotos: isFromCollectPhotos,
+ onAddPhotos: () {
+ Bus.instance.fire(
+ CollectionMetaEvent(
+ c.collection.id,
+ CollectionMetaEventType.autoAddPeople,
+ ),
+ );
+ },
)
: const EmptyState(),
footer: isFromCollectPhotos
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart b/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart
index 83e0ae7db6..68945d8a98 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/empty_album_state.dart
@@ -12,10 +12,13 @@ import "package:photos/utils/navigation_util.dart";
class EmptyAlbumState extends StatelessWidget {
final Collection c;
final bool isFromCollectPhotos;
+ final VoidCallback? onAddPhotos;
+
const EmptyAlbumState(
this.c, {
super.key,
this.isFromCollectPhotos = false,
+ this.onAddPhotos,
});
@override
@@ -107,6 +110,7 @@ class EmptyAlbumState extends StatelessWidget {
context,
SmartAlbumPeople(collectionId: c.id),
);
+ onAddPhotos?.call();
},
),
const SizedBox(height: 48),
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
index 03c0b00625..c44f9b2eaf 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -11,6 +11,7 @@ import "package:photos/core/constants.dart";
import 'package:photos/core/event_bus.dart';
import "package:photos/core/network/network.dart";
import "package:photos/db/files_db.dart";
+import "package:photos/events/collection_meta_event.dart";
import "package:photos/events/magic_sort_change_event.dart";
import 'package:photos/events/subscription_purchased_event.dart';
import "package:photos/gateways/cast_gw.dart";
@@ -111,6 +112,7 @@ enum AlbumPopupAction {
class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
final _logger = Logger("GalleryAppBar");
late StreamSubscription _userAuthEventSubscription;
+ late StreamSubscription<CollectionMetaEvent> _collectionMetaEventSubscription;
late Function() _selectedFilesListener;
String? _appBarTitle;
late CollectionActions collectionActions;
@@ -131,6 +133,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {
setState(() {});
});
+ _collectionMetaEventSubscription = Bus.instance
+ .on<CollectionMetaEvent>()
+ .where(
+ (event) =>
+ event.id == widget.collection?.id &&
+ event.type == CollectionMetaEventType.autoAddPeople,
+ )
+ .listen(stateRefresh);
+
_appBarTitle = widget.title;
galleryType = widget.type;
}
@@ -138,10 +149,16 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
@override
void dispose() {
_userAuthEventSubscription.cancel();
+ _collectionMetaEventSubscription.cancel();
widget.selectedFiles.removeListener(_selectedFilesListener);
super.dispose();
}
+ void stateRefresh(dynamic event) {
+ if (!mounted) return;
+ setState(() {});
+ }
+
@override
Widget build(BuildContext context) {
final inheritedSearchFilterData =