π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat: Add pin/unpin support for shared incoming collections
Prateek Sunal8ad124d34dfe
diff --git a/mobile/apps/photos/lib/models/collection/collection.dart b/mobile/apps/photos/lib/models/collection/collection.dartindex 604e650ba5..dd739cfb60 100644--- a/mobile/apps/photos/lib/models/collection/collection.dart+++ b/mobile/apps/photos/lib/models/collection/collection.dart@@ -105,6 +105,10 @@ class Collection {sharedMagicMetadata.visibility == archiveVisibility;}+ bool hasShareePinned() {+ return sharedMmdVersion > 0 && (sharedMagicMetadata.order ?? 0) != 0;+ }+// hasLink returns true if there's any link attached to the collection// including expired linksbool get hasLink => publicURLs.isNotEmpty;diff --git a/mobile/apps/photos/lib/models/metadata/collection_magic.dart b/mobile/apps/photos/lib/models/metadata/collection_magic.dartindex dfa637a7bd..d0254acf6c 100644--- a/mobile/apps/photos/lib/models/metadata/collection_magic.dart+++ b/mobile/apps/photos/lib/models/metadata/collection_magic.dart@@ -107,13 +107,21 @@ class ShareeMagicMetadata {// null/false value -> no mutebool? mute;- ShareeMagicMetadata({required this.visibility, this.mute});+ /* order is used for pinned collections for sharees.+ Higher the value, higher the preference of the collection to show up first.+ */+ int? order;++ ShareeMagicMetadata({required this.visibility, this.mute, this.order});Map<String, dynamic> toJson() {final Map<String, dynamic> result = {magicKeyVisibility: visibility};if (mute != null) {result[muteKey] = mute!;}+ if (order != null) {+ result[orderKey] = order!;+ }return result;}@@ -128,6 +136,7 @@ class ShareeMagicMetadata {return ShareeMagicMetadata(visibility: map[magicKeyVisibility] ?? visibleVisibility,mute: map[muteKey],+ order: map[orderKey],);}}diff --git a/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dartindex ce74a0c9fc..fc22fac659 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart@@ -119,6 +119,35 @@ class _AlbumSelectionActionWidgetState);if (widget.sectionType == UISectionType.incomingCollections) {+ // Pin/Unpin options for incoming collections (uses sharee metadata)+ // Behind feature flag+ if (flagService.enableShareePin) {+ final hasShareePinnedAlbum = widget.selectedAlbums.albums.any(+ (album) => album.hasShareePinned(),+ );+ final hasShareeUnpinnedAlbum = widget.selectedAlbums.albums.any(+ (album) => !album.hasShareePinned(),+ );++ items.add(+ SelectionActionButton(+ labelText: "Pin",+ icon: Icons.push_pin_rounded,+ onTap: _onPinClickForSharee,+ shouldShow: hasShareeUnpinnedAlbum,+ ),+ );++ items.add(+ SelectionActionButton(+ labelText: "Unpin",+ icon: CupertinoIcons.pin_slash,+ onTap: _onUnpinClickForSharee,+ shouldShow: hasShareePinnedAlbum,+ ),+ );+ }+items.add(SelectionActionButton(labelText: AppLocalizations.of(context).leaveAlbum,@@ -247,6 +276,36 @@ class _AlbumSelectionActionWidgetStatewidget.selectedAlbums.clearAll();}+ Future<void> _onPinClickForSharee() async {+ for (final collection in widget.selectedAlbums.albums) {+ if (collection.type == CollectionType.favorites ||+ collection.hasShareePinned()) {+ continue;+ }++ await updateShareeOrder(context, collection, 1);+ }+ if (hasFavorites) {+ _showFavToast();+ }+ widget.selectedAlbums.clearAll();+ }++ Future<void> _onUnpinClickForSharee() async {+ for (final collection in widget.selectedAlbums.albums) {+ if (collection.type == CollectionType.favorites ||+ !collection.hasShareePinned()) {+ continue;+ }++ await updateShareeOrder(context, collection, 0);+ }+ if (hasFavorites) {+ _showFavToast();+ }+ widget.selectedAlbums.clearAll();+ }+Future<void> _onHideClick() async {for (final collection in widget.selectedAlbums.albums) {if (collection.type == CollectionType.favorites) {diff --git a/mobile/apps/photos/lib/utils/magic_util.dart b/mobile/apps/photos/lib/utils/magic_util.dartindex 7ac60921f2..d5ef18e509 100644--- a/mobile/apps/photos/lib/utils/magic_util.dart+++ b/mobile/apps/photos/lib/utils/magic_util.dart@@ -141,6 +141,27 @@ Future<void> updateOrder(}}+Future<void> updateShareeOrder(+ BuildContext context,+ Collection collection,+ int order,+) async {+ try {+ final Map<String, dynamic> update = {+ orderKey: order,+ };+ await CollectionsService.instance+ .updateShareeMagicMetadata(collection, update);+ Bus.instance.fire(+ CollectionMetaEvent(collection.id, CollectionMetaEventType.orderChanged),+ );+ } catch (e, s) {+ _logger.severe("failed to update sharee order", e, s);+ showShortToast(context, AppLocalizations.of(context).somethingWentWrong);+ rethrow;+ }+}+// changeCoverPhoto is used to change cover photo for a collection. To reset to// default cover photo, pass uploadedFileID as 0Future<void> changeCoverPhoto(diff --git a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dartindex 3035ead5b1..3ba372f02b 100644--- a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart+++ b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart@@ -95,6 +95,8 @@ class FlagService {bool get manualTagFileToPerson => internalUser && hasGrantedMLConsent;+ bool get enableShareePin => internalUser;+Future<void> tryRefreshFlags() async {try {await _fetch();diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsxindex cf6d2d5e27..10e9094909 100644--- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx+++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx@@ -46,6 +46,7 @@ import {updateCollectionOrder,updateCollectionSortOrder,updateCollectionVisibility,+ updateShareeCollectionOrder,} from "ente-new/photos/services/collection";import {PseudoCollectionID,@@ -152,7 +153,7 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({}) => {const { showMiniDialog, onGenericError } = useBaseContext();const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();- const { mapEnabled } = useSettingsSnapshot();+ const { mapEnabled, isShareePinEnabled } = useSettingsSnapshot();const overflowMenuIconRef = useRef<SVGSVGElement | null>(null);const { show: showSortOrderMenu, props: sortOrderMenuVisibilityProps } =@@ -347,6 +348,14 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({updateCollectionOrder(activeCollection, CollectionOrder.default),);+ const pinSharedAlbum = wrap(() =>+ updateShareeCollectionOrder(activeCollection, CollectionOrder.pinned),+ );++ const unpinSharedAlbum = wrap(() =>+ updateShareeCollectionOrder(activeCollection, CollectionOrder.default),+ );+const hideAlbum = wrap(async () => {await updateCollectionVisibility(activeCollection,@@ -449,6 +458,28 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({case "sharedIncoming":menuOptions = [+ // Pin/Unpin for shared incoming collections (behind feature flag)+ ...(isShareePinEnabled+ ? [+ collectionSummary.attributes.has("shareePinned") ? (+ <OverflowMenuOption+ key="unpin"+ onClick={unpinSharedAlbum}+ startIcon={<PushPinOutlinedIcon />}+ >+ {t("unpin_album")}+ </OverflowMenuOption>+ ) : (+ <OverflowMenuOption+ key="pin"+ onClick={pinSharedAlbum}+ startIcon={<PushPinIcon />}+ >+ {t("pin_album")}+ </OverflowMenuOption>+ ),+ ]+ : []),collectionSummary.attributes.has("archived") ? (<OverflowMenuOptionkey="unarchive"diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.tsindex c6b402600f..5d8e3d05f8 100644--- a/web/packages/media/collection.ts+++ b/web/packages/media/collection.ts@@ -721,6 +721,12 @@ export interface CollectionShareeMagicMetadataData {* Expected to be one of {@link ItemVisibility}.*/visibility?: number;+ /**+ * An override to the sort ordering used for the collection by the sharee.+ *+ * Expected to be one of {@link CollectionOrder}.+ */+ order?: number;}/**@@ -728,4 +734,5 @@ export interface CollectionShareeMagicMetadataData {*/export const CollectionShareeMagicMetadataData = z.looseObject({visibility: z.number().nullish().transform(nullToUndefined),+ order: z.number().nullish().transform(nullToUndefined),});diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex 435e661302..7327fb9e59 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -1536,6 +1536,14 @@ const createCollectionSummaries = (attributes.add("pinned");sortPriority = CollectionSummarySortPriority.pinned;}+ // Check for sharee pinned (for incoming shared collections)+ if (+ type == "sharedIncoming" &&+ collection.sharedMagicMetadata?.data.order == CollectionOrder.pinned+ ) {+ attributes.add("shareePinned");+ sortPriority = CollectionSummarySortPriority.pinned;+ }if (type == "sharedIncoming" && collectionType == "favorites") {// See: [Note: User and shared favorites] above.diff --git a/web/packages/new/photos/services/collection-summary.ts b/web/packages/new/photos/services/collection-summary.tsindex 2876e305e1..6a5f70cb18 100644--- a/web/packages/new/photos/services/collection-summary.ts+++ b/web/packages/new/photos/services/collection-summary.ts@@ -21,7 +21,8 @@ export type CollectionSummaryAttribute =| "system"| "archived"| "hideFromCollectionBar"- | "pinned";+ | "pinned"+ | "shareePinned";/*** ID of the special {@link CollectionSummary} instances that are not backed bydiff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex 734e50bdba..b04601534f 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -1036,6 +1036,22 @@ export const updateCollectionOrder = async (order: CollectionOrder,) => updateCollectionPrivateMagicMetadata(collection, { order });+/**+ * Change the order (pin/unpin) of a shared collection on remote for the sharee.+ *+ * Remote only, does not modify local state.+ *+ * This function works only for collections shared with the user (not owned).+ *+ * @param collection The shared collection whose order we want to change.+ *+ * @param order Whether on not the collection is pinned by the sharee.+ */+export const updateShareeCollectionOrder = async (+ collection: Collection,+ order: CollectionOrder,+) => updateCollectionShareeMagicMetadata(collection, { order });+/*** Change the sort order of the files with a collection on remote.*diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.tsindex 4ff936e80f..97c2c848ce 100644--- a/web/packages/new/photos/services/settings.ts+++ b/web/packages/new/photos/services/settings.ts@@ -55,6 +55,10 @@ export interface Settings {* `true` if public link surfaces should be shown to non-owners.*/isSurfacePublicLinkEnabled: boolean;+ /**+ * `true` if sharee pin feature is enabled for shared albums.+ */+ isShareePinEnabled: boolean;/*** `true` if maps are enabled.@@ -116,6 +120,7 @@ const createDefaultSettings = (): Settings => ({isInternalUser: false,isAdminRoleEnabled: false,isSurfacePublicLinkEnabled: false,+ isShareePinEnabled: false,mapEnabled: false,cfUploadProxyDisabled: false,castURL: "https://cast.ente.io",@@ -210,6 +215,7 @@ const syncSettingsSnapshotWithLocalStorage = () => {settings.isAdminRoleEnabled = (flags?.internalUser ?? false) || isDevBuild;settings.isSurfacePublicLinkEnabled =(flags?.internalUser ?? false) || isDevBuild;+ settings.isShareePinEnabled = (flags?.internalUser ?? false) || isDevBuild;settings.mapEnabled = flags?.mapEnabled || false;settings.cfUploadProxyDisabled = savedCFProxyDisabled();if (flags?.castUrl) settings.castURL = flags.castUrl;