Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update space notification emails

Anand Baburajan2b16774eb35d
diff --git a/server/mail-templates/space_notification.html b/server/mail-templates/space_notification.html
index 62a9790e89..da90fac90c 100644
--- a/server/mail-templates/space_notification.html
+++ b/server/mail-templates/space_notification.html
@@ -1,9 +1,139 @@
-{{define "content"}}
-<div style="text-align: center;">
- <p>Hi,</p>
- <p>{{ .Message }}.</p>
+<!DOCTYPE html>
+<html>
+<meta content="text/html; charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1,
+ minimum-scale=1" />
+<style>
+ body {
+ background-color: #f0f1f3;
+ font-family: "Helvetica Neue", "Segoe UI", Helvetica, sans-serif;
+ font-size: 16px;
+ line-height: 24px;
+ margin: 0;
+ color: #232323;
+ }
+
+ .wrap {
+ background-color: #ffffff;
+ padding: 34px 22px 22px;
+ max-width: 320px;
+ margin: 0 auto;
+ border-radius: 32px;
+ }
+
+ .button {
+ background: #08C225;
+ border-radius: 16px;
+ text-decoration: none !important;
+ color: #fff !important;
+ font-size: 14px;
+ font-weight: 500;
+ padding: 16px 28px;
+ display: block;
+ box-sizing: border-box;
+ width: 100%;
+ }
+
+ .button:hover {
+ background: #08B020;
+ }
+
+ .footer {
+ text-align: center;
+ font-size: 12px;
+ color: #888;
+ }
+
+ .footer a {
+ color: #888;
+ margin-right: 5px;
+ }
+
+ .gutter {
+ padding: 30px;
+ }
+
+ img {
+ max-width: 100%;
+ height: auto;
+ }
+
+ a {
+ color: #08C225;
+ }
+
+ a:hover {
+ color: #111;
+ }
+
+ @media screen and (max-width: 600px) {
+ .wrap {
+ max-width: auto;
+ }
+
+ .gutter {
+ padding: 10px;
+ }
+ }
+
+ .footer-icons {
+ padding: 4px !important;
+ width: 24px !important;
+ }
+</style>
+
+<body>
+<div class="gutter" style="padding: 18px">&nbsp;</div>
+<div class="wrap" style=" background-color: rgb(255, 255, 255); padding: 34px
+ 22px 22px; max-width: 320px; margin: 0 auto; border-radius: 32px;
+ font-size: 16px; color: #232323; " >
+ <main>
+ <div style="text-align: center;">
+ {{if .IllustrationURL}}
+ <p style="margin: 0 0 24px;">
+ <img src="{{ .IllustrationURL }}" alt="" style="display: block; margin: 0 auto; width: {{ .IllustrationWidth }}px; height: auto;" />
+ </p>
+ {{end}}
+ <p style="font-size: 26px; font-weight: 800; line-height: 30px; margin: 0 0 4px; color: #232323;">{{ .ActorLabel }}</p>
+ <p style="font-size: 15px; line-height: 21px; margin: 0 0 28px; color: #6b6b6b;">{{ .Notification }}</p>
+ <p style="margin: 0;">
+ <a class="button" href="{{ .AppURL }}" target="_blank">Open Ente Space</a>
+ </p>
+ </div>
+ </main>
+</div>
+<br />
+<div class="footer" style="text-align: center; font-size: 12px; color:
+ rgb(136, 136, 136)" >
+ <div>
+ <a href="https://ente.com" target="_blank" ><img
+ src="https://email-assets.ente.com/ente-2026-green.png" style="width: 100px;
+ padding: 24px" title="Ente" alt="Ente" /></a>
+ </div>
+ <div>
+ <a href="https://fosstodon.org/@ente" target="_blank" ><img
+ src="https://email-assets.ente.com/mastodon-icon.png"
+ class="footer-icons" style="width: 24px; padding: 4px" title="Mastodon"
+ alt="Mastodon" /></a>
+ <a href="https://twitter.com/enteio" target="_blank" ><img
+ src="https://email-assets.ente.com/twitter-icon.png" class="footer-icons"
+ style="width: 24px; padding: 4px" title="Twitter" alt="Twitter" /></a>
+ <a href="https://ente.com/discord" target="_blank" ><img
+ src="https://email-assets.ente.com/discord-icon.png" class="footer-icons"
+ style="width: 24px; padding: 4px" title="Discord" alt="Discord" /></a>
+ <a href="https://github.com/ente-io" target="_blank" ><img
+ src="https://email-assets.ente.com/github-icon.png" class="footer-icons"
+ style="width: 24px; padding: 4px" title="GitHub" alt="GitHub" /></a>
+
+ <a href="https://www.youtube.com/@entestudio" target="_blank" ><img
+ src="https://email-assets.ente.com/youtube-icon.png" class="footer-icons"
+ style="width: 24px; padding: 4px" title="YouTube" alt="YouTube" /></a>
+ </div>
<p>
- <a class="button" href="{{ .AppURL }}" target="_blank">Open Space</a>
+ Ente Technologies, Inc.
+ <br /> 1111B S Governors Ave 6032 Dover, DE 19904
</p>
+ <br />
</div>
-{{end}}
+</body>
+</html>
diff --git a/server/pkg/utils/email/space_notification_template_test.go b/server/pkg/utils/email/space_notification_template_test.go
index 511d4d45a3..a1ec5e2b10 100644
--- a/server/pkg/utils/email/space_notification_template_test.go
+++ b/server/pkg/utils/email/space_notification_template_test.go
@@ -10,11 +10,17 @@ import (
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",
+ body, err := getMailBody("space_notification.html", map[string]interface{}{
+ "ActorLabel": "@alice",
+ "AppURL": "https://ente.space/app",
+ "IllustrationURL": "https://email-assets.ente.com/space-new-post.svg",
+ "IllustrationWidth": 112,
+ "Notification": "just posted a new photo",
})
require.NoError(t, err)
require.Contains(t, body, `<div style="text-align: center;">`)
- require.Contains(t, body, "@alice liked your post.")
+ require.Contains(t, body, "@alice")
+ require.Contains(t, body, "just posted a new photo")
+ require.Contains(t, body, `https://email-assets.ente.com/space-new-post.svg`)
+ require.Contains(t, body, `https://email-assets.ente.com/ente-2026-green.png`)
}
diff --git a/server/space/controller/notifications.go b/server/space/controller/notifications.go
index a7e67c080e..c6aa540eaa 100644
--- a/server/space/controller/notifications.go
+++ b/server/space/controller/notifications.go
@@ -10,9 +10,23 @@ import (
"github.com/spf13/viper"
)
-const spaceNotificationTemplate = "space_notification.html"
+const (
+ spaceNotificationTemplate = "space_notification.html"
+ spaceNewPostIllustrationURL = "https://email-assets.ente.com/space-new-post.svg"
+ spaceNewPostLikeIllustrationURL = "https://email-assets.ente.com/space-new-post-like.svg"
+ spaceNewPostReplyIllustrationURL = "https://email-assets.ente.com/space-new-post-reply.svg"
+ spaceNewFriendIllustrationURL = "https://email-assets.ente.com/space-new-friend.svg"
+ spaceNotificationPostCreated = "post_created"
+ spaceNotificationPostLiked = "post_liked"
+ spaceNotificationPostReplied = "post_replied"
+ spaceNotificationFriendAdded = "friend_added"
+ spaceNewPostIllustrationWidth = 112
+ spaceNewPostLikeIllustrationWidth = 132
+ spaceNewPostReplyIllustrationWidth = 132
+ spaceNewFriendIllustrationWidth = 220
+)
-var sendSpaceNotificationEmail = emailutil.SendTemplatedEmailV2
+var sendSpaceNotificationEmail = emailutil.SendTemplatedEmail
type SpaceEmailNotifier interface {
OnSpacePostCreated(authorSlug string, recipientUserIDs []int64)
@@ -26,19 +40,19 @@ type SpaceEmailSender struct {
}
func (n *SpaceEmailSender) OnSpacePostCreated(authorSlug string, recipientUserIDs []int64) {
- n.send(authorSlug, "posted a new photo", "post_created", recipientUserIDs)
+ n.send(authorSlug, "posted a new photo", spaceNotificationPostCreated, recipientUserIDs)
}
func (n *SpaceEmailSender) OnSpacePostLiked(actorSlug string, recipientUserID int64) {
- n.send(actorSlug, "liked your post", "post_liked", []int64{recipientUserID})
+ n.send(actorSlug, "liked your post", spaceNotificationPostLiked, []int64{recipientUserID})
}
func (n *SpaceEmailSender) OnSpacePostReplied(actorSlug string, recipientUserID int64) {
- n.send(actorSlug, "replied to your post", "post_replied", []int64{recipientUserID})
+ n.send(actorSlug, "replied to your post", spaceNotificationPostReplied, []int64{recipientUserID})
}
func (n *SpaceEmailSender) OnSpaceFriendAdded(actorSlug string, recipientUserID int64) {
- n.send(actorSlug, "is now your friend", "friend_added", []int64{recipientUserID})
+ n.send(actorSlug, "is now your friend", spaceNotificationFriendAdded, []int64{recipientUserID})
}
func (n *SpaceEmailSender) send(actorSlug, action, event string, recipientUserIDs []int64) {
@@ -57,8 +71,11 @@ func (n *SpaceEmailSender) send(actorSlug, action, event string, recipientUserID
subject := spaceEmailSubject(actorSlug, action)
templateData := map[string]interface{}{
- "Message": subject,
- "AppURL": spaceAppURL(),
+ "ActorLabel": spaceEmailActorLabel(actorSlug),
+ "AppURL": spaceAppURL(),
+ "IllustrationURL": spaceEmailIllustrationURL(event),
+ "IllustrationWidth": spaceEmailIllustrationWidth(event),
+ "Notification": spaceEmailNotificationText(event, action),
}
for _, userID := range recipientUserIDs {
user := users[userID]
@@ -70,7 +87,6 @@ func (n *SpaceEmailSender) send(actorSlug, action, event string, recipientUserID
"Ente",
subject,
- "base.html",
spaceNotificationTemplate,
templateData,
nil,
@@ -92,6 +108,59 @@ func spaceEmailSubject(actorSlug, action string) string {
return fmt.Sprintf("@%s %s", actorSlug, action)
}
+func spaceEmailActorLabel(actorSlug string) string {
+ actorSlug = strings.TrimSpace(actorSlug)
+ if actorSlug == "" {
+ return "A friend"
+ }
+ return fmt.Sprintf("@%s", actorSlug)
+}
+
+func spaceEmailNotificationText(event, action string) string {
+ switch event {
+ case spaceNotificationPostCreated:
+ return "just posted a new photo"
+ case spaceNotificationPostLiked:
+ return "just liked your post"
+ case spaceNotificationPostReplied:
+ return "just replied to your post"
+ case spaceNotificationFriendAdded:
+ return "is now your friend"
+ default:
+ return action
+ }
+}
+
+func spaceEmailIllustrationURL(event string) string {
+ switch event {
+ case spaceNotificationPostCreated:
+ return spaceNewPostIllustrationURL
+ case spaceNotificationPostLiked:
+ return spaceNewPostLikeIllustrationURL
+ case spaceNotificationPostReplied:
+ return spaceNewPostReplyIllustrationURL
+ case spaceNotificationFriendAdded:
+ return spaceNewFriendIllustrationURL
+ default:
+ return ""
+ }
+}
+
+func spaceEmailIllustrationWidth(event string) int {
+ switch event {
+ case spaceNotificationPostCreated:
+ return spaceNewPostIllustrationWidth
+ case spaceNotificationPostLiked:
+ return spaceNewPostLikeIllustrationWidth
+ case spaceNotificationPostReplied:
+ return spaceNewPostReplyIllustrationWidth
+ case spaceNotificationFriendAdded:
+ return spaceNewFriendIllustrationWidth
+ default:
+ return 0
+ }
+}
+
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 c8a85cd3d0..aee763f2b0 100644
--- a/server/space/controller/notifications_test.go
+++ b/server/space/controller/notifications_test.go
@@ -68,6 +68,23 @@ func TestSpaceEmailSubjectPrefixesUsernameWithAt(t *testing.T) {
require.Equal(t, "A friend liked your post", spaceEmailSubject(" ", "liked your post"))
}
+func TestSpaceEmailTemplateData(t *testing.T) {
+ require.Equal(t, "@alice", spaceEmailActorLabel(" alice "))
+ require.Equal(t, "A friend", spaceEmailActorLabel(" "))
+ require.Equal(t, "just posted a new photo", spaceEmailNotificationText(spaceNotificationPostCreated, "posted a new photo"))
+ require.Equal(t, "just liked your post", spaceEmailNotificationText(spaceNotificationPostLiked, "liked your post"))
+ require.Equal(t, "just replied to your post", spaceEmailNotificationText(spaceNotificationPostReplied, "replied to your post"))
+ require.Equal(t, "is now your friend", spaceEmailNotificationText(spaceNotificationFriendAdded, "is now your friend"))
+ require.Equal(t, spaceNewPostIllustrationURL, spaceEmailIllustrationURL(spaceNotificationPostCreated))
+ require.Equal(t, spaceNewPostLikeIllustrationURL, spaceEmailIllustrationURL(spaceNotificationPostLiked))
+ require.Equal(t, spaceNewPostReplyIllustrationURL, spaceEmailIllustrationURL(spaceNotificationPostReplied))
+ require.Equal(t, spaceNewFriendIllustrationURL, spaceEmailIllustrationURL(spaceNotificationFriendAdded))
+ require.Equal(t, spaceNewPostIllustrationWidth, spaceEmailIllustrationWidth(spaceNotificationPostCreated))
+ require.Equal(t, spaceNewPostLikeIllustrationWidth, spaceEmailIllustrationWidth(spaceNotificationPostLiked))
+ require.Equal(t, spaceNewPostReplyIllustrationWidth, spaceEmailIllustrationWidth(spaceNotificationPostReplied))
+ require.Equal(t, spaceNewFriendIllustrationWidth, spaceEmailIllustrationWidth(spaceNotificationFriendAdded))
+}
+
func TestPostLikeSendsEmailOnce(t *testing.T) {
_, repos, ctx := setupPostsControllerTest(t)
notifier := newRecordingSpaceEmailNotifier()