Skip to content

armgit / ente

Public Imported from GitHub
0

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

Gate comments and reactions feature behind server flag

Anand Baburajan6740518cbfd7
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsx
index d4c1325a1d..f3711cb14d 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx
@@ -1949,6 +1949,8 @@ const ManagePublicCollect: React.FC<ManagePublicLinkSettingProps> = ({
publicURL,
onUpdate,
}) => {
+ const { isCommentsEnabled } = useSettingsSnapshot();
+
const handleCollectSetting = () => {
void onUpdate({ enableCollect: !publicURL.enableCollect });
};
@@ -1965,12 +1967,16 @@ const ManagePublicCollect: React.FC<ManagePublicLinkSettingProps> = ({
checked={publicURL.enableCollect}
onClick={handleCollectSetting}
/>
- <RowButtonDivider />
- <RowSwitch
- label={t("enable_comments")}
- checked={publicURL.enableComment}
- onClick={handleCommentSetting}
- />
+ {isCommentsEnabled && (
+ <>
+ <RowButtonDivider />
+ <RowSwitch
+ label={t("enable_comments")}
+ checked={publicURL.enableComment}
+ onClick={handleCommentSetting}
+ />
+ </>
+ )}
</RowButtonGroup>
</Stack>
);
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index de525a99b9..96cb7f0cd7 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -196,7 +196,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
const { show: showMapDialog, props: mapDialogVisibilityProps } =
useModalVisibility();
const { onGenericError } = useBaseContext();
- const { mapEnabled } = useSettingsSnapshot();
+ const { mapEnabled, isCommentsEnabled } = useSettingsSnapshot();
const { mode: colorSchemeMode, systemMode } = useColorScheme();
const theme = useTheme();
const resolvedMode =
@@ -385,6 +385,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
onJoinAlbum,
enableComment,
}}
+ isCommentsFeatureEnabled={isCommentsEnabled}
onTriggerRemotePull={handleTriggerRemotePull}
onDownload={handleDownload}
onDelete={handleDelete}
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 8c09854726..5dc47260ff 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -353,6 +353,14 @@ export type FileViewerProps = ModalVisibilityProps & {
* Defaults to `true`.
*/
enableComment?: boolean;
+ /**
+ * `true` if the comments and reactions feature is enabled for the user.
+ *
+ * This is controlled by a server-side feature flag. When `false`, the
+ * like and comment buttons will be hidden for logged-in users.
+ * Defaults to `false`.
+ */
+ isCommentsFeatureEnabled?: boolean;
} & Pick<
FileInfoProps,
"collectionNameByID" | "onSelectCollection" | "onSelectPerson"
@@ -396,6 +404,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
collectionKey,
onJoinAlbum,
enableComment = true,
+ isCommentsFeatureEnabled = false,
}) => {
const { onGenericError } = useBaseContext();
@@ -1502,6 +1511,8 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const showSocialButtons = useMemo(() => {
// Show for public albums (no logged-in user).
if (!haveUser) return true;
+ // For logged-in users, check if the comments feature is enabled.
+ if (!isCommentsFeatureEnabled) return false;
// In collection view: check if that specific collection is shared.
if (
activeCollectionID &&
@@ -1513,7 +1524,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
if (collectionSummary?.attributes.has("shared")) return true;
}
return false;
- }, [haveUser, activeCollectionID, collectionSummaries]);
+ }, [haveUser, isCommentsFeatureEnabled, activeCollectionID, collectionSummaries]);
// Check if a file belongs to any shared collection (for gallery view).
const isFileInSharedCollection = useCallback(
@@ -1535,6 +1546,9 @@ export const FileViewer: React.FC<FileViewerProps> = ({
// collection view), this won't be called. This callback is only
// for gallery view where we need to check per-file.
//
+ // For logged-in users, require the comments feature to be enabled.
+ if (!isCommentsFeatureEnabled) return false;
+ //
// If we're in a specific collection context (not gallery view),
// return false - the collection's shared status is what matters,
// not whether the file happens to be in some other shared album.
@@ -1544,7 +1558,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
return isFileInSharedCollection(file.id);
},
- [isFileInSharedCollection, activeCollectionID],
+ [isCommentsFeatureEnabled, isFileInSharedCollection, activeCollectionID],
);
// Compute shared albums the file belongs to and which are liked for the modal
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index 7507f56381..ae0303e5a4 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -1,4 +1,5 @@
import { ensureLocalUser } from "ente-accounts/services/user";
+import { settingsSnapshot } from "./settings";
import { blobCache } from "ente-base/blob-cache";
import {
boxSeal,
@@ -1456,12 +1457,14 @@ export const createPublicURL = async (
collectionID: number,
attributes?: CreatePublicURLAttributes,
): Promise<PublicURL> => {
+ // Only enable comments by default if the feature flag is enabled.
+ const enableComment = settingsSnapshot().isCommentsEnabled;
const res = await fetch(await apiURL("/collections/share-url"), {
method: "POST",
headers: await authenticatedRequestHeaders(),
body: JSON.stringify({
collectionID,
- enableComment: true,
+ enableComment,
...attributes,
}),
});
diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.ts
index 97c2c848ce..fd36195401 100644
--- a/web/packages/new/photos/services/settings.ts
+++ b/web/packages/new/photos/services/settings.ts
@@ -59,6 +59,10 @@ export interface Settings {
* `true` if sharee pin feature is enabled for shared albums.
*/
isShareePinEnabled: boolean;
+ /**
+ * `true` if the comments and reactions feature is enabled.
+ */
+ isCommentsEnabled: boolean;
/**
* `true` if maps are enabled.
@@ -121,6 +125,7 @@ const createDefaultSettings = (): Settings => ({
isAdminRoleEnabled: false,
isSurfacePublicLinkEnabled: false,
isShareePinEnabled: false,
+ isCommentsEnabled: false,
mapEnabled: false,
cfUploadProxyDisabled: false,
castURL: "https://cast.ente.io",
@@ -200,12 +205,22 @@ const FeatureFlags = z.object({
internalUser: z.boolean().nullish().transform(nullToUndefined),
betaUser: z.boolean().nullish().transform(nullToUndefined),
mapEnabled: z.boolean().nullish().transform(nullToUndefined),
+ serverApiFlag: z.number().nullish().transform(nullToUndefined),
castUrl: z.string().nullish().transform(nullToUndefined),
embedUrl: z.string().nullish().transform(nullToUndefined),
customDomain: z.string().nullish().transform(nullToUndefined),
customDomainCNAME: z.string().nullish().transform(nullToUndefined),
});
+/**
+ * Bit flags for server API features.
+ * These correspond to the constants in server/ente/remotestore.go.
+ */
+const ServerApiFlag = {
+ /** Comments feature is enabled. */
+ Comments: 1 << 1,
+};
+
type FeatureFlags = z.infer<typeof FeatureFlags>;
const syncSettingsSnapshotWithLocalStorage = () => {
@@ -216,6 +231,8 @@ const syncSettingsSnapshotWithLocalStorage = () => {
settings.isSurfacePublicLinkEnabled =
(flags?.internalUser ?? false) || isDevBuild;
settings.isShareePinEnabled = (flags?.internalUser ?? false) || isDevBuild;
+ settings.isCommentsEnabled =
+ ((flags?.serverApiFlag ?? 0) & ServerApiFlag.Comments) !== 0;
settings.mapEnabled = flags?.mapEnabled || false;
settings.cfUploadProxyDisabled = savedCFProxyDisabled();
if (flags?.castUrl) settings.castURL = flags.castUrl;