This commit is contained in:
Manav Rathi
2025-04-04 18:00:14 +05:30
parent 93ad3d65fd
commit 1b59ea1377
3 changed files with 75 additions and 58 deletions

View File

@@ -53,6 +53,10 @@ import {
PeopleEmptyState,
SearchResultsHeader,
} from "ente-new/photos/components/gallery";
import {
constructEmailList,
constructUserIDToEmailMap,
} from "ente-new/photos/components/gallery/helpers";
import {
useGalleryReducer,
type GalleryBarMode,
@@ -107,8 +111,6 @@ import { FileWithPath } from "react-dropzone";
import { Trans } from "react-i18next";
import {
addToFavorites,
constructEmailList,
constructUserIDToEmailMap,
createAlbum,
createUnCategorizedCollection,
removeFromFavorites,

View File

@@ -37,7 +37,6 @@ import {
groupFilesByCollectionID,
sortFiles,
} from "ente-new/photos/services/files";
import type { FamilyData } from "ente-new/photos/services/user-details";
import HTTPService from "ente-shared/network/HTTPService";
import { getData } from "ente-shared/storage/localStorage";
import { getToken } from "ente-shared/storage/localStorage/helpers";
@@ -724,58 +723,3 @@ export async function unhideToCollection(
throw e;
}
}
export const constructUserIDToEmailMap = (
user: User,
collections: Collection[],
): Map<number, string> => {
try {
const userIDToEmailMap = new Map<number, string>();
collections.forEach((item) => {
const { owner, sharees } = item;
if (user.id !== owner.id && owner.email) {
userIDToEmailMap.set(owner.id, owner.email);
}
if (sharees) {
sharees.forEach((item) => {
if (item.id !== user.id)
userIDToEmailMap.set(item.id, item.email);
});
}
});
return userIDToEmailMap;
} catch (e) {
log.error("Error Mapping UserId to email:", e);
return new Map<number, string>();
}
};
export const constructEmailList = (
user: User,
collections: Collection[],
familyData: FamilyData,
): string[] => {
const emails = collections
.map((item) => {
const { owner, sharees } = item;
if (owner.email && item.owner.id !== user.id) {
return [item.owner.email];
} else {
if (!sharees?.length) {
return [];
}
const shareeEmails = item.sharees
.filter((sharee) => sharee.email !== user.email)
.map((sharee) => sharee.email);
return shareeEmails;
}
})
.flat();
// adding family members
if (familyData) {
const family = familyData.members.map((member) => member.email);
emails.push(...family);
}
return Array.from(new Set(emails));
};

View File

@@ -0,0 +1,71 @@
/**
* @file code that really belongs to pages/gallery.tsx itself, but it written
* here in a separate file so that we can write in this package that has
* TypeScript strict mode enabled.
*
* Once the original gallery.tsx is strict mode, this code can be inlined back
* there.
*
* Separate from index.tsx so that it can export non-(React-)components, which
* is a needed for fast refresh to work.
*/
import log from "ente-base/log";
import type { Collection } from "ente-media/collection";
import type { FamilyData } from "ente-new/photos/services/user-details";
import type { User } from "ente-shared/user/types";
export const constructUserIDToEmailMap = (
user: User,
collections: Collection[],
): Map<number, string> => {
try {
const userIDToEmailMap = new Map<number, string>();
collections.forEach((item) => {
const { owner, sharees } = item;
if (user.id !== owner.id && owner.email) {
userIDToEmailMap.set(owner.id, owner.email);
}
if (sharees) {
sharees.forEach((item) => {
if (item.id !== user.id)
userIDToEmailMap.set(item.id, item.email);
});
}
});
return userIDToEmailMap;
} catch (e) {
log.error("Error Mapping UserId to email:", e);
return new Map<number, string>();
}
};
export const constructEmailList = (
user: User,
collections: Collection[],
familyData: FamilyData,
): string[] => {
const emails = collections
.map((item) => {
const { owner, sharees } = item;
if (owner.email && item.owner.id !== user.id) {
return [item.owner.email];
} else {
if (!sharees?.length) {
return [];
}
const shareeEmails = item.sharees
.filter((sharee) => sharee.email !== user.email)
.map((sharee) => sharee.email);
return shareeEmails;
}
})
.flat();
// adding family members
if (familyData) {
const family = familyData.members.map((member) => member.email);
emails.push(...family);
}
return Array.from(new Set(emails));
};