π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Delete test file
Aman Rajef45bd1a8480
diff --git a/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart b/mobile/apps/photos/lib/ui/sharing/add_participant_page.dartdeleted file mode 100644index 5a1a7f8878..0000000000--- a/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart+++ /dev/null@@ -1,446 +0,0 @@-import 'package:email_validator/email_validator.dart';-import 'package:ente_components/ente_components.dart';-import "package:ente_strings/ente_strings.dart";-import 'package:flutter/material.dart';-import 'package:hugeicons/hugeicons.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/share_components.dart';-import 'package:photos/ui/sharing/user_avator_widget.dart';-import "package:photos/ui/sharing/verify_identity_dialog.dart";--enum ActionTypesToShow { addViewer, addCollaborator, addAdmin }--class AddParticipantPage extends StatefulWidget {- final List<ActionTypesToShow> actionTypesToShow;- final List<Collection> collections;-- AddParticipantPage(this.collections, this.actionTypesToShow, {super.key})- : assert(actionTypesToShow.isNotEmpty, 'actionTypesToShow cannot be empty');-- @override- State<StatefulWidget> createState() => _AddParticipantPage();-}--class _AddParticipantPage extends State<AddParticipantPage> {- final _selectedEmails = <String>{};- String _newEmail = '';- bool _emailIsValid = false;- bool isKeypadOpen = false;- late CollectionActions collectionActions;- late List<UserSuggestion> _suggestedUsers;-- final textFieldFocusNode = FocusNode();- final _textController = TextEditingController();-- @override- void initState() {- super.initState();- collectionActions = CollectionActions(CollectionsService.instance);- _suggestedUsers = _getSuggestedUser();- }-- @override- void dispose() {- _textController.dispose();- textFieldFocusNode.dispose();- super.dispose();- }-- @override- Widget build(BuildContext context) {- final filterSuggestedUsers = _suggestedUsers- .where(- (element) => matchesResolvedSuggestionQuery(- element,- _textController.text.trim().toLowerCase(),- ),- )- .toList();- isKeypadOpen = MediaQuery.viewInsetsOf(context).bottom > 100;-- return ShareScaffold(- title: _getTitle(),- subtitle: _getSubtitle(),- resizeToAvoidBottomInset: isKeypadOpen,- footer: _bottomActionBar(),- slivers: _slivers(filterSuggestedUsers),- );- }-- List<Widget> _slivers(List<UserSuggestion> filterSuggestedUsers) {- final footerDescriptions = [- if (filterSuggestedUsers.isNotEmpty)- ShareSectionDescription(- context.strings.longPressAnEmailToVerifyEndToEndEncryption,- ),- ..._roleDescriptionWidgets(),- ];-- return [- SliverSafeArea(- top: false,- bottom: false,- sliver: SliverPadding(- padding: const EdgeInsets.symmetric(horizontal: Spacing.lg),- sliver: SliverList.list(- children: [- ShareSectionTitle(context.strings.addANewEmail),- _enterEmailField(),- if (filterSuggestedUsers.isNotEmpty) ...[- const SizedBox(height: Spacing.xxl),- ShareSectionTitle(context.strings.orPickAnExistingOne),- ],- ],- ),- ),- ),- if (filterSuggestedUsers.isNotEmpty)- SliverPadding(- padding: const EdgeInsets.symmetric(horizontal: Spacing.lg),- sliver: SliverList.builder(- itemCount: filterSuggestedUsers.length,- itemBuilder: (context, index) {- return Column(- mainAxisSize: MainAxisSize.min,- children: [- _suggestedUserItem(filterSuggestedUsers, index),- if (index < filterSuggestedUsers.length - 1)- _suggestedUserSeparator(),- ],- );- },- ),- ),- if (footerDescriptions.isNotEmpty)- SliverSafeArea(- top: false,- bottom: false,- sliver: SliverPadding(- padding: const EdgeInsets.fromLTRB(- Spacing.lg,- 0,- Spacing.lg,- Spacing.sm,- ),- sliver: SliverList.list(children: footerDescriptions),- ),- ),- ];- }-- Widget _bottomActionBar() {- final actionButtons = _actionButtons();- final bottomPadding = isKeypadOpen ? Spacing.sm : Spacing.xl;- return SafeArea(- top: false,- bottom: !isKeypadOpen,- child: Padding(- padding: EdgeInsets.fromLTRB(- Spacing.lg,- Spacing.sm,- Spacing.lg,- bottomPadding,- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- for (var index = 0; index < actionButtons.length; index++) ...[- actionButtons[index],- if (index < actionButtons.length - 1)- const SizedBox(height: Spacing.sm),- ],- ],- ),- ),- );- }-- List<Widget> _roleDescriptionWidgets() {- if (widget.actionTypesToShow.length == 1) {- return const [];- }-- return [- if (widget.actionTypesToShow.contains(ActionTypesToShow.addCollaborator))- ShareSectionDescription(- context.strings.collaboratorsCanAddPhotosAndVideosToTheSharedAlbum,- ),- if (widget.actionTypesToShow.contains(ActionTypesToShow.addAdmin))- ShareSectionDescription(- context.strings.adminsCanManagePhotosAndParticipants,- ),- ];- }-- Widget _suggestedUserItem(List<UserSuggestion> users, int index) {- final currentUser = users[index];- final borderRadius = MenuGroupComponent.itemBorderRadius(- index: index,- itemCount: users.length,- borderRadius: BorderRadius.circular(Radii.button),- );- return ClipRRect(- borderRadius: borderRadius,- child: DecoratedBox(- decoration: BoxDecoration(- color: context.componentColors.fillLight,- borderRadius: borderRadius,- ),- child: ShareMenuItem(- key: ValueKey(- '${currentUser.email}-${resolveSuggestionDisplayName(currentUser)}',- ),- title: resolveSuggestionDisplayName(currentUser),- titleColor: context.componentColors.textLight,- leading: UserAvatarWidget.suggestion(- currentUser,- type: AvatarType.medium,- ),- trailing: _selectedEmails.contains(currentUser.email)- ? shareCheck(context)- : null,- onTap: () async {- textFieldFocusNode.unfocus();- if (_selectedEmails.contains(currentUser.email)) {- _selectedEmails.remove(currentUser.email);- } else {- _selectedEmails.add(currentUser.email);- }- setState(() => {});- },- onLongPress: () async {- await showVerifyIdentitySheet(- context,- self: false,- email: currentUser.email,- );- },- ),- ),- );- }-- Widget _suggestedUserSeparator() {- return ColoredBox(- color: context.componentColors.fillLight,- child: const DividerComponent(),- );- }-- List<Widget> _actionButtons() {- final widgets = <Widget>[];- if (widget.actionTypesToShow.contains(ActionTypesToShow.addCollaborator)) {- widgets.add(- ButtonComponent(- variant:- widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)- ? ButtonComponentVariant.neutral- : ButtonComponentVariant.primary,- size: ButtonComponentSize.large,- label: context.strings.addCollaborators(- count: _selectedEmails.length,- ),- isDisabled: _selectedEmails.isEmpty,- onTap: () => _shareSelected(CollectionParticipantRole.collaborator),- ),- );- }- if (widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)) {- widgets.add(- ButtonComponent(- variant: ButtonComponentVariant.primary,- size: ButtonComponentSize.large,- label: context.strings.addViewers(count: _selectedEmails.length),- isDisabled: _selectedEmails.isEmpty,- onTap: () => _shareSelected(CollectionParticipantRole.viewer),- ),- );- }- if (widget.actionTypesToShow.contains(ActionTypesToShow.addAdmin)) {- widgets.add(- ButtonComponent(- variant: widget.actionTypesToShow.length == 1- ? ButtonComponentVariant.primary- : ButtonComponentVariant.neutral,- size: ButtonComponentSize.large,- label: context.strings.addAdmins(count: _selectedEmails.length),- isDisabled: _selectedEmails.isEmpty,- onTap: () => _shareSelected(CollectionParticipantRole.admin),- ),- );- }- return widgets;- }-- Future<void> _shareSelected(CollectionParticipantRole role) async {- final emails = _selectedEmails- .map((email) => email.trim().toLowerCase())- .toSet();- final collections = List<Collection>.of(widget.collections);- final sharedEmails = await collectionActions.addEmailsToCollections(- context,- collections,- emails,- role,- );- if (!mounted) return;- final count = sharedEmails.length;- final message = switch (role) {- CollectionParticipantRole.viewer =>- context.strings.viewersSuccessfullyAdded(count: count),- CollectionParticipantRole.collaborator =>- context.strings.collaboratorsSuccessfullyAdded(count: count),- CollectionParticipantRole.admin =>- context.strings.adminsSuccessfullyAdded(count: count),- _ => throw ArgumentError.value(role, "role"),- };- showToast(context, message);- if (count == emails.length) {- Navigator.of(context).pop(true);- }- }-- void clearFocus() {- _clearEmailField();- textFieldFocusNode.unfocus();- setState(() => {});- }-- void _clearEmailField() {- _textController.clear();- _newEmail = _textController.text;- _emailIsValid = false;- }-- Widget _enterEmailField() {- return Row(- children: [- Expanded(- child: TextInputComponent(- controller: _textController,- focusNode: textFieldFocusNode,- hintText: context.strings.enterAnEmailAddress,- isClearable: true,- shouldUnfocusOnClearOrSubmit: true,- autofillHints: const [AutofillHints.email],- autocorrect: false,- keyboardType: TextInputType.emailAddress,- onChanged: (value) {- _newEmail = value.trim();- _emailIsValid = EmailValidator.validate(_newEmail);- setState(() {});- },- ),- ),- const SizedBox(width: Spacing.sm),- IconButtonComponent(- variant: IconButtonComponentVariant.green,- tooltip: context.strings.add,- icon: const HugeIcon(icon: HugeIcons.strokeRoundedMailAdd01),- onTap: _emailIsValid ? _addNewEmail : null,- ),- ],- );- }-- Future<void> _addNewEmail() async {- if (!_emailIsValid) {- return;- }- final email = _newEmail;- final result = await collectionActions.doesEmailHaveAccount(context, email);- if (result && mounted && _newEmail == email) {- setState(() {- for (var suggestedUser in _suggestedUsers) {- if (suggestedUser.email == email) {- _selectedEmails.add(suggestedUser.email);- _clearEmailField();- textFieldFocusNode.unfocus();-- return;- }- }- _suggestedUsers.insert(0, UserSuggestion(email));- _selectedEmails.add(email);- _clearEmailField();- textFieldFocusNode.unfocus();- });- }- }-- List<UserSuggestion> _getSuggestedUser() {- final Set<String> existingEmails = {};- final collections = widget.collections;- if (collections.isEmpty) {- return [];- }- final Set<String> ownerEmails = {};-- for (final Collection collection in collections) {- for (final User u in collection.sharees) {- if (u.email.isNotEmpty) {- existingEmails.add(u.email);- }- }- final ownerEmail = collection.owner.email;- if (ownerEmail.isNotEmpty) {- ownerEmails.add(ownerEmail);- existingEmails.add(ownerEmail);- }- }-- final suggestedUsers = UserService.instance.getRelevantContacts()- ..removeWhere((element) => existingEmails.contains(element.email));-- if (_textController.text.trim().isNotEmpty) {- suggestedUsers.removeWhere(- (element) => !matchesResolvedSuggestionQuery(- element,- _textController.text.trim().toLowerCase(),- ),- );- }- suggestedUsers.removeWhere(- (element) => ownerEmails.contains(element.email),- );- suggestedUsers.sort((a, b) => a.email.compareTo(b.email));-- return suggestedUsers;- }-- String _getTitle() {- if (widget.actionTypesToShow.length > 1) {- return context.strings.addParticipants;- }- switch (widget.actionTypesToShow.first) {- case ActionTypesToShow.addViewer:- return context.strings.addViewer;- case ActionTypesToShow.addCollaborator:- return context.strings.addCollaborator;- case ActionTypesToShow.addAdmin:- return context.strings.addAdmin;- }- }-- String? _getSubtitle() {- if (widget.actionTypesToShow.length != 1) {- return null;- }- switch (widget.actionTypesToShow.first) {- case ActionTypesToShow.addCollaborator:- return context- .strings- .collaboratorsCanAddPhotosAndVideosToTheSharedAlbum;- case ActionTypesToShow.addAdmin:- return context.strings.adminsCanManagePhotosAndParticipants;- case ActionTypesToShow.addViewer:- return null;- }- }-}