Skip to content

armgit / ente

Public Imported from GitHub
0

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

Merge main and retain batch sharing in the new flow

AmanRajSinghMouryab421c3454441
diff --cc mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
index f4d5bcc913,71d5552f27..39d255fff1
--- a/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
+++ b/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
@@@ -7,10 -7,8 +7,9 @@@ import 'package:flutter/material.dart'
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
import "package:photos/core/errors.dart";
+import "package:photos/core/network/api_response.dart";
import 'package:photos/db/files_db.dart';
import 'package:photos/gateways/collections/models/create_request.dart';
- import "package:photos/models/api/collection/user.dart";
import 'package:photos/models/button_result.dart';
import 'package:photos/models/collection/collection.dart';
import 'package:photos/models/file/file.dart';
@@@ -28,7 -23,6 +24,7 @@@ import 'package:photos/ui/components/bu
import 'package:photos/ui/components/models/button_type.dart';
import 'package:photos/ui/notification/toast.dart';
import 'package:photos/ui/payment/subscription.dart';
++import 'package:photos/ui/sharing/widgets/sharing_role.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/email_util.dart';
import 'package:photos/utils/share_util.dart';
@@@ -163,270 -184,116 +186,189 @@@ class CollectionActions
return null;
}
- Future<bool> removeParticipant(
- BuildContext context,
- Collection collection,
- User user,
- ) async {
- final actionResult = await showActionSheet(
- context: context,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.critical,
- isInAlert: true,
- shouldStickToDarkTheme: true,
- buttonAction: ButtonAction.first,
- shouldSurfaceExecutionStates: true,
- labelText: context.strings.yesRemove,
- onTap: () async {
- final newSharees = await CollectionsService.instance.unshare(
- collection.id,
- user.email,
- );
- collection.updateSharees(newSharees);
- },
- ),
- ButtonWidget(
- buttonType: ButtonType.secondary,
- buttonAction: ButtonAction.cancel,
- isInAlert: true,
- shouldStickToDarkTheme: true,
- labelText: context.strings.cancel,
- ),
- ],
- title: context.strings.removeWithQuestionMark,
- body: context.strings.removeAlbumParticipantBody(
- userEmail: resolveDisplayName(user),
- ),
- );
- if (actionResult?.action != null) {
- if (actionResult!.action == ButtonAction.error) {
- if (!context.mounted) return false;
- await showGenericErrorDialog(
- context: context,
- error: actionResult.exception,
- );
- }
- return actionResult.action == ButtonAction.first;
- }
- return false;
- }
-
- Future<bool> doesEmailHaveAccount(
- BuildContext context,
- String email, {
- bool showProgress = false,
- }) async {
- ProgressDialog? dialog;
- String? publicKey;
- if (showProgress) {
- dialog = createProgressDialog(
- context,
- context.strings.sharing,
- isDismissible: true,
- );
- await dialog.show();
- }
- try {
- publicKey = await UserService.instance.getPublicKey(email);
- } catch (e) {
- await dialog?.hide();
- logger.severe("Failed to get public key", e);
- if (!context.mounted) return false;
- await showGenericErrorDialog(context: context, error: e);
- return false;
- }
- if (publicKey == null || publicKey == '') {
- // todo: neeraj replace this as per the design where a new screen
- // is used for error. Do this change along with handling of network errors
- if (!context.mounted) return false;
- await showInviteDialog(context, email);
- return false;
- } else {
- return true;
- }
- }
-
- Future<Set<String>> addEmailsToCollections(
- BuildContext context,
++ Future<AddEmailToCollectionResult> addEmailsToCollections(
+ List<Collection> collections,
+ Set<String> emails,
+ CollectionParticipantRole role,
+ ) async {
- final validEmails = <String>{};
+ final ownEmail = Configuration.instance.getEmail()?.trim().toLowerCase();
+ for (final email in emails) {
- if (!context.mounted) return {};
+ if (!isValidEmail(email)) {
- await showErrorDialog(
- context,
- context.strings.invalidEmailAddress,
- context.strings.enterValidEmail,
++ return AddEmailToCollectionResult.failure(
++ failure: AddEmailToCollectionFailure.invalidEmail,
++ email: email,
+ );
- } else if (email == ownEmail) {
- await showErrorDialog(
- context,
- context.strings.oops,
- context.strings.youCannotShareWithYourself,
++ }
++ if (email == ownEmail) {
++ return AddEmailToCollectionResult.failure(
++ failure: AddEmailToCollectionFailure.currentUser,
++ email: email,
+ );
- } else {
- validEmails.add(email);
+ }
+ }
+
- final publicKeys = <String, String>{};
+ try {
- final keys = await UserService.instance.getPublicKeys(validEmails);
++ final keys = await UserService.instance.getPublicKeys(emails);
++ final publicKeys = <String, String>{};
+ for (final entry in keys.entries) {
- if (!context.mounted) return {};
+ final publicKey = entry.value;
+ if (publicKey == null || publicKey.isEmpty) {
- await showInviteDialog(context, entry.key);
- } else {
- publicKeys[entry.key] = publicKey;
++ return AddEmailToCollectionResult.failure(
++ failure: AddEmailToCollectionFailure.noAccount,
++ email: entry.key,
++ );
+ }
++ publicKeys[entry.key] = publicKey;
+ }
- } catch (e) {
- logger.severe("Failed to get public keys", e);
- if (context.mounted) {
- await showGenericErrorDialog(context: context, error: e);
- }
- return {};
- }
- if (publicKeys.isEmpty) return {};
-
- try {
+ for (final collection in collections) {
- if (!context.mounted) return {};
++ final collectionPublicKeys = {
++ for (final entry in publicKeys.entries)
++ if (collectionNeedsShare(collection, entry.key))
++ entry.key: entry.value,
++ };
++ if (collectionPublicKeys.isEmpty) continue;
+ final sharees = await collectionsService.shareBatch(
+ collection.id,
- publicKeys,
++ collectionPublicKeys,
+ role,
+ );
+ collection.updateSharees(sharees);
+ }
- return publicKeys.keys.toSet();
++ return const AddEmailToCollectionResult.success();
+ } catch (e) {
- if (!context.mounted) return {};
+ if (e is UnexpectedApiResponseException &&
+ e.response?.statusCode == 404) {
- final sharedEmails = <String>{};
- for (final email in publicKeys.keys) {
- var result = false;
- for (final collection in collections) {
- if (!context.mounted) return sharedEmails;
- result = await addEmailToCollection(
- context,
- collection,
- email,
- role,
- );
++ AddEmailToCollectionResult? firstFailure;
++ for (final collection in collections) {
++ for (final email in emails) {
++ if (!collectionNeedsShare(collection, email)) continue;
++ final result = await addEmailToCollection(collection, email, role);
++ if (!result.succeeded) firstFailure ??= result;
+ }
- if (result) sharedEmails.add(email);
+ }
- return sharedEmails;
++ return firstFailure ?? const AddEmailToCollectionResult.success();
+ }
- if (e is SharingNotPermittedForFreeAccountsError) {
- await _showUnSupportedAlert(context);
- } else {
- logger.severe("Failed to share collection", e);
- await showGenericErrorDialog(context: context, error: e);
- }
- return {};
++ logger.severe("Failed to share collections", e);
++ return AddEmailToCollectionResult.failure(
++ failure: e is SharingNotPermittedForFreeAccountsError
++ ? AddEmailToCollectionFailure.sharingNotPermitted
++ : AddEmailToCollectionFailure.other,
++ email: emails.first,
++ error: e,
++ );
+ }
+ }
+
- Future<bool> addEmailToCollection(
- BuildContext context,
+ Future<AddEmailToCollectionResult> addEmailToCollection(
Collection collection,
String email,
- CollectionParticipantRole role, {
- bool showProgress = false,
- }) async {
+ CollectionParticipantRole role,
+ ) async {
if (!isValidEmail(email)) {
- await showErrorDialog(
- context,
- context.strings.invalidEmailAddress,
- context.strings.enterValidEmail,
+ return AddEmailToCollectionResult.failure(
+ failure: AddEmailToCollectionFailure.invalidEmail,
+ email: email,
);
- return false;
} else if (email.trim() == Configuration.instance.getEmail()) {
- await showErrorDialog(
- context,
- context.strings.oops,
- context.strings.youCannotShareWithYourself,
+ return AddEmailToCollectionResult.failure(
+ failure: AddEmailToCollectionFailure.currentUser,
+ email: email,
);
- return false;
}
-
- ProgressDialog? dialog;
String? publicKey;
- if (showProgress) {
- dialog = createProgressDialog(
- context,
- context.strings.sharing,
- isDismissible: true,
- );
- await dialog.show();
- }
-
try {
publicKey = await UserService.instance.getPublicKey(email);
} catch (e) {
- await dialog?.hide();
logger.severe("Failed to get public key", e);
- if (!context.mounted) return false;
- await showGenericErrorDialog(context: context, error: e);
- return false;
+ return AddEmailToCollectionResult.failure(
+ failure: AddEmailToCollectionFailure.other,
+ email: email,
+ error: e,
+ );
}
if (publicKey == null || publicKey == '') {
- // todo: neeraj replace this as per the design where a new screen
- // is used for error. Do this change along with handling of network errors
- if (!context.mounted) return false;
- await showDialogWidget(
- context: context,
- title: context.strings.inviteToEnte,
- icon: Icons.info_outline,
- body: context.strings.emailNoEnteAccountPhotos(email: email),
- isDismissible: true,
- buttons: [
- ButtonWidget(
- buttonType: ButtonType.neutral,
- icon: Icons.adaptive.share,
- labelText: context.strings.sendInvite,
- isInAlert: true,
- onTap: () async {
- unawaited(
- shareText(context.strings.shareTextRecommendUsingEnteForPhotos),
- );
- },
- ),
- ],
+ return AddEmailToCollectionResult.failure(
+ failure: AddEmailToCollectionFailure.noAccount,
+ email: email,
);
- return false;
- } else {
- try {
- final newSharees = await collectionsService.share(
- collection.id,
- email,
- publicKey,
- role,
+ }
+ try {
- final newSharees = await CollectionsService.instance.share(
++ final newSharees = await collectionsService.share(
+ collection.id,
+ email,
+ publicKey,
+ role,
+ );
+ collection.updateSharees(newSharees);
+ return const AddEmailToCollectionResult.success();
+ } catch (e) {
+ if (e is SharingNotPermittedForFreeAccountsError) {
+ return AddEmailToCollectionResult.failure(
+ failure: AddEmailToCollectionFailure.sharingNotPermitted,
+ email: email,
+ error: e,
);
- await dialog?.hide();
- collection.updateSharees(newSharees);
- return true;
- } catch (e) {
- await dialog?.hide();
- if (e is SharingNotPermittedForFreeAccountsError) {
- if (!context.mounted) return false;
- await _showUnSupportedAlert(context);
- } else {
- logger.severe("failed to share collection", e);
- if (!context.mounted) return false;
- await showGenericErrorDialog(context: context, error: e);
- }
- return false;
}
+ logger.severe("failed to share collection", e);
+ return AddEmailToCollectionResult.failure(
+ failure: AddEmailToCollectionFailure.other,
+ email: email,
+ error: e,
+ );
+ }
+ }
+
+ Future<void> showAddEmailToCollectionFailure(
+ BuildContext context,
+ AddEmailToCollectionResult result,
+ ) async {
+ switch (result.failure) {
+ case AddEmailToCollectionFailure.invalidEmail:
+ await showErrorDialog(
+ context,
+ context.strings.invalidEmailAddress,
+ context.strings.enterValidEmail,
+ );
+ case AddEmailToCollectionFailure.currentUser:
+ await showErrorDialog(
+ context,
+ context.strings.oops,
+ context.strings.youCannotShareWithYourself,
+ );
+ case AddEmailToCollectionFailure.noAccount:
+ await showBottomSheetComponent<void>(
+ context: context,
+ builder: (sheetContext) => BottomSheetComponent(
+ title: context.strings.inviteToEnte,
+ message: context.strings.emailNoEnteAccountPhotos(
+ email: result.email,
+ ),
+ illustration: Image.asset("assets/warning-grey.png"),
+ closeTooltip: context.strings.close,
+ actions: [
+ ButtonComponent(
+ label: context.strings.sendInvite,
+ variant: ButtonComponentVariant.neutral,
+ leading: Icon(Icons.adaptive.share),
+ shouldSurfaceExecutionStates: false,
+ onTap: () {
+ Navigator.of(sheetContext).pop();
+ unawaited(
+ shareText(
+ context.strings.shareTextRecommendUsingEnteForPhotos,
+ ),
+ );
+ },
+ ),
+ ],
+ ),
+ );
+ case AddEmailToCollectionFailure.sharingNotPermitted:
+ await _showUnSupportedAlert(context);
+ case AddEmailToCollectionFailure.other:
+ await showGenericErrorDialog(context: context, error: result.error);
+ case null:
+ return;
}
}
diff --cc mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart
index 0000000000,168e79c0b7..f1d8d1c3b4
mode 000000,100644..100644
--- a/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart
+++ b/mobile/apps/photos/lib/ui/sharing/add_people_sheet.dart
@@@ -1,0 -1,679 +1,654 @@@
+ import "dart:math" as math;
+
+ import "package:collection/collection.dart";
+ import "package:email_validator/email_validator.dart";
+ import "package:ente_components/ente_components.dart";
+ import "package:ente_pure_utils/ente_pure_utils.dart";
+ import "package:ente_strings/ente_strings.dart";
+ import "package:flutter/material.dart";
+ import "package:hugeicons/hugeicons.dart";
+ import "package:photos/core/configuration.dart";
+ import "package:photos/models/api/collection/user.dart";
+ import "package:photos/models/collection/collection.dart";
+ import "package:photos/services/account/user_service.dart";
+ import "package:photos/services/collections_service.dart";
+ import "package:photos/services/contacts/contact_identity_resolver.dart";
+ import "package:photos/ui/actions/collection/collection_sharing_actions.dart";
+ import "package:photos/ui/notification/toast.dart";
+ import "package:photos/ui/sharing/choose_access_sheet.dart";
+ import "package:photos/ui/sharing/manage_links_widget.dart";
+ import "package:photos/ui/sharing/user_avator_widget.dart";
+ import "package:photos/ui/sharing/verify_identity_dialog.dart";
+ import "package:photos/ui/sharing/widgets/selected_person_chip.dart";
+ import "package:photos/ui/sharing/widgets/sharing_progress_sheet.dart";
+ import "package:photos/ui/sharing/widgets/sharing_role.dart";
+ import "package:photos/utils/dialog_util.dart";
+ import "package:photos/utils/share_util.dart";
+
+ Future<bool> showAddPeopleSheet(
+ BuildContext context,
+ List<Collection> collections,
+ ) async {
+ if (collections.isEmpty) {
+ return false;
+ }
+ final selected = <UserSuggestion>[];
+ late CollectionParticipantRole role;
+ while (true) {
+ final shouldContinue = await showBottomSheetComponent<bool>(
+ context: context,
+ builder: (sheetContext) =>
+ _AddPeopleSheet(collections: collections, selected: selected),
+ );
+ if (shouldContinue != true || !context.mounted) {
+ return false;
+ }
+ final selectedRole = await showChooseAccessSheet(
+ context,
+ selected: selected,
+ initialRole: CollectionParticipantRole.viewer,
+ );
+ if (!context.mounted) {
+ return false;
+ }
+ if (selectedRole == null) {
+ continue;
+ }
+ role = selectedRole;
+ break;
+ }
+ final actions = CollectionActions(CollectionsService.instance);
+ AddEmailToCollectionResult? failure;
+ final success = await showSharingProgressSheet(
+ context,
+ task: () async {
- failure = await _shareSelected(
- collections: collections,
- selected: selected,
- role: role,
- actions: actions,
++ final result = await actions.addEmailsToCollections(
++ collections,
++ selected.map((person) => normalizedSharingEmail(person.email)).toSet(),
++ role,
+ );
- return failure == null;
++ if (!result.succeeded) failure = result;
++ return result.succeeded;
+ },
+ );
+ if (!success && failure != null && context.mounted) {
+ await actions.showAddEmailToCollectionFailure(context, failure!);
+ }
+ return success;
+ }
+
-Future<AddEmailToCollectionResult?> _shareSelected({
- required List<Collection> collections,
- required List<UserSuggestion> selected,
- required CollectionParticipantRole role,
- required CollectionActions actions,
-}) async {
- AddEmailToCollectionResult? firstFailure;
- for (final collection in collections) {
- for (final suggestion in selected) {
- if (!collectionNeedsShare(collection, suggestion.email)) {
- continue;
- }
- final result = await actions.addEmailToCollection(
- collection,
- suggestion.email,
- role,
- );
- if (!result.succeeded) {
- firstFailure ??= result;
- }
- }
- }
- return firstFailure;
-}
-
+ bool _hasActiveLink(Collection collection) {
+ final url = collection.publicURLs.firstOrNull;
+ return url != null && !url.isExpired;
+ }
+
+ bool _canSharePublicLink(Collection collection, int currentUserID) {
+ if (_hasActiveLink(collection)) {
+ return true;
+ }
+ return collection.isOwner(currentUserID);
+ }
+
+ class _AddPeopleSheet extends StatefulWidget {
+ const _AddPeopleSheet({required this.collections, required this.selected});
+
+ final List<Collection> collections;
+ final List<UserSuggestion> selected;
+
+ @override
+ State<_AddPeopleSheet> createState() => _AddPeopleSheetState();
+ }
+
+ class _AddPeopleSheetState extends State<_AddPeopleSheet> {
+ final _textController = TextEditingController();
+ final _focusNode = FocusNode();
+ final _selectedPeopleScrollController = ScrollController();
+ final _contactsScrollController = ScrollController();
+ final _shareLinkKey = GlobalKey();
+ late final List<UserSuggestion> _contacts;
+ bool _emailIsValid = false;
+ bool _emailHasNoAccount = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _contacts = UserService.instance.getRelevantContacts().where((suggestion) {
+ return widget.collections.any(
+ (collection) => collectionNeedsShare(collection, suggestion.email),
+ );
+ }).toList()..sort((a, b) => a.email.compareTo(b.email));
+ }
+
+ @override
+ void dispose() {
+ _textController.dispose();
+ _focusNode.dispose();
+ _selectedPeopleScrollController.dispose();
+ _contactsScrollController.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final selectedEmails = {
+ for (final suggestion in widget.selected)
+ normalizedSharingEmail(suggestion.email),
+ };
+ final availableContacts = _contacts
+ .where(
+ (contact) =>
+ !selectedEmails.contains(normalizedSharingEmail(contact.email)),
+ )
+ .toList();
+ final keyboardVisible = MediaQuery.viewInsetsOf(context).bottom > 0;
+
+ return ConstrainedBox(
+ constraints: BoxConstraints(
+ maxHeight: MediaQuery.sizeOf(context).height * 0.95,
+ ),
+ child: BottomSheetComponent(
+ title: context.strings.addPeople,
+ isKeyboardAware: true,
+ content: Flexible(
+ fit: FlexFit.loose,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SelectedRecipientChips(
+ suggestions: widget.selected,
+ scrollController: _selectedPeopleScrollController,
+ onRemove: _toggleSuggestion,
+ onLongPress: (suggestion) => showVerifyIdentitySheet(
+ context,
+ self: false,
+ email: suggestion.email,
+ ),
+ ),
+ _EmailField(
+ controller: _textController,
+ focusNode: _focusNode,
+ emailIsValid: _emailIsValid,
+ emailHasNoAccount: _emailHasNoAccount,
+ shareKey: _shareLinkKey,
+ onChanged: (value) {
+ setState(() {
+ _emailIsValid = EmailValidator.validate(value.trim());
+ _emailHasNoAccount = false;
+ });
+ },
+ onSubmit: _tryAddTypedEmail,
+ onShareLink: _sharePublicLink,
+ ),
+ if (!_emailHasNoAccount && availableContacts.isNotEmpty) ...[
+ const SizedBox(height: Spacing.xl),
+ _ContactSuggestions(
+ contacts: availableContacts,
+ scrollController: _contactsScrollController,
+ onToggle: _toggleSuggestion,
+ ),
+ ],
+ ],
+ ),
+ ),
+ actions: keyboardVisible && !_emailHasNoAccount
+ ? const []
+ : [
+ ButtonComponent(
+ label: context.strings.continueLabel,
+ variant: ButtonComponentVariant.primary,
+ size: ButtonComponentSize.large,
+ isDisabled: widget.selected.isEmpty,
+ onTap: () => Navigator.of(context).pop(true),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Future<void> _tryAddTypedEmail() async {
+ final email = normalizedSharingEmail(_textController.text);
+ final currentEmail = Configuration.instance.getEmail();
+ if (!EmailValidator.validate(email)) {
+ return;
+ }
+ if (currentEmail != null && email == normalizedSharingEmail(currentEmail)) {
+ await showErrorDialog(
+ context,
+ context.strings.oops,
+ context.strings.youCannotShareWithYourself,
+ );
+ return;
+ }
+ if (_isSelected(email)) {
+ _clearEmail();
+ return;
+ }
+ if (!widget.collections.any(
+ (collection) => collectionNeedsShare(collection, email),
+ )) {
+ showShortToast(context, context.strings.personAlreadyHasAccess);
+ _clearEmail();
+ return;
+ }
+ setState(() => _emailHasNoAccount = false);
+ try {
+ final publicKey = await UserService.instance.getPublicKey(email);
+ if (!mounted) {
+ return;
+ }
+ if (normalizedSharingEmail(_textController.text) != email ||
+ _isSelected(email)) {
+ return;
+ }
+ if (publicKey == null || publicKey.isEmpty) {
+ if (widget.collections.length != 1 ||
+ !_canSharePublicLink(
+ widget.collections.first,
+ Configuration.instance.getUserID()!,
+ )) {
+ await CollectionActions(
+ CollectionsService.instance,
+ ).showAddEmailToCollectionFailure(
+ context,
+ AddEmailToCollectionResult.failure(
+ failure: AddEmailToCollectionFailure.noAccount,
+ email: email,
+ ),
+ );
+ return;
+ }
+ setState(() => _emailHasNoAccount = true);
+ return;
+ }
+ final suggestion = _contacts.firstWhereOrNull(
+ (contact) => normalizedSharingEmail(contact.email) == email,
+ );
+ setState(() {
+ widget.selected.add(suggestion ?? UserSuggestion(email));
+ });
+ _clearEmail();
+ _scrollSelectedPeopleToEnd();
+ } catch (error) {
+ if (!mounted ||
+ normalizedSharingEmail(_textController.text) != email ||
+ _isSelected(email)) {
+ return;
+ }
+ setState(() => _emailHasNoAccount = false);
+ await showGenericErrorDialog(context: context, error: error);
+ }
+ }
+
+ void _toggleSuggestion(UserSuggestion suggestion) {
+ _focusNode.unfocus();
+ var added = false;
+ setState(() {
+ final index = widget.selected.indexWhere(
+ (selected) =>
+ normalizedSharingEmail(selected.email) ==
+ normalizedSharingEmail(suggestion.email),
+ );
+ if (index == -1) {
+ widget.selected.add(suggestion);
+ added = true;
+ } else {
+ widget.selected.removeAt(index);
+ }
+ });
+ if (added) {
+ _scrollSelectedPeopleToEnd();
+ }
+ }
+
+ void _scrollSelectedPeopleToEnd() {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (!mounted || !_selectedPeopleScrollController.hasClients) {
+ return;
+ }
+ _selectedPeopleScrollController.animateTo(
+ _selectedPeopleScrollController.position.maxScrollExtent,
+ duration: Motion.quick,
+ curve: Curves.easeOutCubic,
+ );
+ });
+ }
+
+ bool _isSelected(String email) {
+ return widget.selected.any(
+ (selected) =>
+ normalizedSharingEmail(selected.email) ==
+ normalizedSharingEmail(email),
+ );
+ }
+
+ void _clearEmail() {
+ _textController.clear();
+ _focusNode.unfocus();
+ setState(() {
+ _emailIsValid = false;
+ _emailHasNoAccount = false;
+ });
+ }
+
+ Future<void> _sharePublicLink() async {
+ if (widget.collections.length != 1) {
+ return;
+ }
+ final collection = widget.collections.first;
+ final currentUserID = Configuration.instance.getUserID()!;
+ if (!_canSharePublicLink(collection, currentUserID)) {
+ return;
+ }
+ if (collection.hasLink && !_hasActiveLink(collection)) {
+ await routeToPage(
+ context,
+ ManageSharedLinkWidget(collection: collection),
+ );
+ if (mounted) {
+ setState(() {});
+ }
+ return;
+ }
+ if (!_hasActiveLink(collection)) {
+ final enabled = await CollectionActions(
+ CollectionsService.instance,
+ ).enableUrl(context, collection);
+ if (!enabled || !mounted || !_hasActiveLink(collection)) {
+ return;
+ }
+ setState(() {});
+ }
+ final url = CollectionsService.instance.getPublicUrl(collection);
+ await shareAlbumLink(
+ context,
+ url,
+ _shareLinkKey,
+ albumName: collection.displayName,
+ albumDescription: collection.displayDescription,
+ );
+ }
+ }
+
+ class _EmailField extends StatelessWidget {
+ const _EmailField({
+ required this.controller,
+ required this.focusNode,
+ required this.emailIsValid,
+ required this.emailHasNoAccount,
+ required this.shareKey,
+ required this.onChanged,
+ required this.onSubmit,
+ required this.onShareLink,
+ });
+
+ final TextEditingController controller;
+ final FocusNode focusNode;
+ final bool emailIsValid;
+ final bool emailHasNoAccount;
+ final GlobalKey shareKey;
+ final ValueChanged<String> onChanged;
+ final Future<void> Function() onSubmit;
+ final Future<void> Function() onShareLink;
+
+ @override
+ Widget build(BuildContext context) {
+ final messageStyle = TextStyles.mini.copyWith(
+ color: context.componentColors.textLight,
+ );
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Expanded(
+ child: TextInputComponent(
+ controller: controller,
+ focusNode: focusNode,
+ hintText: context.strings.enterAnEmailAddress,
+ keyboardType: TextInputType.emailAddress,
+ textInputAction: TextInputAction.done,
+ autofillHints: const [AutofillHints.email],
+ autocorrect: false,
+ enableSuggestions: false,
+ isClearable: !emailHasNoAccount,
+ suffix: emailHasNoAccount
+ ? HugeIcon(
+ icon: HugeIcons.strokeRoundedAlert02,
+ size: IconSizes.small,
+ color: context.componentColors.textLight,
+ )
+ : null,
+ onChanged: onChanged,
+ onSubmit: (_) => onSubmit(),
+ ),
+ ),
+ if (!emailHasNoAccount) ...[
+ const SizedBox(width: Spacing.sm),
+ Padding(
+ padding: const EdgeInsets.only(top: Spacing.sm),
+ child: IconButtonComponent(
+ variant: IconButtonComponentVariant.green,
+ shouldSurfaceExecutionStates: false,
+ tooltip: context.strings.add,
+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedMailAdd01),
+ onTap: emailIsValid ? onSubmit : null,
+ ),
+ ),
+ ],
+ ],
+ ),
+ if (emailHasNoAccount) ...[
+ const SizedBox(height: Spacing.sm),
+ SizedBox(
+ width: double.infinity,
+ child: Wrap(
+ alignment: WrapAlignment.center,
+ children: [
+ Text(
+ '${context.strings.noEnteAccountWithThisEmail} ',
+ style: messageStyle,
+ ),
+ InkWell(
+ key: shareKey,
+ onTap: () => onShareLink(),
+ child: Text(
+ context.strings.shareALinkInline,
+ style: messageStyle.copyWith(
+ color: context.componentColors.textBase,
+ decoration: TextDecoration.underline,
+ decorationColor: context.componentColors.textBase,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+ }
+
+ class _ContactSuggestions extends StatelessWidget {
+ const _ContactSuggestions({
+ required this.contacts,
+ required this.scrollController,
+ required this.onToggle,
+ });
+
+ static double rowExtent(BuildContext context) {
+ const textStyle = TextStyles.mini;
+ final lineExtent =
+ MediaQuery.textScalerOf(context).scale(textStyle.fontSize!) *
+ textStyle.height!;
+ return math.max(
+ 104.0,
+ getAvatarSize(AvatarType.huge) + Spacing.sm + lineExtent * 2,
+ );
+ }
+
+ final List<UserSuggestion> contacts;
+ final ScrollController scrollController;
+ final ValueChanged<UserSuggestion> onToggle;
+
+ @override
+ Widget build(BuildContext context) {
+ final rowExtent = _ContactSuggestions.rowExtent(context);
+ final avatarSize = getAvatarSize(AvatarType.huge);
+ const arrowSize = 36.0;
+ final itemWidth = avatarSize + Spacing.lg;
+ final scrollStep = itemWidth + Spacing.lg;
+
+ return SizedBox(
+ height: rowExtent,
+ child: Stack(
+ children: [
+ Positioned.fill(
+ child: ShaderMask(
+ blendMode: BlendMode.dstIn,
+ shaderCallback: (bounds) {
+ final fadeStop = (arrowSize / bounds.width).clamp(0.0, 0.5);
+ return LinearGradient(
+ colors: const [
+ Colors.transparent,
+ Colors.black,
+ Colors.black,
+ Colors.transparent,
+ ],
+ stops: [0, fadeStop, 1 - fadeStop, 1],
+ ).createShader(bounds);
+ },
+ child: ListView.separated(
+ key: const ValueKey("contact-suggestions-scroll"),
+ controller: scrollController,
+ primary: false,
+ scrollDirection: Axis.horizontal,
+ padding: const EdgeInsets.symmetric(horizontal: arrowSize),
+ itemCount: contacts.length,
+ itemBuilder: (context, index) {
+ final contact = contacts[index];
+ return SizedBox(
+ width: itemWidth,
+ child: _ContactSuggestion(
+ key: ValueKey(
+ "contact-${contact.email.trim().toLowerCase()}",
+ ),
+ suggestion: contact,
+ onTap: () => onToggle(contact),
+ onLongPress: () => showVerifyIdentitySheet(
+ context,
+ self: false,
+ email: contact.email,
+ ),
+ ),
+ );
+ },
+ separatorBuilder: (_, _) => const SizedBox(width: Spacing.lg),
+ ),
+ ),
+ ),
+ PositionedDirectional(
+ start: 0,
+ top: 0,
+ child: SizedBox(
+ height: avatarSize,
+ child: Center(
+ child: IconButtonComponent(
+ size: arrowSize,
+ variant: IconButtonComponentVariant.primary,
+ shouldSurfaceExecutionStates: false,
+ tooltip: context.strings.previous,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedArrowLeft01,
+ ),
+ onTap: () => _scroll(context, -scrollStep),
+ ),
+ ),
+ ),
+ ),
+ PositionedDirectional(
+ end: 0,
+ top: 0,
+ child: SizedBox(
+ height: avatarSize,
+ child: Center(
+ child: IconButtonComponent(
+ size: arrowSize,
+ variant: IconButtonComponentVariant.primary,
+ shouldSurfaceExecutionStates: false,
+ tooltip: context.strings.next,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedArrowRight01,
+ ),
+ onTap: () => _scroll(context, scrollStep),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Future<void> _scroll(BuildContext context, double offset) async {
+ if (!scrollController.hasClients) {
+ return;
+ }
+ final position = scrollController.position;
+ final target = (position.pixels + offset)
+ .clamp(position.minScrollExtent, position.maxScrollExtent)
+ .toDouble();
+ if (MediaQuery.disableAnimationsOf(context)) {
+ scrollController.jumpTo(target);
+ return;
+ }
+ await scrollController.animateTo(
+ target,
+ duration: Motion.slow,
+ curve: Curves.easeOutCubic,
+ );
+ }
+ }
+
+ class _ContactSuggestion extends StatelessWidget {
+ const _ContactSuggestion({
+ super.key,
+ required this.suggestion,
+ required this.onTap,
+ required this.onLongPress,
+ });
+
+ final UserSuggestion suggestion;
+ final VoidCallback onTap;
+ final VoidCallback onLongPress;
+
+ @override
+ Widget build(BuildContext context) {
+ final label = resolveSuggestionDisplayName(suggestion);
+ return InkWell(
+ key: ValueKey(
+ "contact-suggestion-${suggestion.email.trim().toLowerCase()}",
+ ),
+ borderRadius: BorderRadius.circular(Radii.button),
+ onTap: onTap,
+ onLongPress: onLongPress,
+ child: Column(
+ children: [
+ UserAvatarWidget.suggestion(suggestion, type: AvatarType.huge),
+ const SizedBox(height: Spacing.sm),
+ Text(
+ label,
+ textAlign: TextAlign.center,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyles.mini.copyWith(
+ color: context.componentColors.textLight,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+ }