π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Include Uncategorized in library sharing
Neeraj Gupta83c94e3e2f7f
diff --git a/mobile/apps/photos/lib/services/library_sharing_service.dart b/mobile/apps/photos/lib/services/library_sharing_service.dartindex 47e0f23b62..40c874afd6 100644--- a/mobile/apps/photos/lib/services/library_sharing_service.dart+++ b/mobile/apps/photos/lib/services/library_sharing_service.dart@@ -48,6 +48,13 @@ CollectionParticipantRole? librarySharingRoleFor(return null;}+CollectionParticipantRole normalizeLibrarySharingRole(+ Collection collection,+ CollectionParticipantRole role,+) => collection.type == CollectionType.uncategorized+ ? CollectionParticipantRole.viewer+ : role;+abstract interface class LibrarySharingRepository {Future<List<Collection>> getEligibleAlbums();@@ -108,8 +115,19 @@ class LibrarySharingService implements LibrarySharingRepository {}@override- Future<List<Collection>> getEligibleAlbums() =>- _collectionsService.orderCollectionsForAlbums(_eligibleAlbums());+ Future<List<Collection>> getEligibleAlbums() async {+ final collections = _eligibleAlbums().toList();+ return [+ ...await _collectionsService.orderCollectionsForAlbums(+ collections.where(+ (collection) => collection.type != CollectionType.uncategorized,+ ),+ ),+ ...collections.where(+ (collection) => collection.type == CollectionType.uncategorized,+ ),+ ];+ }@overrideFuture<Set<int>> shareAlbums({@@ -270,7 +288,6 @@ class LibrarySharingService implements LibrarySharingRepository {final previouslyUnsharedIDs = collections.where((collection) =>- _isShareableAlbum(collection) &&config.unsharedBefore.contains(collection.id) &&!config.hidden.contains(collection.id) &&librarySharingRoleFor(collection, recipient.userID) == null,@@ -393,9 +410,10 @@ class LibrarySharingService implements LibrarySharingRepository {if (!config.hidden.contains(collection.id) &&!config.unsharedBefore.contains(collection.id) &&librarySharingRoleFor(collection, config.recipientUserID) == null)- collection.id: collection.type == CollectionType.uncategorized- ? CollectionParticipantRole.viewer- : config.defaultRole,+ collection.id: normalizeLibrarySharingRole(+ collection,+ config.defaultRole,+ ),};LibrarySharingLocalConfig _applyAutomaticShareResults(@@ -475,8 +493,12 @@ class LibrarySharingService implements LibrarySharingRepository {}Iterable<Collection> _eligibleAlbums() => _collectionsService- .getCollectionsForUI(includeUncategorized: false)- .where(_isShareableAlbum);+ .getCollectionsForUI(includeUncategorized: true)+ .where(+ (collection) =>+ _isShareableAlbum(collection) ||+ collection.type == CollectionType.uncategorized,+ );Iterable<Collection> _automaticallyShareableOwnedCollections(int ownerUserID,diff --git a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_controller.dart b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_controller.dartindex a34f67d431..7b32a797e3 100644--- a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_controller.dart+++ b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_controller.dart@@ -54,6 +54,9 @@ class LibrarySharingController extends ChangeNotifier {_selectedRoles.keys.where(_isShared).length;bool get canStopSharing => selectedActiveShareCount > 0 && !_isMutating;bool get canApply => hasSelection && !_isMutating;+ bool get canEditSelectedRoles =>+ !_isMutating &&+ selectedAlbums.any((album) => album.type != CollectionType.uncategorized);CollectionParticipantRole? get selectedRole {if (_selectedRoles.isEmpty) {@@ -114,10 +117,16 @@ class LibrarySharingController extends ChangeNotifier {CollectionParticipantRole? activeRoleFor(int collectionID) =>_activeRoles[collectionID];- CollectionParticipantRole stagedRoleFor(int collectionID) =>- _selectedRoles[collectionID] ??- activeRoleFor(collectionID) ??- _defaultRole;+ CollectionParticipantRole stagedRoleFor(int collectionID) {+ final role =+ _selectedRoles[collectionID] ??+ activeRoleFor(collectionID) ??+ _defaultRole;+ return normalizeLibrarySharingRole(+ _albums.firstWhere((album) => album.id == collectionID),+ role,+ );+ }void toggleSelection(Collection collection) {if (_isMutating || !isSelecting || !_isVisible(collection)) {@@ -126,7 +135,7 @@ class LibrarySharingController extends ChangeNotifier {final id = collection.id;_failedCount = 0;if (_selectedRoles.remove(id) == null) {- _selectedRoles[id] = activeRoleFor(id) ?? _defaultRole;+ _selectedRoles[id] = stagedRoleFor(id);}_exitEmptyManageMode();_notifyListeners();@@ -137,7 +146,7 @@ class LibrarySharingController extends ChangeNotifier {return;}for (final album in _albums.where(_isVisible)) {- _selectedRoles[album.id] ??= activeRoleFor(album.id) ?? _defaultRole;+ _selectedRoles[album.id] ??= stagedRoleFor(album.id);}_failedCount = 0;_notifyListeners();@@ -157,7 +166,9 @@ class LibrarySharingController extends ChangeNotifier {return;}_defaultRole = role;- _selectedRoles.updateAll((_, _) => role);+ for (final album in selectedAlbums) {+ _selectedRoles[album.id] = normalizeLibrarySharingRole(album, role);+ }_notifyListeners();}@@ -165,7 +176,8 @@ class LibrarySharingController extends ChangeNotifier {if (_isMutating || !_selectedRoles.containsKey(collectionID)) {return;}- _selectedRoles[collectionID] = role;+ final album = _albums.firstWhere((album) => album.id == collectionID);+ _selectedRoles[collectionID] = normalizeLibrarySharingRole(album, role);_notifyListeners();}diff --git a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_role_badge.dart b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_role_badge.dartindex fb8105133a..6527d08be1 100644--- a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_role_badge.dart+++ b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_role_badge.dart@@ -65,11 +65,13 @@ class LibrarySharingRoleSelector extends StatelessWidget {const LibrarySharingRoleSelector({required this.role,this.fallbackLabel,+ this.showChevron = true,super.key,}) : assert(role != null || fallbackLabel != null);final CollectionParticipantRole? role;final String? fallbackLabel;+ final bool showChevron;@overrideWidget build(BuildContext context) {@@ -99,11 +101,13 @@ class LibrarySharingRoleSelector extends StatelessWidget {: librarySharingRoleLabel(context, role!),style: TextStyles.mini.copyWith(color: colors.textBase),),- const SizedBox(width: Spacing.sm),- const HugeIcon(- icon: HugeIcons.strokeRoundedArrowDown01,- size: IconSizes.small,- ),+ if (showChevron) ...[+ const SizedBox(width: Spacing.sm),+ const HugeIcon(+ icon: HugeIcons.strokeRoundedArrowDown01,+ size: IconSizes.small,+ ),+ ],],),);diff --git a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_selection_sheet.dart b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_selection_sheet.dartindex 2103691e44..e56faafe99 100644--- a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_selection_sheet.dart+++ b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_selection_sheet.dart@@ -148,10 +148,11 @@ class LibrarySharingSelectionSheet extends StatelessWidget {Widget _roleControl(BuildContext context) {final selectedRole = controller.selectedRole;- final canEditRole = controller.hasSelection && !controller.isMutating;+ final canEditRole = controller.canEditSelectedRoles;final trailing = LibrarySharingRoleSelector(role: selectedRole,fallbackLabel: LibrarySharingStrings.mixed,+ showChevron: canEditRole,);final menu = MenuComponent(title: LibrarySharingStrings.role,diff --git a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_sheets.dart b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_sheets.dartindex c51ef027bd..86b71bccd7 100644--- a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_sheets.dart+++ b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_sheets.dart@@ -141,6 +141,11 @@ class _LibrarySharingRoleList extends StatelessWidget {itemBuilder: (context, index) {final album = albums[index];final role = controller.stagedRoleFor(album.id);+ final canEditRole = album.type != CollectionType.uncategorized;+ final roleSelector = LibrarySharingRoleSelector(+ role: role,+ showChevron: canEditRole,+ );return ThumbnailListItem(leading:thumbnailBuilder?.call(context, album) ??@@ -154,16 +159,20 @@ class _LibrarySharingRoleList extends StatelessWidget {color: context.componentColors.textBase,),),- trailing: IgnorePointer(- ignoring: controller.isMutating,- child: EntePopupMenuButton<CollectionParticipantRole>(- optionsBuilder: () =>- librarySharingRoleOptions(context, activeRole: role),- onSelected: (role) =>- controller.setRoleForAlbum(album.id, role),- child: LibrarySharingRoleSelector(role: role),- ),- ),+ trailing: canEditRole+ ? IgnorePointer(+ ignoring: controller.isMutating,+ child: EntePopupMenuButton<CollectionParticipantRole>(+ optionsBuilder: () => librarySharingRoleOptions(+ context,+ activeRole: role,+ ),+ onSelected: (role) =>+ controller.setRoleForAlbum(album.id, role),+ child: roleSelector,+ ),+ )+ : roleSelector,);},),@@ -209,6 +218,7 @@ Future<bool> showPreviouslyUnsharedAlbums({builder: (sheetContext) => BottomSheetComponent(title: LibrarySharingStrings.previouslyUnsharedTitle(count),message: LibrarySharingStrings.previouslyUnsharedMessage(count),+ illustration: Image.asset('assets/warning-red.png'),borderSide: BorderSide(color: sheetContext.componentColors.strokeDark,),diff --git a/mobile/apps/photos/test/services/library_sharing_service_test.dart b/mobile/apps/photos/test/services/library_sharing_service_test.dartindex e2668478ac..8c62b10b02 100644--- a/mobile/apps/photos/test/services/library_sharing_service_test.dart+++ b/mobile/apps/photos/test/services/library_sharing_service_test.dart@@ -22,13 +22,18 @@ void main() {];final fixture = await _Fixture.create(albums, blockedIDs: {100, 101});+ expect(+ (await fixture.service.getEligibleAlbums()).last.type,+ CollectionType.uncategorized,+ );+final result = await fixture.service.enableAutomaticSharing(recipient: librarySharingTestRecipient,role: CollectionParticipantRole.admin,);expect(result.failedIDs, isEmpty);- expect(result.previouslyUnsharedIDs, {100});+ expect(result.previouslyUnsharedIDs, {100, 101});expect(fixture.collectionsService.shareBatchSizes, [100, 1]);expect(fixture.collectionsService.sharedRoles[101],@@ -153,6 +158,18 @@ class _FakeCollectionsService extends Mock implements CollectionsService {final List<int> unshareAttempts = [];final Map<int, CollectionParticipantRole> sharedRoles = {};+ @override+ List<Collection> getCollectionsForUI({+ bool includedShared = false,+ bool includeCollab = false,+ bool includeUncategorized = false,+ }) => albums;++ @override+ Future<List<Collection>> orderCollectionsForAlbums(+ Iterable<Collection> collections,+ ) async => collections.toList().reversed.toList();+@overrideList<Collection> getActiveCollections() => albums;diff --git a/mobile/apps/photos/test/ui/sharing/library_sharing_controller_test.dart b/mobile/apps/photos/test/ui/sharing/library_sharing_controller_test.dartindex 5e81971673..bff0ea1377 100644--- a/mobile/apps/photos/test/ui/sharing/library_sharing_controller_test.dart+++ b/mobile/apps/photos/test/ui/sharing/library_sharing_controller_test.dart@@ -180,6 +180,26 @@ void main() {expect(repository.sharedRoles, [CollectionParticipantRole.viewer]);});+ test('keeps uncategorized sharing viewer-only', () async {+ final repository = FakeLibrarySharingRepository([+ librarySharingTestAlbum(1),+ librarySharingTestAlbum(2, type: CollectionType.uncategorized),+ ]);+ final controller = LibrarySharingController(+ recipient: librarySharingTestRecipient,+ repository: repository,+ );+ await controller.load();+ controller.selectAll();+ controller.setRoleForSelection(CollectionParticipantRole.admin);++ expect(controller.stagedRoleFor(1), CollectionParticipantRole.admin);+ expect(controller.stagedRoleFor(2), CollectionParticipantRole.viewer);++ controller.setRoleForAlbum(2, CollectionParticipantRole.collaborator);+ expect(controller.stagedRoleFor(2), CollectionParticipantRole.viewer);+ });+test('does not retry successful writes when the local refresh fails',() async {