π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove copied collection summary code from albums
Anand Baburajane238dc7fd362
diff --git a/web/apps/albums/src/gallery/components/viewer/CommentsSidebar.tsx b/web/apps/albums/src/gallery/components/viewer/CommentsSidebar.tsxindex 896e979826..dc20066b7b 100644--- a/web/apps/albums/src/gallery/components/viewer/CommentsSidebar.tsx+++ b/web/apps/albums/src/gallery/components/viewer/CommentsSidebar.tsx@@ -28,7 +28,6 @@ import {deletePublicReaction,getStoredAnonIdentity,} from "@/albums/services/public-reaction";-import type { CollectionSummaries } from "@/photos/services/collection-summary";import i18n, { t } from "i18next";import React, {useCallback,@@ -366,14 +365,6 @@ export interface CommentsSidebarProps extends ModalVisibilityProps {* The currently active collection ID (when viewing from within a collection).*/activeCollectionID?: number;- /**- * A mapping from file IDs to the IDs of collections they belong to.- */- fileNormalCollectionIDs?: Map<number, number[]>;- /**- * Collection summaries indexed by their IDs.- */- collectionSummaries?: CollectionSummaries;/*** The current user's ID.*/@@ -457,8 +448,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({onClose,file,activeCollectionID,- fileNormalCollectionIDs,- collectionSummaries,currentUserID,prefetchedComments,prefetchedReactions,@@ -643,56 +632,22 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({const hasCollectionContext =activeCollectionID !== undefined && activeCollectionID !== 0;- // Get all collections the file belongs to- const fileCollectionIDs = useMemo(() => {+ // Build collection info for the current public album.+ const collectionsInfo = useMemo((): CollectionInfo[] => {if (!file) return [];- return fileNormalCollectionIDs?.get(file.id) ?? [];- }, [file, fileNormalCollectionIDs]);-- const isPublicAlbum = true;- // Build collection info list with comment counts and cover files (shared albums only)- const collectionsInfo = useMemo((): CollectionInfo[] => {- // For public albums, use the file's collection directly- if (isPublicAlbum && file) {- return [- {- id: file.collectionID,- name: "Album",- commentCount:- commentsByCollection- .get(file.collectionID)- ?.filter((c) => !c.isDeleted).length ?? 0,- coverFile: file,- },- ];- }-- return fileCollectionIDs- .filter((collectionID) =>- collectionSummaries- ?.get(collectionID)- ?.attributes.has("shared"),- )- .map((collectionID) => {- const summary = collectionSummaries?.get(collectionID);- return {- id: collectionID,- name: summary?.name ?? `Album ${collectionID}`,- commentCount:- commentsByCollection- .get(collectionID)- ?.filter((c) => !c.isDeleted).length ?? 0,- coverFile: summary?.coverFile,- };- });- }, [- isPublicAlbum,- file,- fileCollectionIDs,- collectionSummaries,- commentsByCollection,- ]);+ return [+ {+ id: file.collectionID,+ name: "Album",+ commentCount:+ commentsByCollection+ .get(file.collectionID)+ ?.filter((c) => !c.isDeleted).length ?? 0,+ coverFile: file,+ },+ ];+ }, [file, commentsByCollection]);// Collections sorted by comment count (descending) for dropdownconst sortedCollectionsInfo = useMemo(() => {@@ -719,7 +674,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({]);// Check if the current user can delete a given comment.- // User can delete if: they authored the comment, OR they are owner/admin of the collection.+ // In public albums, only the original author can delete their comment.const canDeleteComment = useCallback((comment: Comment): boolean => {// Comment author can always delete their own comment@@ -739,25 +694,9 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return true;}}-- // Check if user is owner or admin of the selected collection- const collectionID = selectedCollectionInfo?.id;- if (!collectionID || !collectionSummaries) {- return false;- }-- const summary = collectionSummaries.get(collectionID);- if (!summary) {- return false;- }-- // User is owner (not sharedIncoming) or admin (sharedIncomingAdmin)- return (- !summary.attributes.has("sharedIncoming") ||- summary.attributes.has("sharedIncomingAdmin")- );+ return false;},- [currentUserID, selectedCollectionInfo, collectionSummaries],+ [currentUserID, selectedCollectionInfo],);// Load comments and reactions from prefetched data.@@ -792,23 +731,13 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return currentSelection;}- // Initial selection: find collection with most comments- // Only consider shared collections (non-shared ones won't appear in the UI)- // For public albums, skip the shared check since there's no collectionSummaries+ // Initial selection: find collection with most comments.let maxCount = -1;let bestCollectionID: number | undefined;for (const [collectionID,collectionComments,] of prefetchedComments) {- // Skip non-shared collections (except for public albums)- if (!isPublicAlbum) {- const isShared = collectionSummaries- ?.get(collectionID)- ?.attributes.has("shared");- if (!isShared) continue;- }-const count = collectionComments.filter((c) => !c.isDeleted,).length;@@ -840,8 +769,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({prefetchedReactions,hasCollectionContext,activeCollectionID,- collectionSummaries,- isPublicAlbum,]);// Load comments when the sidebar opens@@ -859,23 +786,13 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({selectedCollectionID === undefined &&commentsByCollection.size > 0) {- // Find the collection with the most comments- // Only consider shared collections (non-shared ones won't appear in the UI)- // For public albums, skip the shared check since there's no collectionSummaries+ // Find the collection with the most comments.let maxCount = -1;let bestCollectionID: number | undefined;for (const [collectionID,collectionComments,] of commentsByCollection) {- // Skip non-shared collections (except for public albums)- if (!isPublicAlbum) {- const isShared = collectionSummaries- ?.get(collectionID)- ?.attributes.has("shared");- if (!isShared) continue;- }-const count = collectionComments.filter((c) => !c.isDeleted,).length;@@ -893,8 +810,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({hasCollectionContext,selectedCollectionID,commentsByCollection,- collectionSummaries,- isPublicAlbum,]);// Update displayed comments when selected collection changes (gallery view)@@ -906,15 +821,15 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}}, [hasCollectionContext, selectedCollectionID, commentsByCollection]);- // Update hasAnonIdentity when collection changes (for public albums)+ // Update hasAnonIdentity when collection changes.useEffect(() => {- if (isPublicAlbum && selectedCollectionInfo) {+ if (selectedCollectionInfo) {const storedIdentity = getStoredAnonIdentity(selectedCollectionInfo.id,);setHasAnonIdentity(!!storedIdentity);}- }, [isPublicAlbum, selectedCollectionInfo]);+ }, [selectedCollectionInfo]);// Fetch thumbnails for each collection's cover fileuseEffect(() => {@@ -971,10 +886,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return;}- // Get stored anon identity for public albums- const storedIdentity = isPublicAlbum- ? getStoredAnonIdentity(selectedCollectionInfo.id)- : undefined;+ const storedIdentity = getStoredAnonIdentity(selectedCollectionInfo.id);// Find comment reactions that are likes from the current user (or anon user)const newLikedComments = new Map<string, string>();@@ -996,7 +908,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({selectedCollectionInfo,reactionsByCollection,currentUserID,- isPublicAlbum,]);const handleSend = async () => {@@ -1189,9 +1100,9 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}};- // Check if user needs to set up identity before commenting (public album without identity)+ // Check if user needs to set up identity before commenting.const needsIdentityToComment =- isPublicAlbum && selectedCollectionInfo && !hasAnonIdentity;+ !!selectedCollectionInfo && !hasAnonIdentity;const handleReply = (commentToReply: Comment) => {setReplyingTo(commentToReply);diff --git a/web/apps/albums/src/gallery/components/viewer/LikesSidebar.tsx b/web/apps/albums/src/gallery/components/viewer/LikesSidebar.tsxindex 7359fee740..4ab8861c70 100644--- a/web/apps/albums/src/gallery/components/viewer/LikesSidebar.tsx+++ b/web/apps/albums/src/gallery/components/viewer/LikesSidebar.tsx@@ -15,7 +15,6 @@ import { downloadManager } from "@/gallery/services/download";import { getAvatarColor } from "@/gallery/utils/avatar-colors";import type { EnteFile } from "ente-media/file";import { getStoredAnonIdentity } from "@/albums/services/public-reaction";-import type { CollectionSummaries } from "@/photos/services/collection-summary";import { t } from "i18next";import React, {useCallback,@@ -119,14 +118,6 @@ export interface LikesSidebarProps extends ModalVisibilityProps {* The currently active collection ID (when viewing from within a collection).*/activeCollectionID?: number;- /**- * A mapping from file IDs to the IDs of collections they belong to.- */- fileNormalCollectionIDs?: Map<number, number[]>;- /**- * Collection summaries indexed by their IDs.- */- collectionSummaries?: CollectionSummaries;/*** The current user's ID.*/@@ -153,8 +144,6 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({onClose,file,activeCollectionID,- fileNormalCollectionIDs,- collectionSummaries,currentUserID,prefetchedReactions,prefetchedUserIDToEmail,@@ -182,39 +171,23 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({const hasCollectionContext =activeCollectionID !== undefined && activeCollectionID !== 0;- // Get shared collections the file belongs to- const fileCollectionIDs = useMemo(() => {+ // Build collection info for the current public album.+ const collectionsInfo = useMemo((): CollectionInfo[] => {if (!file) return [];- const allCollectionIDs = fileNormalCollectionIDs?.get(file.id) ?? [];- // If no collection IDs from fileNormalCollectionIDs (e.g., public album),- // use the file's collection ID directly- if (allCollectionIDs.length === 0) {- return [file.collectionID];- }-- // Filter to only include shared collections- return allCollectionIDs.filter((id) =>- collectionSummaries?.get(id)?.attributes.has("shared"),- );- }, [file, fileNormalCollectionIDs, collectionSummaries]);-- // Build collection info list with like counts and cover files- const collectionsInfo = useMemo((): CollectionInfo[] => {- return fileCollectionIDs.map((collectionID) => {- const summary = collectionSummaries?.get(collectionID);- return {- id: collectionID,- name: summary?.name ?? `Album ${collectionID}`,+ return [+ {+ id: file.collectionID,+ name: "Album",likeCount:reactionsByCollection- .get(collectionID)+ .get(file.collectionID)?.filter((r) => r.reactionType === "green_heart").length ?? 0,- coverFile: summary?.coverFile,- };- });- }, [fileCollectionIDs, collectionSummaries, reactionsByCollection]);+ coverFile: file,+ },+ ];+ }, [file, reactionsByCollection]);// Collections sorted by like count (descending) for dropdownconst sortedCollectionsInfo = useMemo(() => {diff --git a/web/apps/albums/src/pages/index.tsx b/web/apps/albums/src/pages/index.tsxindex 5a61cd8c7c..b041a4aced 100644--- a/web/apps/albums/src/pages/index.tsx+++ b/web/apps/albums/src/pages/index.tsx@@ -67,7 +67,6 @@ import {GalleryItemsHeaderAdapter,GalleryItemsSummary,} from "@/photos/components/gallery/ListHeader";-import { PseudoCollectionID } from "@/photos/services/collection-summary";import { usePhotosAppContext } from "@/photos/types/context";import { t } from "i18next";import dynamic from "next/dynamic";@@ -129,6 +128,8 @@ const loadShareService = () => import("@/gallery/services/share");const loadJoinPublicAlbumRedirect = () =>import("@/public-album/services/join-public-album-redirect");+const publicAlbumAllFilesCollectionID = 0;+export default function PublicCollectionGallery() {const { showMiniDialog, onGenericError } = useBaseContext();const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();@@ -742,7 +743,7 @@ export default function PublicCollectionGallery() {enableSelect={downloadEnabled}selected={selected}setSelected={setSelected}- activeCollectionID={PseudoCollectionID.all}+ activeCollectionID={publicAlbumAllFilesCollectionID}onAddSaveGroup={onAddSaveGroup}publicAlbumsCredentials={credentials.current}collectionKey={collectionKey.current}diff --git a/web/apps/albums/src/photos/services/collection-summary.ts b/web/apps/albums/src/photos/services/collection-summary.tsdeleted file mode 100644index 0ce77e61ca..0000000000--- a/web/apps/albums/src/photos/services/collection-summary.ts+++ /dev/null@@ -1,259 +0,0 @@-import type { CollectionType } from "ente-media/collection";-import type { EnteFile } from "ente-media/file";--export type CollectionSummaryType =- | CollectionType- | "all"- | "hiddenItems"- | "defaultHidden"- | "archiveItems"- | "trash"- | "userFavorites"- | "sharedIncoming";--export type CollectionSummaryAttribute =- | CollectionSummaryType- | "shared"- | "sharedOutgoing"- | "sharedIncomingViewer"- | "sharedIncomingCollaborator"- | "sharedIncomingAdmin"- | "sharedOnlyViaLink"- | "system"- | "archived"- | "hideFromCollectionBar"- | "pinned"- | "shareePinned";--/**- * ID of the special {@link CollectionSummary} instances that are not backed by- * a real {@link Collection}.- */-export const PseudoCollectionID = {- /**- * The "All" section.- *- * The "All" section is the default view when the user opens the gallery,- * showing them all of their unique non-hidden and non-archived files.- */- all: 0,- /**- * A pseudo-collection containing the individually archived files.- *- * The archive items is a pseudo-collection consisting of all the files- * which have been individually archived. It is what gets shown when the- * user navigates to the "Archive" section.- */- archiveItems: -1,- /**- * Trash.- *- * This pseudo-collection contains items that are in the user's trash. Each- * items corresponds to a file that has been deleted, but has not yet been- * deleted permanently.- *- * As a special case, when the trash pseudo collection is being shown, then- * the corresponding files array will have {@link EnteTrashFile} items- * instead of normal {@link EnteFile} ones.- */- trash: -2,- /**- * A placeholder for the uncategorized collection until the real one comes- * into existence.- *- * [Note: Uncategorized placeholder]- *- * The user's sole "uncategorized" collection is created on demand the first- * time we need to move a file out of the last collection it belonged to- * (yet retain the file).- *- * Until the real uncategorized collection comes into existence, we use this- * dummy placeholder collection as the {@link CollectionSummary} that gets- * shown if the user navigates to the "Uncategorized" section in the UI.- */- uncategorizedPlaceholder: -3,- /**- * A pseudo-collection containing the individually hidden files.- *- * The "Hidden items" is the default pseudo-collection shown in the "Hidden"- * section. It consists of the files that the user has individually hidden.- *- * It is derived by merging all of the user's "default hidden" albums (See:- * Note: Multiple "default" hidden collections]).- *- * In addition to this "Hidden items" pseudo-collection, the "Hidden"- * section also shows other albums that were hidden.- */- hiddenItems: -4,-} as const;--/**- * A massaged version of a collection or a pseudo-collection suitable for being- * directly shown in the UI.- *- * From one perspective, this can be thought of as a- * "CollectionOrPseudoCollection": a group of files listed together in the UI,- * with the files coming from a real "collection" or some special "section".- *- * - In the first case, the underlying listing will be backed by a- * {@link Collection},- *- * - In the second case the files and other attributes comprising the listing- * will be determined by the special case-specific rules for that particular- * pseudo-collection.- *- * However, even when this is backed by a corresponding "real"- * {@link Collection}, it adds some extra attributes that make it easier and- * more efficient for the UI elements to render this collection summary- * directly. So from that perspective, this can be also be thought of as a- * "UICollection".- */-export interface CollectionSummary {- /**- * The ID of the underlying {@link Collection}, or one of the predefined- * {@link PseudoCollectionID}s.- */- id: number;- /**- * The primary "UI" type for the collection or pseudo-collection.- *- * For newer code consider using {@link attributes} instead.- */- type: CollectionSummaryType;- /**- * Various UI related attributes of the collection or pseudo-collection.- *- * This is meant to replace {@link type} gradually. It defines various- * ad-hoc "UI" attributes which make it easier and more efficient for the UI- * elements to render the collection summary in the UI.- */- attributes: Set<CollectionSummaryAttribute>;- /**- * The name of the collection or pseudo-collection surfaced in the UI.- */- name: string;- /**- * The newest file in the collection or pseudo-collection (if any).- */- latestFile: EnteFile | undefined;- /**- * The file to show as the cover for the collection or pseudo-collection.- *- * This can be one of- * - A file explicitly chosen by the user.- * - The latest file.- * - The oldest file (if the user has set a reverse sort on the collection).- */- coverFile: EnteFile | undefined;- /**- * The number of files in the underlying collection, or the number of files- * computed to belong to the pseudo-collection.- */- fileCount: number;- /**- * The time (epoch microseconds) when the collection was last updated. For- * pseudo-collections this will (usually) be the updation time of the latest- * file that it contains.- */- updationTime: number | undefined;- sortPriority: CollectionSummarySortPriority;- order?: number;-}--/**- * Collection summaries, indexed by their IDs.- */-export type CollectionSummaries = Map<number, CollectionSummary>;--/**- * The sort schemes that can be used when we're showing list of collections- * (e.g. in the collection bar).- *- * This is the list of all possible values, see {@link CollectionsSortBy} for- * the type.- */-export const collectionsSortBy = [- "name-asc",- "name-desc",- "creation-time-asc",- "creation-time-desc",- "updation-time-asc",- "updation-time-desc",-] as const;--/**- * Type of individual {@link collectionsSortBy} values.- */-export type CollectionsSortBy = (typeof collectionsSortBy)[number];--/**- * An orderable set collection "priorities".- *- * Collection summaries that need to appear prior to other collection summaries- * get assigned a "priority", which is an otherwise arbitrary integer that only- * serves as a sort priority (higher being prior).- *- * All collections in a higher category appear together, and before collections- * in lower categories. Within each priority, the collections are sorted by the- * applicable {@link CollectionsSortBy}.- */-export const CollectionSummarySortPriority = {- /**- * Currently: "All", "Uncategorized", "Hidden items".- */- system: 9,- favorites: 8,- pinned: 7,- other: 0,-} as const;--/**- * The TypeScript type that restricts the possible values to be one from amongst- * the {@link CollectionSummarySortCategory} constants.- */-export type CollectionSummarySortPriority =- (typeof CollectionSummarySortPriority)[keyof typeof CollectionSummarySortPriority];--export const haveOnlySystemCollections = (- collectionSummaries: CollectionSummaries,-) =>- [...collectionSummaries.values()].every((cs) =>- cs.attributes.has("system"),- );--export const canAddToCollection = ({ attributes }: CollectionSummary) =>- !attributes.has("system") && !attributes.has("sharedIncomingViewer");--export const canMoveToCollection = ({ attributes }: CollectionSummary) =>- !attributes.has("system") && !attributes.has("sharedIncoming");--/**- * Sort an array of collection summaries by the specified sort order.- *- * @param collectionSummaries The array of collection summaries to sort- * @param by The sort order to apply- * @returns A new sorted array of collection summaries- */-export const sortCollectionSummaries = (- collectionSummaries: CollectionSummary[],- by: CollectionsSortBy,-): CollectionSummary[] => {- return [...collectionSummaries].sort((a, b) => {- switch (by) {- case "name-asc":- return a.name.localeCompare(b.name);- case "name-desc":- return b.name.localeCompare(a.name);- case "creation-time-asc":- // Oldest first: lower ID = created earlier.- return a.id - b.id;- case "creation-time-desc":- // Newest first: higher ID = created later.- return b.id - a.id;- case "updation-time-asc":- return (a.updationTime ?? 0) - (b.updationTime ?? 0);- case "updation-time-desc":- return (b.updationTime ?? 0) - (a.updationTime ?? 0);- }- });-};