π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refine Space notifications
Anand Baburajand6a0d8a89e2d
diff --git a/web/apps/space/src/components/SpaceMessagesPage.tsx b/web/apps/space/src/components/SpaceMessagesPage.tsxindex 07da76b349..77700ad5d3 100644--- a/web/apps/space/src/components/SpaceMessagesPage.tsx+++ b/web/apps/space/src/components/SpaceMessagesPage.tsx@@ -9,6 +9,7 @@ import {deleteCurrentMessage,loadCurrentMessageConversations,loadCurrentMessageThread,+ loadCurrentSpaceProfile,loadCurrentSpaceFriends,markCurrentMessageLikesRead,markCurrentMessagesRead,@@ -19,7 +20,7 @@ import {type SpaceMessageConversation,} from "services/space";import { useSpaceAppState } from "state/spaceAppState";-import { spaceRoutes } from "utils/spaceRoutes";+import { messageThreadSourceFromQuery, spaceRoutes } from "utils/spaceRoutes";interface SpaceMessagesPageProps {selectedSpaceId?: string;@@ -106,12 +107,24 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({>([]);const [isConversationsLoading, setIsConversationsLoading] =React.useState(true);+ const [isFriendsLoading, setIsFriendsLoading] = React.useState(true);const [isThreadLoading, setIsThreadLoading] = React.useState(false);const [messages, setMessages] = React.useState<SpaceMessage[]>([]);+ const [selectedFriendProfile, setSelectedFriendProfile] =+ React.useState<SpaceMessageConversation["friend"]>();+ const [+ selectedFriendProfileLoadFailedSpaceId,+ setSelectedFriendProfileLoadFailedSpaceId,+ ] = React.useState<string>();const selectedFriendSpaceIdRef = React.useRef<string | undefined>(undefined,);const markedReadSpaceIdRef = React.useRef<string | undefined>(undefined);+ const messageThreadSource = messageThreadSourceFromQuery(router.query.from);+ const closeConversationRoute =+ messageThreadSource == "notifications"+ ? spaceRoutes.notifications+ : spaceRoutes.messages;const selectedConversation = React.useMemo(() =>selectedSpaceId@@ -131,6 +144,11 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({: undefined,[friends, selectedSpaceId],);+ const selectedLoadedFriendProfile =+ selectedFriendProfile &&+ friendSpaceId(selectedFriendProfile) == selectedSpaceId+ ? selectedFriendProfile+ : undefined;const selectedFriendPlaceholder = React.useMemo(() =>selectedSpaceId ? placeholderFriend(selectedSpaceId) : undefined,@@ -139,6 +157,7 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({const selectedFriend =selectedConversation?.friend ??selectedFriendFromFriends ??+ selectedLoadedFriendProfile ??selectedFriendPlaceholder;const selectedFriendSpaceId = selectedFriend? friendSpaceId(selectedFriend)@@ -193,8 +212,8 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({);const closeConversation = React.useCallback(() => {- if (selectedSpaceId) void router.push(spaceRoutes.messages);- }, [router, selectedSpaceId]);+ if (selectedSpaceId) void router.push(closeConversationRoute);+ }, [closeConversationRoute, router, selectedSpaceId]);const appendMessageIfThreadIsCurrent = React.useCallback((spaceId: string, message: SpaceMessage) => {@@ -264,15 +283,27 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({}, [profile, refreshConversations]);React.useEffect(() => {- if (!profile?.spaceId) return;+ if (!profile?.spaceId) {+ setIsFriendsLoading(false);+ return;+ }+ let cancelled = false;+ setIsFriendsLoading(true);void loadCurrentSpaceFriends(profile.spaceId).then((nextFriends) => {- setFriends(nextFriends);+ if (!cancelled) setFriends(nextFriends);}).catch((error: unknown) =>console.error("Failed to load space friends", error),- );+ )+ .finally(() => {+ if (!cancelled) setIsFriendsLoading(false);+ });++ return () => {+ cancelled = true;+ };}, [profile?.spaceId, setFriends]);React.useEffect(() => {@@ -289,17 +320,63 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({markConversationRead(selectedSpaceId);}, [markConversationRead, selectedConversation, selectedSpaceId]);+ const shouldLoadSelectedFriendProfile = Boolean(+ selectedSpaceId &&+ !isConversationsLoading &&+ !isFriendsLoading &&+ !selectedConversation &&+ !selectedFriendFromFriends,+ );++ React.useEffect(() => {+ setSelectedFriendProfile(undefined);+ setSelectedFriendProfileLoadFailedSpaceId(undefined);++ if (!selectedSpaceId || !shouldLoadSelectedFriendProfile) return;++ let cancelled = false;+ void loadCurrentSpaceProfile(selectedSpaceId)+ .then((friend) => {+ if (!cancelled) setSelectedFriendProfile(friend);+ })+ .catch((error: unknown) => {+ console.error("Failed to load selected space profile", error);+ if (!cancelled) {+ setSelectedFriendProfileLoadFailedSpaceId(selectedSpaceId);+ }+ });++ return () => {+ cancelled = true;+ };+ }, [selectedSpaceId, shouldLoadSelectedFriendProfile]);+React.useEffect(() => {if (!selectedSpaceId ||isConversationsLoading ||- selectedConversation+ isFriendsLoading ||+ selectedConversation ||+ selectedFriendFromFriends ||+ selectedLoadedFriendProfile ||+ (shouldLoadSelectedFriendProfile &&+ selectedFriendProfileLoadFailedSpaceId != selectedSpaceId)) {return;}void router.replace(spaceRoutes.messages);- }, [isConversationsLoading, router, selectedConversation, selectedSpaceId]);+ }, [+ isConversationsLoading,+ isFriendsLoading,+ router,+ selectedConversation,+ selectedFriendFromFriends,+ selectedFriendProfileLoadFailedSpaceId,+ selectedLoadedFriendProfile,+ selectedSpaceId,+ shouldLoadSelectedFriendProfile,+ ]);React.useEffect(() => {markedReadSpaceIdRef.current = undefined;@@ -454,6 +531,11 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({}}profile={profile}selectedFriend={selectedFriend}+ threadBackLabel={+ messageThreadSource == "notifications"+ ? "Back to notifications"+ : undefined+ }/></>);diff --git a/web/apps/space/src/components/SpaceNotificationsPage.tsx b/web/apps/space/src/components/SpaceNotificationsPage.tsxindex e70838ebbb..fba29c1718 100644--- a/web/apps/space/src/components/SpaceNotificationsPage.tsx+++ b/web/apps/space/src/components/SpaceNotificationsPage.tsx@@ -83,6 +83,9 @@ export const SpaceNotificationsPage: React.FC = () => {isLoading={isLoading}notifications={notifications}onBack={() => void router.push(spaceRoutes.home)}+ onOpenFriendMessages={(spaceId) =>+ void router.push(spaceRoutes.messageFromNotifications(spaceId))+ }onShareProfileLink={async () => {if (!profile.spaceId) throw new Error("Missing space.");return (await createCurrentProfileLink(profile.spaceId))diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex 7ffa9e08c5..a868930d63 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -1263,7 +1263,7 @@ const AddedFriendToast: React.FC<AddedFriendToastProps> = ({justifyContent: "center",opacity: 0.9,p: 0,- width: 34,+ width: spaceTouchTargetSize,"&:focus-visible": {outline: "2px solid rgba(0 0 0 / 0.72)",outlineOffset: 2,diff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex c27512d6b1..792663f2cd 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -69,6 +69,7 @@ interface MessagesScreenProps {onShareProfileLink?: () => Promise<string>;profile: SetupProfile;selectedFriend?: SpaceMessageConversation["friend"];+ threadBackLabel?: string;}interface MessageContextMenuState {@@ -205,7 +206,7 @@ const conversationPreview = (profile: SetupProfile,) => {const activity = conversation.latestActivity;- if (!activity) return "No messages yet";+ if (!activity) return "Say hello!";if (activity.type == "post_reply") {return "Replied";}@@ -1095,6 +1096,7 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({onShareProfileLink,profile,selectedFriend,+ threadBackLabel = "Back to messages",}) => {const [messageText, setMessageText] = React.useState("");const [messageContextMenu, setMessageContextMenu] =@@ -1432,7 +1434,7 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({<Boxcomponent="button"type="button"- aria-label={isThreadOpen ? "Back to messages" : "Back"}+ aria-label={isThreadOpen ? threadBackLabel : "Back"}onClick={isThreadOpen ? onCloseThread : onBack}sx={{alignItems: "center",diff --git a/web/apps/space/src/screens/NotificationsScreen.tsx b/web/apps/space/src/screens/NotificationsScreen.tsxindex bde5525106..fe3a02c1ad 100644--- a/web/apps/space/src/screens/NotificationsScreen.tsx+++ b/web/apps/space/src/screens/NotificationsScreen.tsx@@ -18,10 +18,13 @@ const textSecondary = "#777777";const rowHover = "#F6F6F6";const dayMs = 24 * 60 * 60 * 1000;+const microsForTimestamp = (timestampMs: number) => timestampMs * 1000;+interface NotificationsScreenProps {isLoading?: boolean;notifications: SpaceNotification[];onBack?: () => void;+ onOpenFriendMessages?: (spaceId: string) => void;onShareProfileLink?: () => Promise<string>;}@@ -41,31 +44,77 @@ interface NotificationGroup {const fullName = (actor: SpaceNotification["actor"]) =>actor.fullName.trim() || actor.username.trim() || "Someone";-const actorSummary = (actors: SpaceNotification["actor"][]) => {- if (actors.length == 0) return "Someone";- const first = fullName(actors[0]!);- if (actors.length == 1) return first;- const second = fullName(actors[1]!);- if (actors.length == 2) return `${first} and ${second}`;- return `${first} and ${actors.length - 1} others`;+const actorSpaceId = (actor: SpaceNotification["actor"]) =>+ actor.spaceId ?? actor.id;++const ActorName: React.FC<{ actor: SpaceNotification["actor"] }> = ({+ actor,+}) => (+ <Box component="span" sx={{ fontWeight: 700 }}>+ {fullName(actor)}+ </Box>+);++const PostLikeText: React.FC<{ actors: SpaceNotification["actor"][] }> = ({+ actors,+}) => {+ if (actors.length == 1) {+ return (+ <>+ <ActorName actor={actors[0]!} /> liked your post.+ </>+ );+ }+ if (actors.length == 2) {+ return (+ <>+ <ActorName actor={actors[0]!} /> and{" "}+ <ActorName actor={actors[1]!} /> liked your post.+ </>+ );+ }+ if (actors.length == 3) {+ return (+ <>+ <ActorName actor={actors[0]!} />,{" "}+ <ActorName actor={actors[1]!} /> and{" "}+ <ActorName actor={actors[2]!} /> liked your post.+ </>+ );+ }++ return (+ <>+ <ActorName actor={actors[0]!} />, <ActorName actor={actors[1]!} />{" "}+ and {actors.length == 4 ? "2" : "2+"} others liked your post.+ </>+ );};-const notificationText = (group: NotificationGroup) => {- const actors = actorSummary(group.actors);+const NotificationText: React.FC<{ group: NotificationGroup }> = ({ group }) => {+ const actor = group.actors[0]!;switch (group.type) {case "friend_add":- return `${actors} became friends with you`;+ return (+ <>+ <ActorName actor={actor} /> is now a friend.+ </>+ );case "friend_remove":- return `${actors} removed you as a friend`;+ return (+ <>+ <ActorName actor={actor} /> is no longer friends with you.+ </>+ );case "post_like":- return `${actors} liked your post`;+ return <PostLikeText actors={group.actors} />;}};const AvatarStack: React.FC<{ actors: SpaceNotification["actor"][] }> = ({actors,}) => (- <Box sx={{ flexShrink: 0, height: 42, position: "relative", width: 42 }}>+ <Box sx={{ flexShrink: 0, height: 44, position: "relative", width: 44 }}>{actors.slice(0, 3).map((actor, index) => (<Boxkey={`${actor.spaceId ?? actor.id}-${index}`}@@ -73,12 +122,12 @@ const AvatarStack: React.FC<{ actors: SpaceNotification["actor"][] }> = ({bgcolor: avatarSkeletonBackground,border: `2px solid ${notificationsBackground}`,borderRadius: "50%",- height: actors.length == 1 ? 42 : 30,+ height: actors.length == 1 ? 44 : 30,left: actors.length == 1 ? 0 : index * 6,overflow: "hidden",position: "absolute",top: actors.length == 1 ? 0 : index * 5,- width: actors.length == 1 ? 42 : 30,+ width: actors.length == 1 ? 44 : 30,zIndex: 3 - index,}}>@@ -91,6 +140,7 @@ const AvatarStack: React.FC<{ actors: SpaceNotification["actor"][] }> = ({display: "block",height: "100%",objectFit: "cover",+ objectPosition: "center",width: "100%",}}/>@@ -156,7 +206,7 @@ const groupSectionNotifications = (items: SpaceNotification[]) => {const key =item.type == "post_like"? `post_like:${item.post?.postId ?? item.id}`- : item.type;+ : item.id;const existing = groups.get(key);if (existing) {existing.actors.push(item.actor);@@ -177,71 +227,108 @@ const groupSectionNotifications = (items: SpaceNotification[]) => {return [...groups.values()].sort((a, b) => b.createdAtMs - a.createdAtMs);};-const NotificationRow: React.FC<{ group: NotificationGroup }> = ({ group }) => (- <Box- component="li"- sx={{- alignItems: "center",- borderRadius: "8px",- display: "grid",- gap: "12px",- gridTemplateColumns: "42px minmax(0, 1fr) auto",- minHeight: 62,- px: "6px",- py: "7px",- "&:hover": { bgcolor: rowHover },- }}- >- <AvatarStack actors={group.actors} />- <Box sx={{ minWidth: 0 }}>+const NotificationRow: React.FC<{+ group: NotificationGroup;+ onOpenFriendMessages?: (spaceId: string) => void;+}> = ({ group, onOpenFriendMessages }) => {+ const postImageUrl = group.post?.imageUrl;+ const friendActivityActor =+ group.type == "post_like" ? undefined : group.actors[0];+ const friendActivitySpaceId = friendActivityActor+ ? actorSpaceId(friendActivityActor)+ : undefined;+ const canOpenFriendMessages = Boolean(+ friendActivitySpaceId && onOpenFriendMessages,+ );++ const openFriendMessages = () => {+ if (!friendActivitySpaceId) return;+ onOpenFriendMessages?.(friendActivitySpaceId);+ };++ return (+ <Box component="li"><Box- component="p"+ component={canOpenFriendMessages ? "button" : "div"}+ type={canOpenFriendMessages ? "button" : undefined}+ onClick={canOpenFriendMessages ? openFriendMessages : undefined}sx={{+ alignItems: "center",+ appearance: "none",+ bgcolor: "transparent",+ border: 0,+ borderRadius: "8px",color: textBase,- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 14,- fontWeight: 650,- lineHeight: "19px",- m: 0,- }}- >- {notificationText(group)}- </Box>- <Box- component="p"- sx={{- color: textSecondary,- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 12,- fontWeight: 500,- lineHeight: "16px",- m: 0,- mt: "2px",+ cursor: canOpenFriendMessages ? "pointer" : "default",+ display: "grid",+ gap: "10px",+ gridTemplateColumns: postImageUrl+ ? "44px minmax(0, 1fr) 44px"+ : "44px minmax(0, 1fr)",+ minHeight: 64,+ p: "8px 0",+ textAlign: "left",+ width: "100%",+ "&:focus-visible": {+ outline: `2px solid ${green}`,+ outlineOffset: 2,+ },+ "&:hover": { bgcolor: rowHover },}}>- {formatTimeAgo(group.createdAtMs)}+ <AvatarStack actors={group.actors} />+ <Box sx={{ minWidth: 0 }}>+ <Box+ component="p"+ sx={{+ color: textBase,+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 14,+ fontWeight: 500,+ lineHeight: "20px",+ m: 0,+ }}+ >+ <NotificationText group={group} />+ </Box>+ <Box+ component="p"+ sx={{+ color: textSecondary,+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 13,+ fontWeight: 500,+ lineHeight: "18px",+ m: 0,+ }}+ >+ {formatTimeAgo(microsForTimestamp(group.createdAtMs))}+ </Box>+ </Box>+ {postImageUrl && (+ <Box+ component="img"+ alt=""+ src={postImageUrl}+ sx={{+ borderRadius: "6px",+ display: "block",+ height: 44,+ objectFit: "cover",+ objectPosition: "center",+ width: 44,+ }}+ />+ )}</Box></Box>- {group.post?.imageUrl && (- <Box- component="img"- alt=""- src={group.post.imageUrl}- sx={{- borderRadius: "6px",- display: "block",- height: 44,- objectFit: "cover",- width: 44,- }}- />- )}- </Box>-);+ );+};-const NotificationSection: React.FC<{ section: NotificationSection }> = ({- section,-}) => {+const NotificationSection: React.FC<{+ onOpenFriendMessages?: (spaceId: string) => void;+ section: NotificationSection;+}> = ({ onOpenFriendMessages, section }) => {const groups = groupSectionNotifications(section.items);if (groups.length == 0) return null;@@ -264,7 +351,11 @@ const NotificationSection: React.FC<{ section: NotificationSection }> = ({</Box><Box component="ul" sx={{ listStyle: "none", m: 0, p: 0 }}>{groups.map((group) => (- <NotificationRow key={group.id} group={group} />+ <NotificationRow+ key={group.id}+ group={group}+ onOpenFriendMessages={onOpenFriendMessages}+ />))}</Box></Box>@@ -275,6 +366,7 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({isLoading = false,notifications,onBack,+ onOpenFriendMessages,onShareProfileLink,}) => {const [isInviteDialogOpen, setIsInviteDialogOpen] = React.useState(false);@@ -354,11 +446,12 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({bgcolor: notificationsBackground,boxSizing: "border-box",display: "grid",- gridTemplateColumns: "44px minmax(0, 1fr) 44px",- height: 58,- px: "10px",+ gridTemplateColumns: `${spaceTouchTargetSize}px 1fr ${spaceTouchTargetSize}px`,+ height: 56,+ px: 2,position: "sticky",top: 0,+ width: "100%",zIndex: 2,}}>@@ -376,7 +469,8 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({cursor: onBack ? "pointer" : "default",display: "flex",height: spaceTouchTargetSize,- justifyContent: "center",+ justifyContent: "flex-start",+ ml: "-2px",p: 0,width: spaceTouchTargetSize,"&:focus-visible": {@@ -488,6 +582,7 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({sections.map((section) => (<NotificationSectionkey={section.title}+ onOpenFriendMessages={onOpenFriendMessages}section={section}/>))diff --git a/web/apps/space/src/utils/spaceRoutes.ts b/web/apps/space/src/utils/spaceRoutes.tsindex cfd78a0beb..7ea404ae61 100644--- a/web/apps/space/src/utils/spaceRoutes.ts+++ b/web/apps/space/src/utils/spaceRoutes.ts@@ -1,5 +1,6 @@export type SetupProfileSource = "login" | "verify";export type ProfileImageFlowSource = "profile" | "settings";+export type MessageThreadSource = "messages" | "notifications";export type VerifyFlow = "login" | "signup";const valueFromQuery = (value: string | string[] | undefined) =>@@ -18,6 +19,8 @@ export const spaceRoutes = {login: "/login",message: (spaceId: string) =>`/app/messages/${encodeURIComponent(spaceId)}`,+ messageFromNotifications: (spaceId: string) =>+ `/app/messages/${encodeURIComponent(spaceId)}?from=notifications`,messages: "/app/messages",notifications: "/app/notifications",onboarding: "/",@@ -62,5 +65,10 @@ export const profileImageFlowSourceFromQuery = (): ProfileImageFlowSource =>valueFromQuery(value) == "settings" ? "settings" : "profile";+export const messageThreadSourceFromQuery = (+ value: string | string[] | undefined,+): MessageThreadSource =>+ valueFromQuery(value) == "notifications" ? "notifications" : "messages";+export const friendSpaceIdFromQuery = (value: string | string[] | undefined) =>valueFromQuery(value) ?? "";