Skip to content

armgit / ente

Public Imported from GitHub
0

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

Handle shared uncategorized collections

Neeraj Guptaeee69a266381
diff --git a/mobile/apps/locker/lib/services/collections/collections_service.dart b/mobile/apps/locker/lib/services/collections/collections_service.dart
index d615f72608..f88e6f411c 100644
--- a/mobile/apps/locker/lib/services/collections/collections_service.dart
+++ b/mobile/apps/locker/lib/services/collections/collections_service.dart
@@ -25,6 +25,7 @@ import 'package:locker/services/files/offline/offline_files_service.dart';
import 'package:locker/services/files/sync/models/file.dart';
import 'package:locker/services/trash/models/trash_item_request.dart';
import "package:locker/services/trash/trash_service.dart";
+import "package:locker/utils/collection_list_util.dart";
import "package:locker/utils/crypto_helper.dart";
import 'package:logging/logging.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -214,7 +215,9 @@ class CollectionService {
final int userID = Configuration.instance.getUserID()!;
return collections.where((c) {
- if (!includeUncategorized && c.type == CollectionType.uncategorized) {
+ if (!includeUncategorized &&
+ c.type == CollectionType.uncategorized &&
+ c.isOwner(userID)) {
return false;
}
@@ -362,10 +365,10 @@ class CollectionService {
Future<Collection> getOrCreateUncategorizedCollection() async {
final collections = await getCollections();
- for (final collection in collections) {
- if (collection.type == CollectionType.uncategorized) {
- return collection;
- }
+ final userID = Configuration.instance.getUserID()!;
+ final collection = findUserUncategorizedCollection(collections, userID);
+ if (collection != null) {
+ return collection;
}
_logger.info("No collections found, creating uncategorized collection.");
return await createCollection(
diff --git a/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart b/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart
index 8ec59f7143..be4f7af284 100644
--- a/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart
@@ -1,10 +1,10 @@
-import 'package:collection/collection.dart' show IterableExtension;
import 'package:dotted_border/dotted_border.dart';
import "package:ente_components/ente_components.dart";
import 'package:flutter/material.dart';
import 'package:locker/extensions/collection_extension.dart';
import 'package:locker/l10n/l10n.dart';
import 'package:locker/services/collections/models/collection.dart';
+import 'package:locker/services/configuration.dart';
import 'package:locker/utils/collection_actions.dart';
import 'package:locker/utils/collection_list_util.dart';
@@ -46,25 +46,26 @@ class _CollectionSelectionWidgetState extends State<CollectionSelectionWidget> {
@override
void initState() {
super.initState();
- _availableCollections = uniqueCollectionsById(widget.collections);
- _uncategorizedCollection = _availableCollections.firstWhereOrNull(
- (collection) => collection.type == CollectionType.uncategorized,
- );
- _availableCollections.removeWhere(
- (collection) => collection.type == CollectionType.uncategorized,
- );
+ _updateCollections();
}
@override
void didUpdateWidget(CollectionSelectionWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.collections != widget.collections) {
- _availableCollections = uniqueCollectionsById(widget.collections);
- _uncategorizedCollection = _availableCollections.firstWhereOrNull(
- (collection) => collection.type == CollectionType.uncategorized,
- );
+ _updateCollections();
+ }
+ }
+
+ void _updateCollections() {
+ _availableCollections = uniqueCollectionsById(widget.collections);
+ _uncategorizedCollection = findUserUncategorizedCollection(
+ _availableCollections,
+ Configuration.instance.getUserID()!,
+ );
+ if (_uncategorizedCollection != null) {
_availableCollections.removeWhere(
- (collection) => collection.type == CollectionType.uncategorized,
+ (collection) => collection.id == _uncategorizedCollection!.id,
);
}
}
diff --git a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart b/mobile/apps/locker/lib/ui/pages/all_collections_page.dart
index 5d887a1350..b589320d8c 100644
--- a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/all_collections_page.dart
@@ -9,6 +9,7 @@ import 'package:locker/l10n/l10n.dart';
import 'package:locker/models/selected_collections.dart';
import 'package:locker/services/collections/collections_service.dart';
import 'package:locker/services/collections/models/collection.dart';
+import 'package:locker/services/configuration.dart';
import 'package:locker/ui/components/collection_list_widget.dart';
import "package:locker/ui/components/empty_state_widget.dart";
import 'package:locker/ui/components/item_list_view.dart';
@@ -70,9 +71,11 @@ class _AllCollectionsPageState extends State<AllCollectionsPage> {
final regularCollections = <Collection>[];
Collection? uncategorized;
+ final userID = Configuration.instance.getUserID()!;
for (final collection in collections) {
- if (collection.type == CollectionType.uncategorized) {
+ if (collection.type == CollectionType.uncategorized &&
+ collection.isOwner(userID)) {
uncategorized = collection;
} else {
regularCollections.add(collection);
diff --git a/mobile/apps/locker/lib/ui/pages/file_upload_screen.dart b/mobile/apps/locker/lib/ui/pages/file_upload_screen.dart
index 698103ed6f..72634b8201 100644
--- a/mobile/apps/locker/lib/ui/pages/file_upload_screen.dart
+++ b/mobile/apps/locker/lib/ui/pages/file_upload_screen.dart
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import "package:hugeicons/hugeicons.dart";
import 'package:locker/l10n/l10n.dart';
import 'package:locker/services/collections/models/collection.dart';
+import 'package:locker/services/configuration.dart';
import 'package:locker/ui/components/collection_selection_widget.dart';
import "package:locker/utils/file_icon_utils.dart";
import 'package:path/path.dart' as path;
@@ -47,9 +48,11 @@ class _FileUploadScreenState extends State<FileUploadScreen> {
_files = List.from(widget.files);
_availableCollections = List.from(widget.collections);
- if (widget.selectedCollection != null &&
- widget.selectedCollection!.type != CollectionType.uncategorized) {
- _selectedCollectionIds.add(widget.selectedCollection!.id);
+ final selectedCollection = widget.selectedCollection;
+ if (selectedCollection != null &&
+ (selectedCollection.type != CollectionType.uncategorized ||
+ !selectedCollection.isOwner(Configuration.instance.getUserID()!))) {
+ _selectedCollectionIds.add(selectedCollection.id);
}
}
diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dart
index 8a00c19a67..844af6cb9c 100644
--- a/mobile/apps/locker/lib/ui/pages/home_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart
@@ -224,7 +224,10 @@ class _HomePageState extends UploaderPageState<HomePage>
}
List<Collection> _filterOutUncategorized(List<Collection> collections) {
- return CollectionSortUtil.filterAndSortCollections(collections);
+ return CollectionSortUtil.filterAndSortCollections(
+ collections,
+ Configuration.instance.getUserID()!,
+ );
}
@override
diff --git a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
index 7d4c936d27..8d4a41729f 100644
--- a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
+++ b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
@@ -194,27 +194,29 @@ class _ShareCollectionSheetState extends State<ShareCollectionSheet> {
);
},
),
- const SizedBox(width: 16),
- _ShareActionOption(
- icon: HugeIcons.strokeRoundedLink02,
- label: _hasPublicLink
- ? context.l10n.manageLink
- : context.l10n.linkLabel,
- onTap: () async {
- if (!_hasPublicLink) {
- await _createAndSharePublicLink();
- return;
- }
-
- await routeToPage(
- context,
- ManageSharedLinkWidget(collection: widget.collection),
- );
- if (mounted) {
- setState(() {});
- }
- },
- ),
+ if (widget.collection.type != CollectionType.uncategorized) ...[
+ const SizedBox(width: 16),
+ _ShareActionOption(
+ icon: HugeIcons.strokeRoundedLink02,
+ label: _hasPublicLink
+ ? context.l10n.manageLink
+ : context.l10n.linkLabel,
+ onTap: () async {
+ if (!_hasPublicLink) {
+ await _createAndSharePublicLink();
+ return;
+ }
+
+ await routeToPage(
+ context,
+ ManageSharedLinkWidget(collection: widget.collection),
+ );
+ if (mounted) {
+ setState(() {});
+ }
+ },
+ ),
+ ],
],
);
}
diff --git a/mobile/apps/locker/lib/utils/collection_list_util.dart b/mobile/apps/locker/lib/utils/collection_list_util.dart
index e2c05e8f06..eadd996d56 100644
--- a/mobile/apps/locker/lib/utils/collection_list_util.dart
+++ b/mobile/apps/locker/lib/utils/collection_list_util.dart
@@ -1,30 +1,21 @@
import 'package:locker/services/collections/models/collection.dart';
/// Returns a list of collections with duplicate IDs removed while preserving
-/// order. Stops at the first uncategorized collection encountered.
+/// order.
List<Collection> uniqueCollectionsById(List<Collection> collections) {
final seenIds = <int>{};
- final unique = <Collection>[];
-
- bool uncategorizedSeen = false;
+ return collections.where((collection) => seenIds.add(collection.id)).toList();
+}
+Collection? findUserUncategorizedCollection(
+ Iterable<Collection> collections,
+ int userID,
+) {
for (final collection in collections) {
- final isUncategorizedCollection = _isUncategorized(collection);
-
- if (seenIds.add(collection.id)) {
- if (isUncategorizedCollection) {
- if (uncategorizedSeen) {
- continue;
- }
- uncategorizedSeen = true;
- }
- unique.add(collection);
+ if (collection.type == CollectionType.uncategorized &&
+ collection.isOwner(userID)) {
+ return collection;
}
}
-
- return unique;
-}
-
-bool _isUncategorized(Collection collection) {
- return collection.type == CollectionType.uncategorized;
+ return null;
}
diff --git a/mobile/apps/locker/lib/utils/collection_sort_util.dart b/mobile/apps/locker/lib/utils/collection_sort_util.dart
index 80e12f9426..b9251f5259 100644
--- a/mobile/apps/locker/lib/utils/collection_sort_util.dart
+++ b/mobile/apps/locker/lib/utils/collection_sort_util.dart
@@ -28,12 +28,15 @@ class CollectionSortUtil {
return sortedList;
}
- /// Filters out uncategorized collections and sorts the remaining ones
+ /// Filters out the user's uncategorized collection and sorts the rest.
static List<Collection> filterAndSortCollections(
List<Collection> collections,
+ int userID,
) {
final filtered = collections
- .where((c) => c.type != CollectionType.uncategorized)
+ .where(
+ (c) => c.type != CollectionType.uncategorized || !c.isOwner(userID),
+ )
.toList();
sortCollections(filtered);
return filtered;
diff --git a/mobile/apps/locker/test/utils/collection_list_util_test.dart b/mobile/apps/locker/test/utils/collection_list_util_test.dart
new file mode 100644
index 0000000000..7160aecc50
--- /dev/null
+++ b/mobile/apps/locker/test/utils/collection_list_util_test.dart
@@ -0,0 +1,45 @@
+import "package:ente_sharing/models/user.dart";
+import "package:flutter_test/flutter_test.dart";
+import "package:locker/services/collections/models/collection.dart";
+import "package:locker/utils/collection_list_util.dart";
+
+void main() {
+ test("keeps distinct uncategorized collections", () {
+ final ownCollection = _uncategorizedCollection(1, 10);
+ final sharedCollection = _uncategorizedCollection(2, 20);
+
+ expect(
+ uniqueCollectionsById([
+ sharedCollection,
+ ownCollection,
+ sharedCollection,
+ ]),
+ [sharedCollection, ownCollection],
+ );
+ });
+
+ test("finds the uncategorized collection owned by the user", () {
+ final sharedCollection = _uncategorizedCollection(1, 20);
+ final ownCollection = _uncategorizedCollection(2, 10);
+
+ expect(
+ findUserUncategorizedCollection([sharedCollection, ownCollection], 10),
+ ownCollection,
+ );
+ });
+}
+
+Collection _uncategorizedCollection(int id, int ownerID) => Collection(
+ id,
+ User(id: ownerID, email: "[email protected]"),
+ "",
+ null,
+ "Uncategorized",
+ null,
+ null,
+ CollectionType.uncategorized,
+ CollectionAttributes(),
+ const [],
+ const [],
+ 0,
+);
diff --git a/mobile/apps/photos/lib/services/collections_service.dart b/mobile/apps/photos/lib/services/collections_service.dart
index 9da6a0f411..c187a15114 100644
--- a/mobile/apps/photos/lib/services/collections_service.dart
+++ b/mobile/apps/photos/lib/services/collections_service.dart
@@ -495,7 +495,8 @@ class CollectionsService {
(c) =>
!c.isDeleted &&
(includeUncategorized ||
- c.type != CollectionType.uncategorized) &&
+ c.type != CollectionType.uncategorized ||
+ !c.isOwner(userID)) &&
!c.isHidden() &&
allowedRoles.contains(c.getRole(userID)),
)
@@ -555,6 +556,7 @@ class CollectionsService {
final List<Collection> quickLinks = [];
final List<Collection> collections = getCollectionsForUI(
includedShared: true,
+ includeUncategorized: true,
);
for (final c in collections) {
if (c.owner.id == Configuration.instance.getUserID()) {
diff --git a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
index 00335754db..40768b27ca 100644
--- a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
+++ b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
@@ -452,12 +452,14 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
final List<Collection> pinned = [];
final List<Collection> unpinned = [];
final List<Collection> recentlyCreated = [];
+ final userID = Configuration.instance.getUserID()!;
// show uncategorized collection only for restore files action
Collection? uncategorized;
for (final collection in collections) {
if (collection.isQuickLinkCollection() ||
collection.type == CollectionType.favorites ||
- collection.type == CollectionType.uncategorized) {
+ (collection.type == CollectionType.uncategorized &&
+ collection.isOwner(userID))) {
if (collection.type == CollectionType.uncategorized) {
uncategorized = collection;
}
diff --git a/mobile/apps/photos/lib/ui/sharing/album_participants_page.dart b/mobile/apps/photos/lib/ui/sharing/album_participants_page.dart
index 82b4e1ae44..7467c1d3f4 100644
--- a/mobile/apps/photos/lib/ui/sharing/album_participants_page.dart
+++ b/mobile/apps/photos/lib/ui/sharing/album_participants_page.dart
@@ -76,7 +76,10 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {
final bool hasActivePublicLink =
_collection.hasLink &&
!(_collection.publicURLs.firstOrNull?.isExpired ?? true);
- final bool shouldShowPublicLink = !isOwner && hasActivePublicLink;
+ final bool shouldShowPublicLink =
+ _collection.type != CollectionType.uncategorized &&
+ !isOwner &&
+ hasActivePublicLink;
final int participants = 1 + _collection.getSharees().length;
final User owner = _collection.owner;
if (owner.id == currentUserID && owner.email == "") {
diff --git a/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart b/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart
index cdebb93b40..7df5c32d1c 100644
--- a/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart
+++ b/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart
@@ -170,7 +170,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
]);
}
- if (isOwner) {
+ if (isOwner && _collection.type != CollectionType.uncategorized) {
children.addAll([
const SizedBox(height: Spacing.xxl),
ShareSectionTitle(
diff --git a/mobile/apps/photos/lib/ui/tabs/albums/albums_manage_sheet.dart b/mobile/apps/photos/lib/ui/tabs/albums/albums_manage_sheet.dart
index 55330f88fd..6678af354e 100644
--- a/mobile/apps/photos/lib/ui/tabs/albums/albums_manage_sheet.dart
+++ b/mobile/apps/photos/lib/ui/tabs/albums/albums_manage_sheet.dart
@@ -6,6 +6,7 @@ import "package:ente_lock_screen/local_authentication_service.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
+import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/collection/collection.dart";
import "package:photos/services/collections_service.dart";
@@ -59,7 +60,9 @@ Future<void> showAlbumsManageSheet(BuildContext context) {
Collection? collection = CollectionsService.instance
.getActiveCollections()
.firstWhereOrNull(
- (c) => c.type == CollectionType.uncategorized,
+ (c) =>
+ c.type == CollectionType.uncategorized &&
+ c.isOwner(Configuration.instance.getUserID()!),
);
collection ??= await CollectionsService.instance
.getUncategorizedCollection();
diff --git a/web/apps/locker/src/types.ts b/web/apps/locker/src/types.ts
index 899df2f4b7..9fd000c702 100644
--- a/web/apps/locker/src/types.ts
+++ b/web/apps/locker/src/types.ts
@@ -170,7 +170,7 @@ export const canLeaveCollection = (
collection: LockerCollection,
currentUserID: number | undefined,
) =>
- canOpenCollectionSharing(collection) &&
+ !isImportantCollection(collection) &&
!isCollectionOwner(collection, currentUserID);
export const isLockerItemOwner = (
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsx
index e725a9188b..5205d7a9a0 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx
@@ -186,7 +186,9 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({
const isSharedIncoming = collectionSummary?.type == "sharedIncoming";
const showEmailSection = !isSharedIncoming || canManageParticipants;
const hasPublicLink = collection?.publicURLs.length > 0;
- const showPublicShare = isOwner || (isSharedIncoming && hasPublicLink);
+ const showPublicShare =
+ collection?.type != "uncategorized" &&
+ (isOwner || (isSharedIncoming && hasPublicLink));
// Use a ref to track if we've already fetched for this dialog session
const hasFetchedForSession = useRef(false);
@@ -206,6 +208,7 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({
const shouldFetch =
open &&
collection &&
+ collection.type != "uncategorized" &&
!isOwner &&
isSharedIncoming &&
!hasPublicLink &&
diff --git a/web/apps/photos/tests/collection.test.ts b/web/apps/photos/tests/collection.test.ts
new file mode 100644
index 0000000000..c47854ccd6
--- /dev/null
+++ b/web/apps/photos/tests/collection.test.ts
@@ -0,0 +1,24 @@
+import { findUserUncategorizedCollection } from "ente-media/collection";
+import { describe, expect, test } from "vitest";
+
+describe("findUserUncategorizedCollection", () => {
+ test("selects the collection owned by the user", () => {
+ const sharedCollection = { type: "uncategorized", owner: { id: 20 } };
+ const ownCollection = { type: "uncategorized", owner: { id: 10 } };
+
+ expect(
+ findUserUncategorizedCollection(
+ [sharedCollection, ownCollection],
+ 10,
+ ),
+ ).toBe(ownCollection);
+ });
+
+ test("does not return another user's collection", () => {
+ const sharedCollection = { type: "uncategorized", owner: { id: 20 } };
+
+ expect(
+ findUserUncategorizedCollection([sharedCollection], 10),
+ ).toBeUndefined();
+ });
+});
diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.ts
index c83407f083..3e94a26ba5 100644
--- a/web/packages/media/collection.ts
+++ b/web/packages/media/collection.ts
@@ -171,12 +171,28 @@ export const collectionTypes = [
* corresponding operation moves the file to the user's special
* "uncategorized" collection, creating it if needed.
*
- * Similar to "favorites", the user can have only one "uncategorized"
- * collection. However, unlike "favorites", the "uncategorized" collection
- * cannot be shared.
+ * Similar to "favorites", the user can own only one "uncategorized"
+ * collection. Shared collections of this type can also be present locally,
+ * so callers must include the owner when resolving the user's collection.
*/
export type CollectionType = (typeof collectionTypes)[number];
+interface CollectionTypeAndOwner {
+ type: string;
+ owner: { id: number };
+}
+
+export const findUserUncategorizedCollection = <
+ T extends CollectionTypeAndOwner,
+>(
+ collections: readonly T[],
+ userID: number,
+) =>
+ collections.find(
+ (collection) =>
+ collection.type == "uncategorized" && collection.owner.id == userID,
+ );
+
/**
* The privilege level of a participant associated with a collection.
*
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 086a78f21a..c615b8acf1 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -7,6 +7,7 @@ import {
import {
CollectionOrder,
collectionTypes,
+ findUserUncategorizedCollection,
type Collection,
} from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
@@ -655,7 +656,10 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
hiddenCollectionSummaries,
archivedCollectionSummaries,
uncategorizedCollectionSummaryID:
- deriveUncategorizedCollectionSummaryID(normalCollections),
+ deriveUncategorizedCollectionSummaryID(
+ normalCollections,
+ user.id,
+ ),
view,
});
}
@@ -786,7 +790,10 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
hiddenCollectionSummaries,
archivedCollectionSummaries,
uncategorizedCollectionSummaryID:
- deriveUncategorizedCollectionSummaryID(normalCollections),
+ deriveUncategorizedCollectionSummaryID(
+ normalCollections,
+ state.user!.id,
+ ),
selectedCollectionSummaryID,
pendingSearchSuggestions:
enqueuePendingSearchSuggestionsIfNeeded(
@@ -1541,8 +1548,9 @@ const deriveNormalCollectionSummaries = (
collectionFiles,
);
- const uncategorizedCollection = normalCollections.find(
- ({ type }) => type == "uncategorized",
+ const uncategorizedCollection = findUserUncategorizedCollection(
+ normalCollections,
+ user.id,
);
if (!uncategorizedCollection) {
const id = PseudoCollectionID.uncategorizedPlaceholder;
@@ -1698,8 +1706,9 @@ const deriveArchivedCollectionSummaries = (
*/
const deriveUncategorizedCollectionSummaryID = (
normalCollections: Collection[],
+ userID: number,
) =>
- normalCollections.find(({ type }) => type == "uncategorized")?.id ??
+ findUserUncategorizedCollection(normalCollections, userID)?.id ??
PseudoCollectionID.uncategorizedPlaceholder;
const createCollectionSummaries = (
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index 28236f4b44..c8f1fd0b79 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -15,6 +15,7 @@ import { groupFilesByCollectionID } from "ente-gallery/utils/file";
import {
CollectionSubType,
decryptRemoteCollection,
+ findUserUncategorizedCollection,
RemoteCollection,
RemotePublicURL,
type Collection,
@@ -1015,10 +1016,7 @@ export const copyFiles = async (
*/
const savedUserUncategorizedCollection = async () => {
const userID = ensureLocalUser().id;
- return (await savedCollections()).find(
- (collection) =>
- collection.type == "uncategorized" && collection.owner.id == userID,
- );
+ return findUserUncategorizedCollection(await savedCollections(), userID);
};
/**
@@ -1490,7 +1488,7 @@ const removeOwnFilesFromOwnCollection = async (
const remainingFiles = filesToRemove.filter(pendingRemove);
if (remainingFiles.length) {
const uncategorizedCollection =
- collections.find((c) => c.type == "uncategorized") ??
+ findUserUncategorizedCollection(collections, userID) ??
(await createUncategorizedCollection());
await moveFromCollection(
@@ -2426,6 +2424,7 @@ export const fetchPendingRemovalActions = async (): Promise<
export const movePendingRemovalActionsToUncategorized = async (
collections: Collection[],
) => {
+ const userID = ensureLocalUser().id;
const pendingActions = await fetchPendingRemovalActions();
if (!pendingActions.length) return;
@@ -2489,7 +2488,7 @@ export const movePendingRemovalActionsToUncategorized = async (
// Move files from normal collections to uncategorized
if (!uncategorizedCollection) {
uncategorizedCollection =
- collections.find((c) => c.type == "uncategorized") ??
+ findUserUncategorizedCollection(collections, userID) ??
(await createUncategorizedCollection());
}
targetCollection = uncategorizedCollection;