From 19d146c4a979cf929ce98a118f928ac3175469d5 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 3 Jul 2023 12:00:15 +0530 Subject: [PATCH 01/41] separate out incomingShare Viewer and Collaborator CollectionSummaryType --- apps/photos/src/constants/collection.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/photos/src/constants/collection.ts b/apps/photos/src/constants/collection.ts index e2e106a039..9235d67fa7 100644 --- a/apps/photos/src/constants/collection.ts +++ b/apps/photos/src/constants/collection.ts @@ -19,7 +19,8 @@ export enum CollectionSummaryType { uncategorized = 'uncategorized', all = 'all', outgoingShare = 'outgoingShare', - incomingShare = 'incomingShare', + incomingShareViewer = 'incomingShareViewer', + incomingShareCollaborator = 'incomingShareCollaborator', sharedOnlyViaLink = 'sharedOnlyViaLink', archived = 'archived', hidden = 'hidden', @@ -40,7 +41,8 @@ export const COLLECTION_SORT_ORDER = new Map([ [CollectionSummaryType.favorites, 2], [CollectionSummaryType.album, 3], [CollectionSummaryType.folder, 3], - [CollectionSummaryType.incomingShare, 3], + [CollectionSummaryType.incomingShareViewer, 3], + [CollectionSummaryType.incomingShareCollaborator, 3], [CollectionSummaryType.outgoingShare, 3], [CollectionSummaryType.sharedOnlyViaLink, 3], [CollectionSummaryType.archived, 3], @@ -57,10 +59,20 @@ export const SYSTEM_COLLECTION_TYPES = new Set([ CollectionSummaryType.hidden, ]); -export const SELECT_NOT_ALLOWED_COLLECTION = new Set([ +export const ADD_TO_NOT_ALLOWED_COLLECTION = new Set([ CollectionSummaryType.all, CollectionSummaryType.archive, - CollectionSummaryType.incomingShare, + CollectionSummaryType.incomingShareViewer, + CollectionSummaryType.trash, + CollectionSummaryType.uncategorized, + CollectionSummaryType.hidden, +]); + +export const MOVE_TO_NOT_ALLOWED_COLLECTION = new Set([ + CollectionSummaryType.all, + CollectionSummaryType.archive, + CollectionSummaryType.incomingShareViewer, + CollectionSummaryType.incomingShareCollaborator, CollectionSummaryType.trash, CollectionSummaryType.uncategorized, CollectionSummaryType.hidden, From 029bd7fb93e3eb7efc3018ff6cd1838ed1c79ca6 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 3 Jul 2023 12:01:33 +0530 Subject: [PATCH 02/41] added support for showing collab album in collection selector add to album --- .../Collections/CollectionSelector/index.tsx | 13 ++++++++++--- apps/photos/src/utils/collection/index.ts | 14 ++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/photos/src/components/Collections/CollectionSelector/index.tsx b/apps/photos/src/components/Collections/CollectionSelector/index.tsx index 5431f1c651..6fde32eb43 100644 --- a/apps/photos/src/components/Collections/CollectionSelector/index.tsx +++ b/apps/photos/src/components/Collections/CollectionSelector/index.tsx @@ -18,8 +18,11 @@ import { DUMMY_UNCATEGORIZED_SECTION, } from 'constants/collection'; import { t } from 'i18next'; -import { isSelectAllowedCollection } from 'utils/collection'; import { createUnCategorizedCollection } from 'services/collectionService'; +import { + isAddToAllowedCollection, + isMoveToAllowedCollection, +} from 'utils/collection'; export interface CollectionSelectorAttributes { callback: (collection: Collection) => void; @@ -56,15 +59,19 @@ function CollectionSelector({ ?.filter(({ id, type }) => { if (id === attributes.fromCollection) { return false; + } else if ( + attributes.intent === CollectionSelectorIntent.add + ) { + return isAddToAllowedCollection(type); } else if ( attributes.intent === CollectionSelectorIntent.upload ) { return ( - isSelectAllowedCollection(type) || + isMoveToAllowedCollection(type) || type === CollectionSummaryType.uncategorized ); } else { - return isSelectAllowedCollection(type); + return isMoveToAllowedCollection(type); } }) .sort((a, b) => { diff --git a/apps/photos/src/utils/collection/index.ts b/apps/photos/src/utils/collection/index.ts index 7dbc9a0fd6..0258b358f2 100644 --- a/apps/photos/src/utils/collection/index.ts +++ b/apps/photos/src/utils/collection/index.ts @@ -28,7 +28,8 @@ import { HIDE_FROM_COLLECTION_BAR_TYPES, OPTIONS_NOT_HAVING_COLLECTION_TYPES, SYSTEM_COLLECTION_TYPES, - SELECT_NOT_ALLOWED_COLLECTION, + MOVE_TO_NOT_ALLOWED_COLLECTION, + ADD_TO_NOT_ALLOWED_COLLECTION, } from 'constants/collection'; import { getUnixTimeInMicroSecondsWithDelta } from 'utils/time'; import { SUB_TYPE, VISIBILITY_STATE } from 'types/magicMetadata'; @@ -237,8 +238,12 @@ export const hasNonSystemCollections = ( return false; }; -export const isSelectAllowedCollection = (type: CollectionSummaryType) => { - return !SELECT_NOT_ALLOWED_COLLECTION.has(type); +export const isMoveToAllowedCollection = (type: CollectionSummaryType) => { + return !MOVE_TO_NOT_ALLOWED_COLLECTION.has(type); +}; + +export const isAddToAllowedCollection = (type: CollectionSummaryType) => { + return !ADD_TO_NOT_ALLOWED_COLLECTION.has(type); }; export const isSystemCollection = (type: CollectionSummaryType) => { @@ -258,7 +263,8 @@ export const showDownloadQuickOption = (type: CollectionSummaryType) => { type === CollectionSummaryType.album || type === CollectionSummaryType.uncategorized || type === CollectionSummaryType.hidden || - type === CollectionSummaryType.incomingShare || + type === CollectionSummaryType.incomingShareViewer || + type === CollectionSummaryType.incomingShareCollaborator || type === CollectionSummaryType.outgoingShare || type === CollectionSummaryType.sharedOnlyViaLink || type === CollectionSummaryType.archived From 17b7776ab5b9544c20efe86256bbfc5e0ec03e21 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 3 Jul 2023 13:12:37 +0530 Subject: [PATCH 03/41] updated usage of CollectionSummaryType.incomingShare to newer separate types --- .../Collections/CollectionInfoWithOptions.tsx | 3 ++- .../CollectionListBar/CollectionCard.tsx | 4 +++- .../Collections/CollectionOptions/index.tsx | 7 ++++++- .../CollectionShare/sharees/index.tsx | 4 ++-- .../CollectionShare/sharees/row.tsx | 6 +++--- apps/photos/src/pages/gallery/index.tsx | 9 +++++++-- apps/photos/src/services/collectionService.ts | 11 +++++++---- apps/photos/src/types/collection/index.ts | 18 +++++++++++++++--- apps/photos/src/utils/collection/index.ts | 17 +++++++++++++++-- 9 files changed, 60 insertions(+), 19 deletions(-) diff --git a/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsx b/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsx index ffe6ae04da..8ddeb379a7 100644 --- a/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsx +++ b/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsx @@ -36,7 +36,8 @@ export default function CollectionInfoWithOptions({ return ; case CollectionSummaryType.archived: return ; - case CollectionSummaryType.incomingShare: + case CollectionSummaryType.incomingShareViewer: + case CollectionSummaryType.incomingShareCollaborator: return ; case CollectionSummaryType.outgoingShare: return ; diff --git a/apps/photos/src/components/Collections/CollectionListBar/CollectionCard.tsx b/apps/photos/src/components/Collections/CollectionListBar/CollectionCard.tsx index aca2d4cc86..c32f3ddda1 100644 --- a/apps/photos/src/components/Collections/CollectionListBar/CollectionCard.tsx +++ b/apps/photos/src/components/Collections/CollectionListBar/CollectionCard.tsx @@ -63,7 +63,9 @@ function CollectionCardIcon({ collectionType }) { {collectionType === CollectionSummaryType.outgoingShare && ( )} - {collectionType === CollectionSummaryType.incomingShare && ( + {(collectionType === CollectionSummaryType.incomingShareViewer || + collectionType === + CollectionSummaryType.incomingShareCollaborator) && ( )} {collectionType === CollectionSummaryType.sharedOnlyViaLink && ( diff --git a/apps/photos/src/components/Collections/CollectionOptions/index.tsx b/apps/photos/src/components/Collections/CollectionOptions/index.tsx index 16e593f458..5b00543e94 100644 --- a/apps/photos/src/components/Collections/CollectionOptions/index.tsx +++ b/apps/photos/src/components/Collections/CollectionOptions/index.tsx @@ -322,7 +322,12 @@ const CollectionOptions = (props: CollectionOptionsProps) => { downloadOptionText={t('DOWNLOAD_HIDDEN')} /> ) : collectionSummaryType === - CollectionSummaryType.incomingShare ? ( + CollectionSummaryType.incomingShareCollaborator ? ( + + ) : collectionSummaryType === + CollectionSummaryType.incomingShareViewer ? ( diff --git a/apps/photos/src/components/Collections/CollectionShare/sharees/index.tsx b/apps/photos/src/components/Collections/CollectionShare/sharees/index.tsx index ff2d93991e..d5ff5593aa 100644 --- a/apps/photos/src/components/Collections/CollectionShare/sharees/index.tsx +++ b/apps/photos/src/components/Collections/CollectionShare/sharees/index.tsx @@ -4,7 +4,7 @@ import { AppContext } from 'pages/_app'; import React, { useContext } from 'react'; import { t } from 'i18next'; import { unshareCollection } from 'services/collectionService'; -import { Collection } from 'types/collection'; +import { Collection, CollectionUser } from 'types/collection'; import ShareeRow from './row'; interface Iprops { @@ -15,7 +15,7 @@ export function CollectionShareSharees({ collection }: Iprops) { const appContext = useContext(AppContext); const galleryContext = useContext(GalleryContext); - const collectionUnshare = async (sharee) => { + const collectionUnshare = async (sharee: CollectionUser) => { try { appContext.startLoading(); await unshareCollection(collection, sharee.email); diff --git a/apps/photos/src/components/Collections/CollectionShare/sharees/row.tsx b/apps/photos/src/components/Collections/CollectionShare/sharees/row.tsx index 2f8f5bb31e..a4646310dc 100644 --- a/apps/photos/src/components/Collections/CollectionShare/sharees/row.tsx +++ b/apps/photos/src/components/Collections/CollectionShare/sharees/row.tsx @@ -1,16 +1,16 @@ import React from 'react'; import { SpaceBetweenFlex } from 'components/Container'; -import { User } from 'types/user'; import MoreHorizIcon from '@mui/icons-material/MoreHoriz'; import OverflowMenu from 'components/OverflowMenu/menu'; import NotInterestedIcon from '@mui/icons-material/NotInterested'; import { OverflowMenuOption } from 'components/OverflowMenu/option'; import { t } from 'i18next'; +import { CollectionUser } from 'types/collection'; interface IProps { - sharee: User; - collectionUnshare: (sharee: User) => void; + sharee: CollectionUser; + collectionUnshare: (sharee: CollectionUser) => void; } const ShareeRow = ({ sharee, collectionUnshare }: IProps) => { const handleClick = () => collectionUnshare(sharee); diff --git a/apps/photos/src/pages/gallery/index.tsx b/apps/photos/src/pages/gallery/index.tsx index c24ccf9eb1..fcfbb7a540 100644 --- a/apps/photos/src/pages/gallery/index.tsx +++ b/apps/photos/src/pages/gallery/index.tsx @@ -1036,7 +1036,9 @@ export default function Gallery() { activeCollection={activeCollection} isIncomingSharedCollection={ collectionSummaries.get(activeCollection)?.type === - CollectionSummaryType.incomingShare + CollectionSummaryType.incomingShareCollaborator || + collectionSummaries.get(activeCollection)?.type === + CollectionSummaryType.incomingShareViewer } enableDownload={true} fileToCollectionsMap={fileToCollectionsMap} @@ -1105,7 +1107,10 @@ export default function Gallery() { isIncomingSharedCollection={ collectionSummaries.get(activeCollection) ?.type === - CollectionSummaryType.incomingShare + CollectionSummaryType.incomingShareCollaborator || + collectionSummaries.get(activeCollection) + ?.type === + CollectionSummaryType.incomingShareViewer } isInSearchMode={isInSearchMode} /> diff --git a/apps/photos/src/services/collectionService.ts b/apps/photos/src/services/collectionService.ts index 57797a435b..07bff96e72 100644 --- a/apps/photos/src/services/collectionService.ts +++ b/apps/photos/src/services/collectionService.ts @@ -48,12 +48,13 @@ import { User } from 'types/user'; import { isQuickLinkCollection, isOutgoingShare, - isIncomingShare, isSharedOnlyViaLink, isValidMoveTarget, isHiddenCollection, getNonHiddenCollections, changeCollectionSubType, + isIncomingViewerShare, + isIncomingCollabShare, } from 'utils/collection'; import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker'; import { getLocalFiles } from './fileService'; @@ -1024,9 +1025,11 @@ export async function getCollectionSummaries( latestFile: collectionLatestFiles.get(collection.id), fileCount: collectionFilesCount.get(collection.id) ?? 0, updationTime: collection.updationTime, - type: isIncomingShare(collection, user) - ? CollectionSummaryType.incomingShare - : isOutgoingShare(collection) + type: isIncomingViewerShare(collection, user) + ? CollectionSummaryType.incomingShareViewer + : isIncomingCollabShare(collection, user) + ? CollectionSummaryType.incomingShareCollaborator + : isOutgoingShare(collection, user) ? CollectionSummaryType.outgoingShare : isSharedOnlyViaLink(collection) ? CollectionSummaryType.sharedOnlyViaLink diff --git a/apps/photos/src/types/collection/index.ts b/apps/photos/src/types/collection/index.ts index d989a316cc..cc388ddae5 100644 --- a/apps/photos/src/types/collection/index.ts +++ b/apps/photos/src/types/collection/index.ts @@ -1,4 +1,3 @@ -import { User } from 'types/user'; import { EnteFile } from 'types/file'; import { CollectionSummaryType, CollectionType } from 'constants/collection'; import { @@ -8,9 +7,22 @@ import { VISIBILITY_STATE, } from 'types/magicMetadata'; +export enum COLLECTION_ROLE { + OWNER = 'OWNER', + VIEWER = 'VIEWER', + COLLABORATOR = 'COLLABORATOR', + UNKNOWN = 'UNKNOWN', +} + +export interface CollectionUser { + id: number; + email: string; + role: COLLECTION_ROLE; +} + export interface EncryptedCollection { id: number; - owner: User; + owner: CollectionUser; // collection name was unencrypted in the past, so we need to keep it as optional name?: string; encryptedKey: string; @@ -19,7 +31,7 @@ export interface EncryptedCollection { nameDecryptionNonce: string; type: CollectionType; attributes: collectionAttributes; - sharees: User[]; + sharees: CollectionUser[]; publicURLs?: PublicURL[]; updationTime: number; isDeleted: boolean; diff --git a/apps/photos/src/utils/collection/index.ts b/apps/photos/src/utils/collection/index.ts index 0258b358f2..bf4a57ef29 100644 --- a/apps/photos/src/utils/collection/index.ts +++ b/apps/photos/src/utils/collection/index.ts @@ -17,6 +17,7 @@ import { User } from 'types/user'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { logError } from 'utils/sentry'; import { + COLLECTION_ROLE, Collection, CollectionMagicMetadataProps, CollectionPublicMagicMetadataProps, @@ -301,12 +302,24 @@ export const isHiddenCollection = (collection: Collection) => export const isQuickLinkCollection = (collection: Collection) => collection.magicMetadata?.data.subType === SUB_TYPE.QUICK_LINK_COLLECTION; -export function isOutgoingShare(collection: Collection): boolean { - return collection.sharees?.length > 0; +export function isOutgoingShare(collection: Collection, user: User): boolean { + return collection.owner.id === user.id && collection.sharees?.length > 0; } + export function isIncomingShare(collection: Collection, user: User) { return collection.owner.id !== user.id; } + +export function isIncomingViewerShare(collection: Collection, user: User) { + const sharee = collection.sharees?.find((sharee) => sharee.id === user.id); + return sharee?.role === COLLECTION_ROLE.VIEWER; +} + +export function isIncomingCollabShare(collection: Collection, user: User) { + const sharee = collection.sharees?.find((sharee) => sharee.id === user.id); + return sharee?.role === COLLECTION_ROLE.COLLABORATOR; +} + export function isSharedOnlyViaLink(collection: Collection) { return collection.publicURLs?.length && !collection.sharees?.length; } From 53b245b21f7dfd0373c285cca059776f18e286f7 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 3 Jul 2023 13:23:21 +0530 Subject: [PATCH 04/41] refactor --- .../components/Collections/CollectionOptions/index.tsx | 9 +++------ apps/photos/src/types/collection/index.ts | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/photos/src/components/Collections/CollectionOptions/index.tsx b/apps/photos/src/components/Collections/CollectionOptions/index.tsx index 5b00543e94..fc45f08460 100644 --- a/apps/photos/src/components/Collections/CollectionOptions/index.tsx +++ b/apps/photos/src/components/Collections/CollectionOptions/index.tsx @@ -322,12 +322,9 @@ const CollectionOptions = (props: CollectionOptionsProps) => { downloadOptionText={t('DOWNLOAD_HIDDEN')} /> ) : collectionSummaryType === - CollectionSummaryType.incomingShareCollaborator ? ( - - ) : collectionSummaryType === - CollectionSummaryType.incomingShareViewer ? ( + CollectionSummaryType.incomingShareViewer || + collectionSummaryType === + CollectionSummaryType.incomingShareCollaborator ? ( diff --git a/apps/photos/src/types/collection/index.ts b/apps/photos/src/types/collection/index.ts index cc388ddae5..7b2a00c849 100644 --- a/apps/photos/src/types/collection/index.ts +++ b/apps/photos/src/types/collection/index.ts @@ -8,8 +8,8 @@ import { } from 'types/magicMetadata'; export enum COLLECTION_ROLE { - OWNER = 'OWNER', VIEWER = 'VIEWER', + OWNER = 'OWNER', COLLABORATOR = 'COLLABORATOR', UNKNOWN = 'UNKNOWN', } From a69848d819212b2cb7d6bb19202d7b0b1b0ccba5 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 4 Jul 2023 11:05:53 +0530 Subject: [PATCH 05/41] refactor CollectionSummaryType determination and fallback to incoming share viewer if not a collab incoming share --- apps/photos/src/services/collectionService.ts | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/apps/photos/src/services/collectionService.ts b/apps/photos/src/services/collectionService.ts index 07bff96e72..3c25133655 100644 --- a/apps/photos/src/services/collectionService.ts +++ b/apps/photos/src/services/collectionService.ts @@ -53,8 +53,8 @@ import { isHiddenCollection, getNonHiddenCollections, changeCollectionSubType, - isIncomingViewerShare, isIncomingCollabShare, + isIncomingShare, } from 'utils/collection'; import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker'; import { getLocalFiles } from './fileService'; @@ -1019,25 +1019,32 @@ export async function getCollectionSummaries( collectionFilesCount.get(collection.id) || collection.type === CollectionType.uncategorized ) { + let type: CollectionSummaryType; + if (isIncomingShare(collection, user)) { + if (isIncomingCollabShare(collection, user)) { + type = CollectionSummaryType.incomingShareCollaborator; + } else { + type = CollectionSummaryType.incomingShareViewer; + } + } else if (isOutgoingShare(collection, user)) { + type = CollectionSummaryType.outgoingShare; + } else if (isSharedOnlyViaLink(collection)) { + type = CollectionSummaryType.sharedOnlyViaLink; + } else if (IsArchived(collection)) { + type = CollectionSummaryType.archived; + } else if (isHiddenCollection(collection)) { + type = CollectionSummaryType.hidden; + } else { + type = CollectionSummaryType[collection.type]; + } + collectionSummaries.set(collection.id, { id: collection.id, name: collection.name, latestFile: collectionLatestFiles.get(collection.id), fileCount: collectionFilesCount.get(collection.id) ?? 0, updationTime: collection.updationTime, - type: isIncomingViewerShare(collection, user) - ? CollectionSummaryType.incomingShareViewer - : isIncomingCollabShare(collection, user) - ? CollectionSummaryType.incomingShareCollaborator - : isOutgoingShare(collection, user) - ? CollectionSummaryType.outgoingShare - : isSharedOnlyViaLink(collection) - ? CollectionSummaryType.sharedOnlyViaLink - : IsArchived(collection) - ? CollectionSummaryType.archived - : isHiddenCollection(collection) - ? CollectionSummaryType.hidden - : CollectionSummaryType[collection.type], + type: type, }); } } From 580f4ab3c98595817e1e5134216029e5db8ddd29 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 4 Jul 2023 11:07:12 +0530 Subject: [PATCH 06/41] show incoming item on home screen --- apps/photos/src/pages/gallery/index.tsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/apps/photos/src/pages/gallery/index.tsx b/apps/photos/src/pages/gallery/index.tsx index c24ccf9eb1..2fdea92dd2 100644 --- a/apps/photos/src/pages/gallery/index.tsx +++ b/apps/photos/src/pages/gallery/index.tsx @@ -492,15 +492,6 @@ export default function Gallery() { return true; } - // shared files can only be seen in their respective collection - if (isSharedFile(user, item)) { - if (activeCollection === item.collectionID) { - return true; - } else { - return false; - } - } - // archived collections files can only be seen in their respective collection if (archivedCollections.has(item.collectionID)) { if (activeCollection === item.collectionID) { From d63eaf3116ba775d3439c30d8c5c60284dbb0c95 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 4 Jul 2023 11:38:11 +0530 Subject: [PATCH 07/41] run post handleCollectionOps even when toProcessFiles are zero --- apps/photos/src/pages/gallery/index.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/photos/src/pages/gallery/index.tsx b/apps/photos/src/pages/gallery/index.tsx index 2fdea92dd2..16c5c3ccaf 100644 --- a/apps/photos/src/pages/gallery/index.tsx +++ b/apps/photos/src/pages/gallery/index.tsx @@ -689,15 +689,15 @@ export default function Gallery() { : selectedFiles.filter( (file) => file.ownerID === user.id ); - if (toProcessFiles.length === 0) { - return; + if (toProcessFiles.length > 0) { + await handleCollectionOps( + ops, + collection, + toProcessFiles, + selected.collectionID + ); } - await handleCollectionOps( - ops, - collection, - toProcessFiles, - selected.collectionID - ); + clearSelection(); await syncWithRemote(false, true); setActiveCollection(collection.id); From 94078483a78bb181a1c7b476b1ac2798fe61db3b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 4 Jul 2023 11:48:08 +0530 Subject: [PATCH 08/41] show shared file in search screen --- apps/photos/src/pages/gallery/index.tsx | 5 ----- apps/photos/src/services/searchService.ts | 21 ++++----------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/apps/photos/src/pages/gallery/index.tsx b/apps/photos/src/pages/gallery/index.tsx index 16c5c3ccaf..6621eb5a61 100644 --- a/apps/photos/src/pages/gallery/index.tsx +++ b/apps/photos/src/pages/gallery/index.tsx @@ -53,7 +53,6 @@ import { downloadFiles, getSelectedFiles, getUniqueFiles, - isSharedFile, mergeMetadata, sortFiles, } from 'utils/file'; @@ -444,10 +443,6 @@ export default function Gallery() { // SEARCH MODE if (isInSearchMode) { - // shared files are not searchable - if (isSharedFile(user, item)) { - return false; - } if ( search?.date && !isSameDayAnyYear(search.date)( diff --git a/apps/photos/src/services/searchService.ts b/apps/photos/src/services/searchService.ts index a22c0279ed..db55354049 100644 --- a/apps/photos/src/services/searchService.ts +++ b/apps/photos/src/services/searchService.ts @@ -22,8 +22,6 @@ import { } from 'utils/search'; import { Person, Thing } from 'types/machineLearning'; import { getUniqueFiles } from 'utils/file'; -import { User } from 'types/user'; -import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { getLatestEntities } from './entityService'; import { LocationTag, LocationTagData, EntityType } from 'types/entity'; @@ -66,7 +64,6 @@ function convertSuggestionsToOptions( suggestions: Suggestion[], files: EnteFile[] ) { - const user = getData(LS_KEYS.USER) as User; const previewImageAppendedOptions: SearchOption[] = suggestions .map((suggestion) => ({ suggestion, @@ -74,7 +71,7 @@ function convertSuggestionsToOptions( })) .map(({ suggestion, searchQuery }) => { const resultFiles = getUniqueFiles( - files.filter((file) => isSearchedFile(user, file, searchQuery)) + files.filter((file) => isSearchedFile(file, searchQuery)) ); return { ...suggestion, @@ -260,21 +257,14 @@ function searchCollection( } function searchFilesByName(searchPhrase: string, files: EnteFile[]) { - const user = getData(LS_KEYS.USER) as User; - if (!user) return []; - return files.filter( - (file) => - file.ownerID === user.id && - file.metadata.title.toLowerCase().includes(searchPhrase) + return files.filter((file) => + file.metadata.title.toLowerCase().includes(searchPhrase) ); } function searchFilesByCaption(searchPhrase: string, files: EnteFile[]) { - const user = getData(LS_KEYS.USER) as User; - if (!user) return []; return files.filter( (file) => - file.ownerID === user.id && file.pubMagicMetadata && file.pubMagicMetadata.data.caption ?.toLowerCase() @@ -324,13 +314,10 @@ async function searchThing(searchPhrase: string) { ); } -function isSearchedFile(user: User, file: EnteFile, search: Search) { +function isSearchedFile(file: EnteFile, search: Search) { if (search?.collection) { return search.collection === file.collectionID; } - if (file.ownerID !== user.id) { - return false; - } if (search?.date) { return isSameDayAnyYear(search.date)( From d1b9367cf820ea58541e4957c44e664c46c8c6d2 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 4 Jul 2023 12:09:08 +0530 Subject: [PATCH 09/41] remove isIncomingSharedCollection logic and use isOwnFile logic to show icons in PhotoViewer --- apps/photos/src/components/PhotoFrame.tsx | 3 - .../src/components/PhotoViewer/index.tsx | 58 +++++++++++-------- apps/photos/src/pages/gallery/index.tsx | 4 -- apps/photos/src/pages/shared-albums/index.tsx | 1 - 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/apps/photos/src/components/PhotoFrame.tsx b/apps/photos/src/components/PhotoFrame.tsx index 31730fe1ff..5f22032e2e 100644 --- a/apps/photos/src/components/PhotoFrame.tsx +++ b/apps/photos/src/components/PhotoFrame.tsx @@ -45,7 +45,6 @@ interface Props { deletedFileIds?: Set; setDeletedFileIds?: (value: Set) => void; activeCollection: number; - isIncomingSharedCollection?: boolean; enableDownload?: boolean; fileToCollectionsMap: Map; collectionNameMap: Map; @@ -61,7 +60,6 @@ const PhotoFrame = ({ deletedFileIds, setDeletedFileIds, activeCollection, - isIncomingSharedCollection, enableDownload, fileToCollectionsMap, collectionNameMap, @@ -529,7 +527,6 @@ const PhotoFrame = ({ favItemIds={favItemIds} deletedFileIds={deletedFileIds} setDeletedFileIds={setDeletedFileIds} - isIncomingSharedCollection={isIncomingSharedCollection} isTrashCollection={activeCollection === TRASH_SECTION} isHiddenCollection={activeCollection === HIDDEN_SECTION} enableDownload={enableDownload} diff --git a/apps/photos/src/components/PhotoViewer/index.tsx b/apps/photos/src/components/PhotoViewer/index.tsx index 1296fcd9d3..3c0becb8ce 100644 --- a/apps/photos/src/components/PhotoViewer/index.tsx +++ b/apps/photos/src/components/PhotoViewer/index.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useRef, useState } from 'react'; +import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'; import Photoswipe from 'photoswipe'; import PhotoswipeUIDefault from 'photoswipe/dist/photoswipe-ui-default'; import classnames from 'classnames'; @@ -43,6 +43,7 @@ import { t } from 'i18next'; import { getParsedExifData } from 'services/upload/exifService'; import { getFileType } from 'services/typeDetectionService'; import { ConversionFailedNotification } from './styledComponents/ConversionFailedNotification'; +import { GalleryContext } from 'pages/gallery'; interface PhotoswipeFullscreenAPI { enter: () => void; @@ -71,7 +72,6 @@ interface Iprops { favItemIds: Set; deletedFileIds: Set; setDeletedFileIds?: (value: Set) => void; - isIncomingSharedCollection: boolean; isTrashCollection: boolean; isHiddenCollection: boolean; enableDownload: boolean; @@ -99,10 +99,14 @@ function PhotoViewer(props: Iprops) { const publicCollectionGalleryContext = useContext( PublicCollectionGalleryContext ); + + const galleryContext = useContext(GalleryContext); const appContext = useContext(AppContext); const exifExtractionInProgress = useRef(null); - const [shouldShowCopyOption] = useState(isClipboardItemPresent()); + const shouldShowCopyOption = useMemo(() => isClipboardItemPresent(), []); + + const [isOwnFile, setIsOwnFile] = useState(false); useEffect(() => { if (!pswpElement) return; @@ -245,6 +249,13 @@ function PhotoViewer(props: Iprops) { setIsFav(isInFav(file)); } + function updateIsOwnFile(file: EnteFile) { + const isOwnFile = + !publicCollectionGalleryContext.accessedThroughSharedURL && + galleryContext.user?.id === file.ownerID; + setIsOwnFile(isOwnFile); + } + const openPhotoSwipe = () => { const { items, currentIndex } = props; const options = { @@ -308,6 +319,7 @@ function PhotoViewer(props: Iprops) { if (!photoSwipe?.currItem) return; const currItem = photoSwipe.currItem as EnteFile; updateFavButton(currItem); + updateIsOwnFile(currItem); if (currItem.metadata.fileType !== FILE_TYPE.IMAGE) { setExif({ key: currItem.src, value: null }); return; @@ -370,8 +382,9 @@ function PhotoViewer(props: Iprops) { const onFavClick = async (file: EnteFile) => { try { if ( + !file || props.isTrashCollection || - props.isIncomingSharedCollection || + !isOwnFile || props.isHiddenCollection ) { return; @@ -408,11 +421,7 @@ function PhotoViewer(props: Iprops) { }; const confirmTrashFile = (file: EnteFile) => { - if ( - !file || - props.isIncomingSharedCollection || - props.isTrashCollection - ) { + if (!file || !isOwnFile || props.isTrashCollection) { return; } appContext.setDialogMessage(getTrashFileMessage(() => trashFile(file))); @@ -599,19 +608,18 @@ function PhotoViewer(props: Iprops) { )} - {!props.isIncomingSharedCollection && - !props.isTrashCollection && ( - - )} + {isOwnFile && !props.isTrashCollection && ( + + )} - {!props.isIncomingSharedCollection && + {isOwnFile && !props.isTrashCollection && !props.isHiddenCollection && (