π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add contact colors to avatar backgrounds in comments and likes sidebars
Anand Baburajan44718c9330ac
diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsxindex 7dadcd6914..cf8520b75e 100644--- a/web/packages/gallery/components/viewer/CommentsSidebar.tsx+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx@@ -15,6 +15,7 @@ import {import { type ModalVisibilityProps } from "ente-base/components/utils/modal";import log from "ente-base/log";import { downloadManager } from "ente-gallery/services/download";+import { getAvatarColor } from "ente-gallery/utils/avatar-colors";import type { EnteFile } from "ente-media/file";import { getCollectionByID } from "ente-new/photos/services/collection";import type { CollectionSummaries } from "ente-new/photos/services/collection-summary";@@ -204,17 +205,13 @@ const CommentHeader: React.FC<CommentHeaderProps> = ({}) => (<CommentHeaderContainer><Avatar- sx={(theme) => ({+ sx={{width: avatarSize,height: avatarSize,fontSize: 14,- bgcolor: "#E0E0E0",- color: "#666",- ...theme.applyStyles("dark", {- bgcolor: "rgba(255, 255, 255, 0.16)",- color: "rgba(255, 255, 255, 0.7)",- }),- })}+ bgcolor: getAvatarColor(userName),+ color: "#fff",+ }}>{userName[0]?.toUpperCase()}</Avatar>@@ -1676,7 +1673,12 @@ const OwnTimestamp = styled(Typography)(({ theme }) => ({}));// Comment Bubbles-const CommentBubbleWrapper = styled(Box)<{+const CommentBubbleWrapper = styled(Box, {+ shouldForwardProp: (prop) =>+ !["isOwn", "isFirstOwn", "isLastOwn", "isHighlighted"].includes(+ prop as string,+ ),+})<{isOwn: boolean;isFirstOwn?: boolean;isLastOwn?: boolean;@@ -1698,7 +1700,9 @@ const CommentBubbleInner = styled(Box)(() => ({maxWidth: 320,}));-const CommentBubble = styled(Box)<{ isOwn: boolean }>(({ isOwn, theme }) => ({+const CommentBubble = styled(Box, {+ shouldForwardProp: (prop) => prop !== "isOwn",+})<{ isOwn: boolean }>(({ isOwn, theme }) => ({backgroundColor: isOwn ? "#0DAF35" : "#F0F0F0",borderRadius: isOwn ? "20px 6px 20px 20px" : "6px 20px 20px 20px",padding: "20px 40px 20px 20px",@@ -1707,27 +1711,27 @@ const CommentBubble = styled(Box)<{ isOwn: boolean }>(({ isOwn, theme }) => ({...(!isOwn && theme.applyStyles("dark", { backgroundColor: "#363636" })),}));-const CommentText = styled(Typography)<{ isOwn: boolean }>(- ({ isOwn, theme }) => ({- color: isOwn ? "#fff" : "#000",- fontSize: 14,- whiteSpace: "pre-wrap",- overflowWrap: "break-word",- ...(!isOwn && theme.applyStyles("dark", { color: "#fff" })),- }),-);+const CommentText = styled(Typography, {+ shouldForwardProp: (prop) => prop !== "isOwn",+})<{ isOwn: boolean }>(({ isOwn, theme }) => ({+ color: isOwn ? "#fff" : "#000",+ fontSize: 14,+ whiteSpace: "pre-wrap",+ overflowWrap: "break-word",+ ...(!isOwn && theme.applyStyles("dark", { color: "#fff" })),+}));-const QuotedReplyContainer = styled(Box)<{ isOwn: boolean }>(- ({ isOwn, theme }) => ({- borderLeft: `3px solid ${isOwn ? "rgba(255,255,255,0.5)" : "#ccc"}`,- paddingLeft: 10,- marginBottom: 16,- ...(!isOwn &&- theme.applyStyles("dark", {- borderLeft: "3px solid rgba(255, 255, 255, 0.3)",- })),- }),-);+const QuotedReplyContainer = styled(Box, {+ shouldForwardProp: (prop) => prop !== "isOwn",+})<{ isOwn: boolean }>(({ isOwn, theme }) => ({+ borderLeft: `3px solid ${isOwn ? "rgba(255,255,255,0.5)" : "#ccc"}`,+ paddingLeft: 10,+ marginBottom: 16,+ ...(!isOwn &&+ theme.applyStyles("dark", {+ borderLeft: "3px solid rgba(255, 255, 255, 0.3)",+ })),+}));// Actionsconst ActionsContainer = styled(Box)(({ theme }) => ({diff --git a/web/packages/gallery/components/viewer/LikesSidebar.tsx b/web/packages/gallery/components/viewer/LikesSidebar.tsxindex 24d9b40727..9e82d61b21 100644--- a/web/packages/gallery/components/viewer/LikesSidebar.tsx+++ b/web/packages/gallery/components/viewer/LikesSidebar.tsx@@ -12,6 +12,7 @@ import {import { type ModalVisibilityProps } from "ente-base/components/utils/modal";import log from "ente-base/log";import { downloadManager } from "ente-gallery/services/download";+import { getAvatarColor } from "ente-gallery/utils/avatar-colors";import type { EnteFile } from "ente-media/file";import type { CollectionSummaries } from "ente-new/photos/services/collection-summary";import { type UnifiedReaction } from "ente-new/photos/services/social";@@ -495,18 +496,13 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({likers.map((liker) => (<LikerRow key={liker.id}><Avatar- sx={(theme) => ({+ sx={{width: 32,height: 32,fontSize: 14,- bgcolor: "#E0E0E0",- color: "#666",- ...theme.applyStyles("dark", {- bgcolor:- "rgba(255, 255, 255, 0.16)",- color: "rgba(255, 255, 255, 0.7)",- }),- })}+ bgcolor: getAvatarColor(liker.userName),+ color: "#fff",+ }}>{liker.userName[0]?.toUpperCase() ?? "?"}</Avatar>diff --git a/web/packages/gallery/utils/avatar-colors.ts b/web/packages/gallery/utils/avatar-colors.tsnew file mode 100644index 0000000000..a8d672e931--- /dev/null+++ b/web/packages/gallery/utils/avatar-colors.ts@@ -0,0 +1,44 @@+/**+ * Avatar colors matching the mobile app's contact colors.+ *+ * These colors are used to give users a consistent colored avatar+ * based on their identifier (email or user ID).+ */+export const avatarColors = [+ "#76549A", // Purple+ "#DF7861", // Coral+ "#94B49F", // Sage green+ "#87A2FB", // Periwinkle blue+ "#C689C6", // Orchid+ "#937DC2", // Soft purple+ "#325288", // Deep blue+ "#85B4E0", // Sky blue+ "#C1A3A3", // Dusty rose+ "#E1A059", // Amber+ "#426165", // Teal+ "#6B77B2", // Slate blue+ "#957FEF", // Violet+ "#DD9DE2", // Pink+ "#82AB8B", // Forest green+ "#9BBBE8", // Light blue+ "#8FBEBE", // Seafoam+ "#8AC3A1", // Mint+ "#A8B0F2", // Lavender+ "#B0C695", // Lime green+ "#E99AAD", // Rose+ "#D18484", // Salmon+ "#78B5A7", // Cyan+];++/**+ * Get a consistent avatar color for a user based on their email or userName.+ *+ * Uses the same algorithm as the mobile app: the string length modulo the+ * number of available colors determines the color index.+ *+ * @param identifier - The user's email or userName (any string)+ * @returns A hex color string from the avatar colors palette+ */+export const getAvatarColor = (identifier: string): string => {+ return avatarColors[identifier.length % avatarColors.length]!;+};