π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add social comments overlay
Anand Baburajana3d7de5b89d0
diff --git a/web/apps/albums/src/public-album/viewer/components/CommentsSidebar.tsx b/web/apps/albums/src/public-album/viewer/components/CommentsSidebar.tsxindex 28c54a4ce3..3bf012813a 100644--- a/web/apps/albums/src/public-album/viewer/components/CommentsSidebar.tsx+++ b/web/apps/albums/src/public-album/viewer/components/CommentsSidebar.tsx@@ -25,10 +25,11 @@ import {Typography,} from "@mui/material";import { type ModalVisibilityProps } from "ente-base/components/utils/modal";+import { formatTimeAgo } from "ente-base/date";import type { PublicAlbumsCredentials } from "ente-base/http";import log from "ente-base/log";import type { EnteFile } from "ente-media/file";-import i18n, { t } from "i18next";+import { t } from "i18next";import React, {useCallback,useEffect,@@ -165,36 +166,6 @@ interface CollectionInfo {// Utility Functions// =============================================================================-const formatTimeAgo = (timestampMicros: number): string => {- // Server timestamps are in microseconds, convert to milliseconds- const timestampMs = Math.floor(timestampMicros / 1000);- const now = Date.now();- const diff = now - timestampMs;- const minutes = Math.floor(diff / 60000);- if (minutes < 1) return t("just_now");- if (minutes < 60) return t("minutes_ago", { count: minutes });- const hours = Math.floor(minutes / 60);- if (hours < 24) return t("hours_ago", { count: hours });- const days = Math.floor(hours / 24);- if (days < 7) return t("days_ago", { count: days });-- // For 7+ days, show actual date using locale-aware formatting- const date = new Date(timestampMs);- const currentYear = new Date(now).getFullYear();- const locale = i18n.language;- if (date.getFullYear() === currentYear) {- return date.toLocaleDateString(locale, {- month: "short",- day: "numeric",- });- }- return date.toLocaleDateString(locale, {- month: "short",- day: "numeric",- year: "numeric",- });-};-const getParentComment = (parentID: string | undefined,comments: Comment[],diff --git a/web/apps/social/src/components/SocialFileViewer.tsx b/web/apps/social/src/components/SocialFileViewer.tsxindex 94801c05dd..e6c99efbb5 100644--- a/web/apps/social/src/components/SocialFileViewer.tsx+++ b/web/apps/social/src/components/SocialFileViewer.tsx@@ -2,9 +2,11 @@ import {Cancel01Icon,Comment01Icon,FavouriteIcon,+ Navigation03Icon,} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box } from "@mui/material";+import { formatTimeAgo } from "ente-base/date";import type PhotoSwipe from "photoswipe";import React from "react";import {@@ -26,6 +28,17 @@ const viewerHeaderHeight = 56;const viewerBottomPadding = 72;const defaultPhotoWidth = 900;const defaultPhotoHeight = 680;+const commentsBackground = "#202020";+const commentsSurface = "#2C2C2C";+const commentsSurfaceHover = "#343434";+const commentsOwnerBubble = "#3FA43D";+const commentsMuted = "rgba(244, 244, 244, 0.54)";+const commentsTimestamp = "rgba(255, 255, 255, 0.55)";++interface SocialViewerUser {+ avatarUrl?: string | null;+ name: string;+}export interface SocialViewerPhoto {alt?: string;@@ -38,10 +51,136 @@ export interface SocialViewerPhoto {}interface SocialFileViewerProps {+ currentUser?: SocialViewerUser;onClose: () => void;photo: SocialViewerPhoto;}+interface MockComment {+ id: string;+ author: string;+ avatarUrl?: string | null;+ createdAtMicros: number;+ isOwner?: boolean;+ replyTo?: { author: string; text: string };+ text: string;+}++const minuteMs = 60 * 1000;+const hourMs = 60 * minuteMs;+const dayMs = 24 * hourMs;+const microsForTimestamp = (timestampMs: number) => timestampMs * 1000;+const microsAgo = (durationMs: number) =>+ microsForTimestamp(Date.now() - durationMs);++const mockComments: MockComment[] = [+ {+ id: "mira",+ author: "Mira Sen",+ avatarUrl: "/images/sample-feed-3.jpg",+ createdAtMicros: microsAgo(12 * minuteMs),+ text: "The colors in this shot are so good.",+ },+ {+ id: "you-reply-mira",+ author: "You",+ createdAtMicros: microsAgo(9 * minuteMs),+ isOwner: true,+ replyTo: {+ author: "Mira Sen",+ text: "The colors in this shot are so good.",+ },+ text: "That evening light did all the work.",+ },+ {+ id: "nikhil",+ author: "Nikhil Rao",+ avatarUrl: "/images/sample-feed-5.jpg",+ createdAtMicros: microsAgo(28 * minuteMs),+ text: "This trail needs to be on our next trip list.",+ },+ {+ id: "aparna",+ author: "Aparna Bhatnagar",+ avatarUrl: "/images/sample-feed-4.jpg",+ createdAtMicros: microsAgo(46 * minuteMs),+ text: "The framing is perfect.",+ },+ {+ id: "mira-reply",+ author: "Mira Sen",+ avatarUrl: "/images/sample-feed-3.jpg",+ createdAtMicros: microsAgo(31 * minuteMs),+ replyTo: {+ author: "Aparna Bhatnagar",+ text: "The framing is perfect.",+ },+ text: "Agree, the path pulls you right in.",+ },+ {+ id: "devika",+ author: "Devika Iyer",+ avatarUrl: "/images/sample-feed-2.jpg",+ createdAtMicros: microsAgo(42 * minuteMs),+ text: "Saving this for the weekend plan.",+ },+ {+ id: "you-reply-devika",+ author: "You",+ createdAtMicros: microsAgo(39 * minuteMs),+ isOwner: true,+ replyTo: {+ author: "Devika Iyer",+ text: "Saving this for the weekend plan.",+ },+ text: "Go early if you want the quiet stretch.",+ },+ {+ id: "kabir",+ author: "Kabir Mehta",+ avatarUrl: "/images/sample-feed-1.jpg",+ createdAtMicros: microsAgo(1 * hourMs),+ text: "Looks peaceful. Was it crowded?",+ },+ {+ id: "you-crowd-reply",+ author: "You",+ avatarUrl: "/images/sample-feed-6.jpg",+ createdAtMicros: microsAgo(55 * minuteMs),+ isOwner: true,+ replyTo: {+ author: "Kabir Mehta",+ text: "Looks peaceful. Was it crowded?",+ },+ text: "Not really. We went just after sunrise.",+ },+ {+ id: "samar",+ author: "Samar Jain",+ avatarUrl: "/images/sample-feed-4.jpg",+ createdAtMicros: microsAgo(3 * dayMs),+ text: "The composition makes it feel cinematic.",+ },+ {+ id: "leena",+ author: "Leena Shah",+ avatarUrl: "/images/sample-feed-6.jpg",+ createdAtMicros: microsAgo(8 * dayMs),+ text: "Need the exact location for this one.",+ },+ {+ id: "you-reply-leena",+ author: "You",+ createdAtMicros: microsAgo(8 * dayMs - 34 * minuteMs),+ isOwner: true,+ replyTo: {+ author: "Leena Shah",+ text: "Need the exact location for this one.",+ },+ text: "I will send you the pin.",+ },+];+const viewerActionButtonSx = {alignItems: "center",bgcolor: controlBackground,@@ -61,14 +200,272 @@ const viewerActionButtonSx = {"&:hover": { bgcolor: controlBackgroundHover },};+const SocialAvatar: React.FC<{+ avatarUrl?: string | null;+ name: string;+ size: number;+}> = ({ avatarUrl, name, size }) => (+ <Box+ sx={{+ alignItems: "center",+ bgcolor: avatarUrl ? "transparent" : paleGreen,+ borderRadius: "50%",+ color: green,+ display: "flex",+ flexShrink: 0,+ height: size,+ justifyContent: "center",+ overflow: "hidden",+ width: size,+ }}+ >+ {avatarUrl ? (+ <Box+ component="img"+ alt=""+ src={avatarUrl}+ sx={{+ display: "block",+ height: "100%",+ objectFit: "cover",+ objectPosition: "center",+ width: "100%",+ }}+ />+ ) : (+ <Box+ sx={{+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: Math.max(10, Math.round(size * 0.34)),+ fontWeight: 800,+ lineHeight: 1,+ }}+ >+ {initialsFor(name)}+ </Box>+ )}+ </Box>+);++const CommentItem: React.FC<{ comment: MockComment }> = ({ comment }) => {+ const isOwner = Boolean(comment.isOwner);+ const authorName = firstNameFrom(comment.author);+ const replyAuthorName = comment.replyTo+ ? firstNameFrom(comment.replyTo.author)+ : undefined;+ const timestampLabel = formatTimeAgo(comment.createdAtMicros);+ const timestampDateTime = new Date(+ Math.floor(comment.createdAtMicros / 1000),+ ).toISOString();++ return (+ <Box+ component="li"+ sx={{+ alignItems: isOwner ? "flex-end" : "flex-start",+ display: "flex",+ flexDirection: "column",+ listStyle: "none",+ maxWidth: "100%",+ minWidth: 0,+ width: "100%",+ }}+ >+ <Box+ sx={{+ alignItems: "center",+ display: "flex",+ gap: "10px",+ justifyContent: isOwner ? "flex-end" : "flex-start",+ maxWidth: "min(calc(100vw - 32px), 360px)",+ minWidth: 0,+ width: isOwner ? "auto" : "100%",+ }}+ >+ {!isOwner && (+ <SocialAvatar+ avatarUrl={comment.avatarUrl}+ name={authorName}+ size={28}+ />+ )}+ {isOwner ? (+ <Box+ component="time"+ dateTime={timestampDateTime}+ sx={{+ color: commentsTimestamp,+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 12,+ fontWeight: 600,+ lineHeight: "16px",+ mr: "2px",+ }}+ >+ {timestampLabel}+ </Box>+ ) : (+ <Box+ sx={{+ alignItems: "baseline",+ display: "flex",+ gap: "4px",+ minWidth: 0,+ overflow: "hidden",+ whiteSpace: "nowrap",+ }}+ >+ <Box+ sx={{+ color: textBase,+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 14,+ fontWeight: 750,+ lineHeight: "20px",+ minWidth: 0,+ overflow: "hidden",+ textOverflow: "ellipsis",+ }}+ >+ {authorName}+ </Box>+ <Box+ aria-hidden+ sx={{+ color: commentsTimestamp,+ flexShrink: 0,+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 12,+ fontWeight: 600,+ lineHeight: "16px",+ }}+ >+ β’+ </Box>+ <Box+ component="time"+ dateTime={timestampDateTime}+ sx={{+ color: commentsTimestamp,+ flexShrink: 0,+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 12,+ fontWeight: 600,+ lineHeight: "16px",+ }}+ >+ {timestampLabel}+ </Box>+ </Box>+ )}+ </Box>+ <Box+ className={isOwner ? "green-bg" : undefined}+ sx={{+ bgcolor: isOwner ? commentsOwnerBubble : commentsSurface,+ borderRadius: isOwner+ ? "20px 6px 20px 20px"+ : "6px 20px 20px 20px",+ color: textBase,+ maxWidth: "min(calc(100vw - 72px), 360px)",+ minWidth: 0,+ ml: isOwner ? 0 : "28px",+ mt: isOwner ? "6px" : "12px",+ overflow: "hidden",+ px: "16px",+ py: comment.replyTo ? "16px" : "14px",+ width: "fit-content",+ }}+ >+ {comment.replyTo && (+ <Box+ sx={{+ alignItems: "stretch",+ display: "flex",+ gap: "10px",+ mb: "8px",+ maxWidth: "100%",+ minWidth: 0,+ }}+ >+ <Box+ aria-hidden+ sx={{+ alignSelf: "stretch",+ bgcolor: isOwner+ ? "rgba(255, 255, 255, 0.55)"+ : "#8C8C8C",+ borderRadius: "999px",+ flexShrink: 0,+ width: 3,+ }}+ />+ <Box sx={{ minWidth: 0 }}>+ <Box+ sx={{+ color: "rgba(244, 244, 244, 0.92)",+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 12,+ fontWeight: 750,+ lineHeight: "18px",+ overflow: "hidden",+ textOverflow: "ellipsis",+ whiteSpace: "nowrap",+ }}+ >+ {replyAuthorName}+ </Box>+ <Box+ sx={{+ color: "rgba(244, 244, 244, 0.82)",+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 12,+ fontWeight: 500,+ lineHeight: "17px",+ overflow: "hidden",+ textOverflow: "ellipsis",+ whiteSpace: "nowrap",+ }}+ >+ {comment.replyTo.text}+ </Box>+ </Box>+ </Box>+ )}+ <Box+ sx={{+ color: "rgba(244, 244, 244, 0.94)",+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 14,+ fontWeight: 600,+ lineHeight: "22px",+ overflowWrap: "anywhere",+ whiteSpace: "pre-wrap",+ }}+ >+ {comment.text}+ </Box>+ </Box>+ </Box>+ );+};+export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({+ currentUser,onClose,photo,}) => {+ const [screen, setScreen] = React.useState<"photo" | "comments">("photo");const displayName = firstNameFrom(photo.name);const dateLabel = formatSocialDate(photo.timestampMs);const initials = initialsFor(photo.name);const viewerRootRef = React.useRef<HTMLDivElement | null>(null);+ const currentUserName = currentUser?.name.trim() || "You";React.useEffect(() => {const root = viewerRootRef.current;@@ -172,15 +569,18 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({aria-modal="true"sx={{bgcolor: viewerBackground,+ boxSizing: "border-box",color: textBase,display: "flex",flexDirection: "column",inset: 0,isolation: "isolate",minHeight: "100svh",+ maxWidth: "100vw",overflow: "hidden",+ overflowX: "hidden",position: "fixed",- width: "100vw",+ width: "100%",zIndex: 1300,}}>@@ -393,6 +793,7 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({component="button"type="button"aria-label="Comment on photo"+ onClick={() => setScreen("comments")}sx={viewerActionButtonSx}><HugeiconsIcon@@ -402,6 +803,197 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({/></Box></Box>+ {screen == "comments" && (+ <Box+ sx={{+ bgcolor: commentsBackground,+ color: textBase,+ boxSizing: "border-box",+ display: "flex",+ flexDirection: "column",+ inset: 0,+ maxWidth: "100vw",+ overflow: "hidden",+ overflowX: "hidden",+ position: "fixed",+ width: "100%",+ zIndex: 3,+ }}+ >+ <Box+ component="header"+ sx={{+ alignItems: "center",+ display: "grid",+ flexShrink: 0,+ gridTemplateColumns: "1fr 40px",+ minHeight: 56,+ px: "16px",+ boxSizing: "border-box",+ width: "100%",+ }}+ >+ <Box+ component="h1"+ sx={{+ color: textBase,+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 18,+ fontWeight: 750,+ lineHeight: "24px",+ m: 0,+ }}+ >+ Comments+ </Box>+ <Box+ component="button"+ type="button"+ aria-label="Close comments"+ onClick={() => setScreen("photo")}+ sx={{+ alignItems: "center",+ bgcolor: "transparent",+ border: 0,+ borderRadius: "50%",+ color: controlIcon,+ cursor: "pointer",+ display: "flex",+ height: 28,+ justifyContent: "center",+ justifySelf: "flex-end",+ p: 0,+ width: 28,+ "&:focus-visible": {+ outline: `2px solid ${green}`,+ outlineOffset: 2,+ },+ "&:hover": {+ bgcolor: "transparent",+ color: textBase,+ },+ }}+ >+ <HugeiconsIcon+ icon={Cancel01Icon}+ size={18}+ strokeWidth={1.8}+ />+ </Box>+ </Box>+ <Box+ component="ol"+ sx={{+ display: "flex",+ flex: "1 1 auto",+ flexDirection: "column",+ gap: "22px",+ m: 0,+ boxSizing: "border-box",+ maxWidth: "100%",+ minHeight: 0,+ overflowX: "hidden",+ overflowY: "auto",+ p: "14px 16px 18px",+ width: "100%",+ }}+ >+ {mockComments.map((comment) => (+ <CommentItem key={comment.id} comment={comment} />+ ))}+ </Box>+ <Box+ sx={{+ bgcolor: commentsBackground,+ boxSizing: "border-box",+ flexShrink: 0,+ maxWidth: "100%",+ p: "18px 14px max(12px, env(safe-area-inset-bottom))",+ width: "100%",+ }}+ >+ <Box+ sx={{+ alignItems: "center",+ bgcolor: commentsSurface,+ borderRadius: "999px",+ boxSizing: "border-box",+ display: "grid",+ gap: "8px",+ gridTemplateColumns: "28px minmax(0, 1fr) 36px",+ maxWidth: "100%",+ minHeight: 44,+ minWidth: 0,+ overflow: "hidden",+ p: "4px 4px 4px 6px",+ width: "100%",+ }}+ >+ <SocialAvatar+ avatarUrl={currentUser?.avatarUrl}+ name={currentUserName}+ size={28}+ />+ <Box+ component="input"+ aria-label="Add a comment"+ placeholder="Add a comment..."+ sx={{+ appearance: "none",+ bgcolor: "transparent",+ border: 0,+ color: textBase,+ fontFamily:+ '"Inter Variable", Inter, sans-serif',+ fontSize: 14,+ fontWeight: 600,+ lineHeight: "20px",+ minWidth: 0,+ outline: 0,+ p: 0,+ width: "100%",+ "&::placeholder": {+ color: commentsMuted,+ opacity: 1,+ },+ }}+ />+ <Box+ component="button"+ type="button"+ aria-label="Send comment"+ sx={{+ alignItems: "center",+ bgcolor: commentsSurfaceHover,+ border: 0,+ borderRadius: "50%",+ color: controlIcon,+ cursor: "pointer",+ display: "flex",+ height: 36,+ justifyContent: "center",+ p: 0,+ width: 36,+ "&:focus-visible": {+ outline: `2px solid ${green}`,+ outlineOffset: 2,+ },+ "&:hover": {+ bgcolor: "rgba(255, 255, 255, 0.14)",+ },+ }}+ >+ <HugeiconsIcon+ icon={Navigation03Icon}+ size={20}+ strokeWidth={1.8}+ />+ </Box>+ </Box>+ </Box>+ </Box>+ )}</Box>);};diff --git a/web/apps/social/src/screens/HomeScreen.tsx b/web/apps/social/src/screens/HomeScreen.tsxindex 2fa5dedc71..2bdd5735e4 100644--- a/web/apps/social/src/screens/HomeScreen.tsx+++ b/web/apps/social/src/screens/HomeScreen.tsx@@ -403,6 +403,10 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({</Box>{selectedPhoto && (<SocialFileViewer+ currentUser={{+ avatarUrl: profile.avatarUrl,+ name: initialsSource,+ }}photo={selectedPhoto}onClose={() => setSelectedPhoto(null)}/>diff --git a/web/apps/social/src/screens/ProfileScreen.tsx b/web/apps/social/src/screens/ProfileScreen.tsxindex fb52e86072..4014a1ba38 100644--- a/web/apps/social/src/screens/ProfileScreen.tsx+++ b/web/apps/social/src/screens/ProfileScreen.tsx@@ -880,6 +880,10 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({</Box>{selectedPhoto && (<SocialFileViewer+ currentUser={{+ avatarUrl: profile.avatarUrl,+ name: displayName,+ }}photo={selectedPhoto}onClose={() => setSelectedPhoto(null)}/>diff --git a/web/packages/base/date.ts b/web/packages/base/date.tsindex 1aea5aa2b1..ec9d0e4b8c 100644--- a/web/packages/base/date.ts+++ b/web/packages/base/date.ts@@ -1,3 +1,5 @@+import i18n, { t } from "i18next";+/*** Return `true` if both the given dates have the same day.*/@@ -5,3 +7,57 @@ export const isSameDay = (first: Date, second: Date) =>first.getFullYear() === second.getFullYear() &&first.getMonth() === second.getMonth() &&first.getDate() === second.getDate();++const translatedRelativeTime = (+ key: "just_now" | "minutes_ago" | "hours_ago" | "days_ago",+ fallback: string,+ count?: number,+) => {+ const translated = t(key, count === undefined ? undefined : { count });+ return typeof translated != "string" || !translated || translated == key+ ? fallback+ : translated;+};++/**+ * Format a server timestamp in microseconds using the same thresholds as the+ * comments sidebar: relative labels for recent comments, locale dates for older+ * ones.+ */+export const formatTimeAgo = (timestampMicros: number): string => {+ const timestampMs = Math.floor(timestampMicros / 1000);+ const now = Date.now();+ const diff = now - timestampMs;+ const minutes = Math.floor(diff / 60000);+ if (minutes < 1) return translatedRelativeTime("just_now", "just now");+ if (minutes < 60) {+ return translatedRelativeTime(+ "minutes_ago",+ `${minutes}m ago`,+ minutes,+ );+ }+ const hours = Math.floor(minutes / 60);+ if (hours < 24) {+ return translatedRelativeTime("hours_ago", `${hours}h ago`, hours);+ }+ const days = Math.floor(hours / 24);+ if (days < 7) {+ return translatedRelativeTime("days_ago", `${days}d ago`, days);+ }++ const date = new Date(timestampMs);+ const currentYear = new Date(now).getFullYear();+ const locale = i18n.language || "en-US";+ if (date.getFullYear() === currentYear) {+ return date.toLocaleDateString(locale, {+ month: "short",+ day: "numeric",+ });+ }+ return date.toLocaleDateString(locale, {+ month: "short",+ day: "numeric",+ year: "numeric",+ });+};