Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update Space email and feed behavior

Anand Baburajan93bd34f968c9
diff --git a/server/mail-templates/space_notification.html b/server/mail-templates/space_notification.html
index bdd2cb3ed2..62a9790e89 100644
--- a/server/mail-templates/space_notification.html
+++ b/server/mail-templates/space_notification.html
@@ -1,7 +1,9 @@
{{define "content"}}
-<p>Hi,</p>
-<p>{{ .Message }}.</p>
-<p>
- <a class="button" href="{{ .AppURL }}" target="_blank">Open Space</a>
-</p>
+<div style="text-align: center;">
+ <p>Hi,</p>
+ <p>{{ .Message }}.</p>
+ <p>
+ <a class="button" href="{{ .AppURL }}" target="_blank">Open Space</a>
+ </p>
+</div>
{{end}}
diff --git a/server/pkg/utils/email/space_notification_template_test.go b/server/pkg/utils/email/space_notification_template_test.go
new file mode 100644
index 0000000000..511d4d45a3
--- /dev/null
+++ b/server/pkg/utils/email/space_notification_template_test.go
@@ -0,0 +1,20 @@
+package email
+
+import (
+ "testing"
+
+ "github.com/ente-io/museum/internal/testutil"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSpaceNotificationTemplateCentersContent(t *testing.T) {
+ testutil.WithServerRoot(t)
+
+ body, err := getMailBodyWithBase("base.html", "space_notification.html", map[string]interface{}{
+ "Message": "@alice liked your post",
+ "AppURL": "https://ente.space/app",
+ })
+ require.NoError(t, err)
+ require.Contains(t, body, `<div style="text-align: center;">`)
+ require.Contains(t, body, "@alice liked your post.")
+}
diff --git a/server/space/controller/notifications.go b/server/space/controller/notifications.go
index 9ab64cf7c8..a7e67c080e 100644
--- a/server/space/controller/notifications.go
+++ b/server/space/controller/notifications.go
@@ -45,10 +45,6 @@ func (n *SpaceEmailSender) send(actorSlug, action, event string, recipientUserID
if n == nil || n.UserRepo == nil || len(recipientUserIDs) == 0 {
return
}
- actorSlug = strings.TrimSpace(actorSlug)
- if actorSlug == "" {
- actorSlug = "A friend"
- }
recipientUserIDs = uniqueUserIDs(recipientUserIDs)
if len(recipientUserIDs) == 0 {
return
@@ -59,7 +55,7 @@ func (n *SpaceEmailSender) send(actorSlug, action, event string, recipientUserID
return
}
- subject := fmt.Sprintf("%s %s", actorSlug, action)
+ subject := spaceEmailSubject(actorSlug, action)
templateData := map[string]interface{}{
"Message": subject,
"AppURL": spaceAppURL(),
@@ -88,6 +84,14 @@ func (n *SpaceEmailSender) send(actorSlug, action, event string, recipientUserID
}
}
+func spaceEmailSubject(actorSlug, action string) string {
+ actorSlug = strings.TrimSpace(actorSlug)
+ if actorSlug == "" {
+ return fmt.Sprintf("A friend %s", action)
+ }
+ return fmt.Sprintf("@%s %s", actorSlug, action)
+}
+
func uniqueUserIDs(userIDs []int64) []int64 {
seen := make(map[int64]struct{}, len(userIDs))
out := make([]int64, 0, len(userIDs))
diff --git a/server/space/controller/notifications_test.go b/server/space/controller/notifications_test.go
index 8d5ad3b998..a3f5ccb6fe 100644
--- a/server/space/controller/notifications_test.go
+++ b/server/space/controller/notifications_test.go
@@ -62,6 +62,12 @@ func requireNoSpaceEmail(t *testing.T, notifier *recordingSpaceEmailNotifier) {
}
}
+func TestSpaceEmailSubjectPrefixesUsernameWithAt(t *testing.T) {
+ require.Equal(t, "@alice liked your post", spaceEmailSubject("alice", "liked your post"))
+ require.Equal(t, "@alice posted a new photo", spaceEmailSubject(" alice ", "posted a new photo"))
+ require.Equal(t, "A friend liked your post", spaceEmailSubject(" ", "liked your post"))
+}
+
func TestPostLikeSendsEmailOnce(t *testing.T) {
_, repos, ctx := setupPostsControllerTest(t)
notifier := newRecordingSpaceEmailNotifier()
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 8c7c730a32..34bd0d9a36 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -69,6 +69,7 @@ const emptyFeedItemGap = "22px";
const feedHorizontalPadding = "16px";
const minimumFeedPhotoFrameAspectRatio = 3 / 4;
const feedMediaLoadRootMargin = "640px 0px";
+const feedLoadMoreRootMargin = "0px 0px 160px 0px";
const feedCaptionTextSx = {
color: textBase,
fontFamily: '"Inter Variable", Inter, sans-serif',
@@ -1317,6 +1318,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
const [isHeaderFocused, setIsHeaderFocused] = useState(false);
const isHeaderHidden = isHeaderTriggered && !isHeaderFocused;
const postInputRef = React.useRef<HTMLInputElement | null>(null);
+ const feedLoadMoreRef = React.useRef<HTMLDivElement | null>(null);
const localPostObjectUrlsRef = React.useRef<Set<string>>(new Set());
const activeLocalPostObjectUrlRef = React.useRef<string | null>(null);
const feedAvatarLoadsInFlightRef = React.useRef<
@@ -1557,6 +1559,44 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
return scheduleScrollPageToTop();
}, [feedScrollRequest]);
+ React.useEffect(() => {
+ if (!hasMoreFeedItems || isFeedLoadingMore || !onLoadMoreFeedItems) {
+ return;
+ }
+
+ const element = feedLoadMoreRef.current;
+ if (!element) return;
+
+ let didRequestLoad = false;
+ const loadMore = () => {
+ if (didRequestLoad) return;
+
+ didRequestLoad = true;
+ void Promise.resolve(onLoadMoreFeedItems()).catch(
+ (error: unknown) => {
+ console.error("Failed to load more space feed", error);
+ },
+ );
+ };
+
+ if (
+ typeof window == "undefined" ||
+ !("IntersectionObserver" in window)
+ ) {
+ loadMore();
+ return;
+ }
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (entries.some((entry) => entry.isIntersecting)) loadMore();
+ },
+ { rootMargin: feedLoadMoreRootMargin },
+ );
+ observer.observe(element);
+ return () => observer.disconnect();
+ }, [hasMoreFeedItems, isFeedLoadingMore, onLoadMoreFeedItems]);
+
const openInviteDialog = () => {
setInviteShareError(null);
setIsInviteDialogOpen(true);
@@ -1968,49 +2008,23 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
)}
{hasMoreFeedItems && onLoadMoreFeedItems && (
<Box
- component="button"
- type="button"
- disabled={isFeedLoadingMore}
- onClick={onLoadMoreFeedItems}
+ ref={feedLoadMoreRef}
+ aria-live="polite"
sx={{
alignItems: "center",
alignSelf: "center",
- appearance: "none",
- bgcolor: paleGreen,
- border: 0,
- borderRadius: "18px",
- color: green,
- cursor: isFeedLoadingMore
- ? "default"
- : "pointer",
- display: "inline-flex",
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 600,
- height: spaceTouchTargetSize,
+ display: "flex",
+ height: 48,
justifyContent: "center",
- lineHeight: "18px",
mb: 0,
- minWidth: 116,
mt: "12px",
- opacity: isFeedLoadingMore ? 0.7 : 1,
- px: "18px",
- whiteSpace: "nowrap",
- "&:focus-visible": {
- outline: `2px solid ${green}`,
- outlineOffset: 2,
- },
- "&:hover": {
- bgcolor: isFeedLoadingMore
- ? paleGreen
- : "#DDF1E1",
- },
+ width: "100%",
}}
>
- {isFeedLoadingMore
- ? "Loading..."
- : "Load more"}
+ <SpaceLoadingSpinner
+ ariaLabel="Loading more posts"
+ size={22}
+ />
</Box>
)}
</>