Skip to content

armgit / ente

Public Imported from GitHub
0

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

Show albums skipped during library sharing

Neeraj Guptac52bb218ca4e
diff --git a/mobile/apps/photos/lib/services/library_sharing_service.dart b/mobile/apps/photos/lib/services/library_sharing_service.dart
index cb1d6757f5..47e0f23b62 100644
--- a/mobile/apps/photos/lib/services/library_sharing_service.dart
+++ b/mobile/apps/photos/lib/services/library_sharing_service.dart
@@ -30,6 +30,11 @@ const _reconcileEventSources = {
'collection_visibility_changed',
};
+typedef EnableAutomaticSharingResult = ({
+ Set<int> failedIDs,
+ Set<int> previouslyUnsharedIDs,
+});
+
CollectionParticipantRole? librarySharingRoleFor(
Collection collection,
int userID,
@@ -58,7 +63,7 @@ abstract interface class LibrarySharingRepository {
Future<bool> isAutomaticSharingEnabled(int recipientUserID);
- Future<Set<int>> enableAutomaticSharing({
+ Future<EnableAutomaticSharingResult> enableAutomaticSharing({
required LibrarySharingRecipient recipient,
required CollectionParticipantRole role,
});
@@ -206,20 +211,20 @@ class LibrarySharingService implements LibrarySharingRepository {
}
@override
- Future<Set<int>> enableAutomaticSharing({
+ Future<EnableAutomaticSharingResult> enableAutomaticSharing({
required LibrarySharingRecipient recipient,
required CollectionParticipantRole role,
}) async {
- final failedIDs = await _operationLock.synchronized(
+ final result = await _operationLock.synchronized(
() => _enableAutomaticSharing(recipient, role),
);
- if (failedIDs.isEmpty) {
+ if (result.failedIDs.isEmpty) {
await reconcile();
}
- return failedIDs;
+ return result;
}
- Future<Set<int>> _enableAutomaticSharing(
+ Future<EnableAutomaticSharingResult> _enableAutomaticSharing(
LibrarySharingRecipient recipient,
CollectionParticipantRole role,
) async {
@@ -262,7 +267,17 @@ class LibrarySharingService implements LibrarySharingRepository {
ownerUserID,
config.copyWith(enabled: failedIDs.isEmpty),
);
- return failedIDs;
+ final previouslyUnsharedIDs = collections
+ .where(
+ (collection) =>
+ _isShareableAlbum(collection) &&
+ config.unsharedBefore.contains(collection.id) &&
+ !config.hidden.contains(collection.id) &&
+ librarySharingRoleFor(collection, recipient.userID) == null,
+ )
+ .map((collection) => collection.id)
+ .toSet();
+ return (failedIDs: failedIDs, previouslyUnsharedIDs: previouslyUnsharedIDs);
}
@override
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.dart
index 2fdda6fa97..a34f67d431 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
@@ -208,31 +208,33 @@ class LibrarySharingController extends ChangeNotifier {
);
}
- Future<bool> enableAutomaticSharing(CollectionParticipantRole role) async {
+ Future<EnableAutomaticSharingResult?> enableAutomaticSharing(
+ CollectionParticipantRole role,
+ ) async {
if (_isLoading || _isMutating || _isAutomaticSharingEnabled) {
- return false;
+ return null;
}
_beginMutation();
try {
- final failedIDs = await _repository.enableAutomaticSharing(
+ final result = await _repository.enableAutomaticSharing(
recipient: recipient,
role: role,
);
await _reloadAfterMutation();
- _failedCount = failedIDs.length;
- _isAutomaticSharingEnabled = failedIDs.isEmpty;
- if (failedIDs.isEmpty) {
+ _failedCount = result.failedIDs.length;
+ _isAutomaticSharingEnabled = result.failedIDs.isEmpty;
+ if (result.failedIDs.isEmpty) {
_selectionMode = null;
_clearSelectionState();
}
- return failedIDs.isEmpty;
+ return result;
} catch (error, stackTrace) {
_logger.warning(
'Failed to enable automatic library sharing',
error,
stackTrace,
);
- return false;
+ return null;
} finally {
_isMutating = false;
_notifyListeners();
diff --git a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart
index 41eeac039c..e1bddd48db 100644
--- a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart
+++ b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_page.dart
@@ -424,10 +424,22 @@ class _LibrarySharingPageState extends State<LibrarySharingPage> {
}
Future<void> _enableLibrarySharing(CollectionParticipantRole role) async {
- await _showFailureIfNeeded(
- await _controller.enableAutomaticSharing(role),
- () => _enableLibrarySharing(role),
+ final result = await _controller.enableAutomaticSharing(role);
+ if (result == null || result.failedIDs.isNotEmpty) {
+ await _showFailureIfNeeded(false, () => _enableLibrarySharing(role));
+ return;
+ }
+ final previouslyUnsharedCount = result.previouslyUnsharedIDs.length;
+ if (!mounted || previouslyUnsharedCount == 0) {
+ return;
+ }
+ final review = await showPreviouslyUnsharedAlbums(
+ context: context,
+ count: previouslyUnsharedCount,
);
+ if (review && mounted) {
+ _controller.enterAddMode();
+ }
}
Future<void> _showFailureIfNeeded(
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.dart
index 4cb9d3ad9e..c51ef027bd 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
@@ -1,4 +1,5 @@
import 'package:ente_components/ente_components.dart';
+import 'package:ente_strings/ente_strings.dart';
import 'package:flutter/material.dart';
import 'package:photos/models/collection/collection.dart';
import 'package:photos/ui/collections/album/list_item.dart';
@@ -199,6 +200,31 @@ Future<bool> confirmStopLibrarySharing({
false;
}
+Future<bool> showPreviouslyUnsharedAlbums({
+ required BuildContext context,
+ required int count,
+}) async {
+ return await showBottomSheetComponent<bool>(
+ context: context,
+ builder: (sheetContext) => BottomSheetComponent(
+ title: LibrarySharingStrings.previouslyUnsharedTitle(count),
+ message: LibrarySharingStrings.previouslyUnsharedMessage(count),
+ borderSide: BorderSide(
+ color: sheetContext.componentColors.strokeDark,
+ ),
+ actions: [
+ ButtonComponent(
+ label: sheetContext.strings.review,
+ density: ButtonComponentDensity.compact,
+ shouldSurfaceExecutionStates: false,
+ onTap: () => Navigator.of(sheetContext).pop(true),
+ ),
+ ],
+ ),
+ ) ??
+ false;
+}
+
Future<void> showLibrarySharingFailure({
required BuildContext context,
required LibrarySharingController controller,
diff --git a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_strings.dart b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_strings.dart
index c3ac530a0a..08c52ba3cc 100644
--- a/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_strings.dart
+++ b/mobile/apps/photos/lib/ui/sharing/library_sharing/library_sharing_strings.dart
@@ -21,6 +21,18 @@ abstract final class LibrarySharingStrings {
'Hidden albums will not be shared. You can stop sharing any album at any time.',
);
static String get enable => pendingTranslation('Enable');
+ static String previouslyUnsharedTitle(int count) => switch (count) {
+ 1 => pendingTranslation("1 album wasn't shared"),
+ _ => pendingTranslation("$count albums weren't shared"),
+ };
+ static String previouslyUnsharedMessage(int count) => switch (count) {
+ 1 => pendingTranslation(
+ "Sharing was stopped for this album earlier, so it wasn't shared again.",
+ ),
+ _ => pendingTranslation(
+ "Sharing was stopped for these albums earlier, so they weren't shared again.",
+ ),
+ };
static String sharedAlbumCount(int count) => switch (count) {
0 => pendingTranslation('No albums shared'),
1 => pendingTranslation('1 album shared'),
diff --git a/mobile/apps/photos/test/services/library_sharing_service_test.dart b/mobile/apps/photos/test/services/library_sharing_service_test.dart
index 1343d9b9ba..e2668478ac 100644
--- a/mobile/apps/photos/test/services/library_sharing_service_test.dart
+++ b/mobile/apps/photos/test/services/library_sharing_service_test.dart
@@ -20,24 +20,23 @@ void main() {
for (var id = 1; id <= 100; id++) librarySharingTestAlbum(id),
librarySharingTestAlbum(101, type: CollectionType.uncategorized),
];
- final fixture = await _Fixture.create(albums, blockedIDs: {100});
+ final fixture = await _Fixture.create(albums, blockedIDs: {100, 101});
- expect(
- await fixture.service.enableAutomaticSharing(
- recipient: librarySharingTestRecipient,
- role: CollectionParticipantRole.admin,
- ),
- isEmpty,
+ final result = await fixture.service.enableAutomaticSharing(
+ recipient: librarySharingTestRecipient,
+ role: CollectionParticipantRole.admin,
);
+ expect(result.failedIDs, isEmpty);
+ expect(result.previouslyUnsharedIDs, {100});
expect(fixture.collectionsService.shareBatchSizes, [100, 1]);
expect(
fixture.collectionsService.sharedRoles[101],
CollectionParticipantRole.viewer,
);
final config = await fixture.readConfig();
- expect(config.addedAutomatically.length, 100);
- expect(config.unsharedBefore, {100});
+ expect(config.addedAutomatically.length, 99);
+ expect(config.unsharedBefore, {100, 101});
});
test('hidden automatic shares remain until explicitly unshared', () async {
diff --git a/mobile/apps/photos/test/ui/sharing/library_sharing_page_test.dart b/mobile/apps/photos/test/ui/sharing/library_sharing_page_test.dart
index ea6652612a..9187408dd7 100644
--- a/mobile/apps/photos/test/ui/sharing/library_sharing_page_test.dart
+++ b/mobile/apps/photos/test/ui/sharing/library_sharing_page_test.dart
@@ -142,6 +142,45 @@ void main() {
);
});
+ testWidgets('offers to review albums that were previously unshared', (
+ tester,
+ ) async {
+ final repository = FakeLibrarySharingRepository([
+ librarySharingTestAlbum(1),
+ librarySharingTestAlbum(2),
+ ])..automaticSharingBlockedIDs.add(2);
+ final controller = _LayoutTestLibrarySharingController(repository);
+
+ await tester.pumpWidget(
+ _app(
+ LibrarySharingPage(
+ recipient: librarySharingTestRecipient,
+ controller: controller,
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Library sharing'));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+ await tester.tap(find.text('Enable'));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+
+ expect(find.text("1 album wasn't shared"), findsOneWidget);
+ expect(
+ find.text(
+ "Sharing was stopped for this album earlier, so it wasn't shared again.",
+ ),
+ findsOneWidget,
+ );
+
+ await tester.tap(find.text('Review'));
+ await tester.pumpAndSettle();
+ expect(controller.isAddingAlbums, isTrue);
+ expect(find.text('Share with'), findsOneWidget);
+ });
+
testWidgets('keeps the library sharing banner while albums are selected', (
tester,
) async {
@@ -548,16 +587,19 @@ Widget _app(Widget home) {
}
class _LayoutTestLibrarySharingController extends LibrarySharingController {
- _LayoutTestLibrarySharingController()
- : super(
- recipient: librarySharingTestRecipient,
- repository: FakeLibrarySharingRepository([
- librarySharingTestAlbum(
- 1,
- recipientRole: CollectionParticipantRole.viewer,
- ),
- ]),
- );
+ _LayoutTestLibrarySharingController([
+ FakeLibrarySharingRepository? repository,
+ ]) : super(
+ recipient: librarySharingTestRecipient,
+ repository:
+ repository ??
+ FakeLibrarySharingRepository([
+ librarySharingTestAlbum(
+ 1,
+ recipientRole: CollectionParticipantRole.viewer,
+ ),
+ ]),
+ );
@override
List<Collection> get visibleAlbums => const [];
diff --git a/mobile/apps/photos/test/ui/sharing/library_sharing_test_helpers.dart b/mobile/apps/photos/test/ui/sharing/library_sharing_test_helpers.dart
index aac3e8cca5..51500c0568 100644
--- a/mobile/apps/photos/test/ui/sharing/library_sharing_test_helpers.dart
+++ b/mobile/apps/photos/test/ui/sharing/library_sharing_test_helpers.dart
@@ -19,6 +19,7 @@ class FakeLibrarySharingRepository implements LibrarySharingRepository {
final List<int> sharedIDs = [];
final List<int> unsharedIDs = [];
final List<CollectionParticipantRole> sharedRoles = [];
+ final Set<int> automaticSharingBlockedIDs = {};
Completer<void>? shareGate;
Completer<List<Collection>>? loadGate;
Object? loadFailure;
@@ -84,7 +85,7 @@ class FakeLibrarySharingRepository implements LibrarySharingRepository {
automaticSharingEnabled;
@override
- Future<Set<int>> enableAutomaticSharing({
+ Future<EnableAutomaticSharingResult> enableAutomaticSharing({
required LibrarySharingRecipient recipient,
required CollectionParticipantRole role,
}) async {
@@ -92,12 +93,16 @@ class FakeLibrarySharingRepository implements LibrarySharingRepository {
recipient: recipient,
roles: {
for (final album in albums)
- if (librarySharingRoleFor(album, recipient.userID) == null)
+ if (librarySharingRoleFor(album, recipient.userID) == null &&
+ !automaticSharingBlockedIDs.contains(album.id))
album.id: role,
},
);
automaticSharingEnabled = failures.isEmpty;
- return failures;
+ return (
+ failedIDs: failures,
+ previouslyUnsharedIDs: automaticSharingBlockedIDs,
+ );
}
@override