π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(collection):fix-simultaneous-updations
Aswin Asokd9d1fedbaa04
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 55eff12782..21a8f0a408 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -116,8 +116,7 @@ import {removeFromCollection,removeFromFavoritesCollection,renameCollection,- updateCollectionCover,- updateCollectionDescription,+ updateCollectionDetails,} from "ente-new/photos/services/collection";import {haveOnlySystemCollections,@@ -1499,20 +1498,18 @@ const Page: React.FC = () => {didAttemptWrite = true;await renameCollection(activeCollection, name);}- if (+ const descriptionChanged =(activeCollection.pubMagicMetadata?.data.caption ?? ""- ).trim() != description- ) {+ ).trim() != description;+ if (descriptionChanged || coverID !== undefined) {didAttemptWrite = true;- await updateCollectionDescription(- activeCollection,- description,- );- }- if (coverID !== undefined) {- didAttemptWrite = true;- await updateCollectionCover(activeCollection, coverID);+ await updateCollectionDetails(activeCollection, {+ description: descriptionChanged+ ? description+ : undefined,+ coverID,+ });}} finally {if (didAttemptWrite) {diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex b75f151397..0bf67f791e 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -971,7 +971,7 @@ export const updateCollectionSortOrder = async (export const updateCollectionCover = async (collection: Collection,coverID: number,-) => updateCollectionPublicMagicMetadata(collection, { coverID });+) => updateCollectionDetails(collection, { coverID });const albumDescriptionSegmenter =typeof Intl !== "undefined" && "Segmenter" in Intl@@ -986,19 +986,33 @@ export const albumDescriptionGraphemeCount = (description: string) =>export const updateCollectionDescription = async (collection: Collection,description: string,+) => updateCollectionDetails(collection, { description });++interface CollectionDetailsUpdates {+ description?: string;+ coverID?: number;+}++export const updateCollectionDetails = async (+ collection: Collection,+ { description, coverID }: CollectionDetailsUpdates,) => {- const normalizedDescription = description.trim();- if (- albumDescriptionGraphemeCount(normalizedDescription) >- maxAlbumDescriptionLength- ) {- throw new Error(- `Album descriptions cannot exceed ${maxAlbumDescriptionLength} characters`,- );+ const updates: CollectionPublicMagicMetadataData = {};+ if (description !== undefined) {+ const normalizedDescription = description.trim();+ if (+ albumDescriptionGraphemeCount(normalizedDescription) >+ maxAlbumDescriptionLength+ ) {+ throw new Error(+ `Album descriptions cannot exceed ${maxAlbumDescriptionLength} characters`,+ );+ }+ updates.caption = normalizedDescription;}- return updateCollectionPublicMagicMetadata(collection, {- caption: normalizedDescription,- });+ if (coverID !== undefined) updates.coverID = coverID;++ return updateCollectionPublicMagicMetadata(collection, updates);};export const updateCollectionLayout = async (