π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add social post email notifications
Anand Baburajan257c66c68c8b
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 9a8deb7d4d..2e2d3d206c 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -113,6 +113,7 @@ func main() {viper.SetDefault("apps.accounts", "https://accounts.ente.io")viper.SetDefault("apps.cast", "https://cast.ente.io")viper.SetDefault("apps.family", "https://family.ente.io")+ viper.SetDefault("apps.social", "https://ente.gg")setupLogger(environment)log.Infof("Booting up %s server with commit #%s", environment, os.Getenv("GIT_COMMIT"))@@ -940,7 +941,7 @@ func main() {userEntityController := &userEntityCtrl.Controller{Repo: userEntityRepo}userEntityHandler := &api.UserEntityHandler{Controller: userEntityController}wallRepos := wallrepo.NewModule(db, s3Config)- wallModule := wallcontroller.NewModule(wallRepos, userAuthRepo)+ wallModule := wallcontroller.NewModule(wallRepos, userAuthRepo, &wallcontroller.WallEmailNotifier{UserRepo: userRepo})wallHandlers := wallapi.NewHandlers(wallModule)privateAPI.POST("/user-entity/key", userEntityHandler.CreateKey)diff --git a/server/config/example.yaml b/server/config/example.yamlindex 159e8bcc12..6ce9e55765 100644--- a/server/config/example.yaml+++ b/server/config/example.yaml@@ -65,6 +65,8 @@ apps:# Set this to the URL where your accounts web app is running, primarily used for# passkey based 2FA.accounts: http://localhost:3001+ # Set this to the URL where your social web app is running.+ social: http://localhost:3012# Key used for encrypting customer emails before storing them in DB#diff --git a/server/configurations/local.yaml b/server/configurations/local.yamlindex 8619970603..5f935e83c2 100644--- a/server/configurations/local.yaml+++ b/server/configurations/local.yaml@@ -108,6 +108,9 @@ apps:accounts:# Default is https://family.ente.iofamily:+ # Default is https://ente.gg+ # Set this to the URL where your social web app is running.+ social:# Default is https://memories.ente.io## If you're running a self-hosted instance and wish to serve public memory shares,diff --git a/server/mail-templates/wall_post_created.html b/server/mail-templates/wall_post_created.htmlnew file mode 100644index 0000000000..2ae6d3b0cb--- /dev/null+++ b/server/mail-templates/wall_post_created.html@@ -0,0 +1,184 @@+<!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: 27px;+ margin: 0;+ color: #444;+ }++ pre {+ background: #f4f4f4f4;+ padding: 2px;+ }++ table {+ width: 100%;+ border: 1px solid #ddd;+ }++ table td {+ border-color: #ddd;+ padding: 5px;+ }++ .wrap {+ background-color: #fff;+ padding: 30px;+ max-width: 525px;+ margin: 0 auto;+ border-radius: 5px;+ }++ .button {+ background: #0055d4;+ border-radius: 3px;+ text-decoration: none !important;+ color: #fff !important;+ font-weight: bold;+ padding: 10px 30px;+ display: inline-block;+ }++ .button:hover {+ background: #111;+ }++ .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: #0055d4;+ }++ 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: 4px"> </div>+ <div+ class="wrap"+ style="+ background-color: rgb(255, 255, 255);+ padding: 2px 30px 30px 30px;+ max-width: 525px;+ margin: 0 auto;+ border-radius: 5px;+ font-size: 16px;+ "+ >+ <p>Hi,</p>+ <p>{{ .Author }} has shared a new post.</p>+ <p>+ <a class="button" href="{{ .AppURL }}" target="_blank">Check it out</a>+ </p>+ </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.io/ente-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.io/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.io/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.io/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.io/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.io/youtube-icon.png"+ class="footer-icons"+ style="width: 24px; padding: 4px"+ title="YouTube"+ alt="YouTube"+ /></a>+ </div>+ <p>+ Ente Technologies, Inc.+ <br />+ 1111B S Governors Ave 6032 Dover, DE 19904+ </p>+ <br />+ </div>+ </body>+</html>diff --git a/server/wall/controller/module.go b/server/wall/controller/module.goindex fdc931b652..ec342d3049 100644--- a/server/wall/controller/module.go+++ b/server/wall/controller/module.go@@ -17,7 +17,11 @@ type Module struct {UserAuth *baserepo.UserAuthRepository}-func NewModule(repos *repo.Module, userAuthRepo *baserepo.UserAuthRepository) *Module {+func NewModule(repos *repo.Module, userAuthRepo *baserepo.UserAuthRepository, emailNotifiers ...WallPostEmailNotifier) *Module {+ var emailNotifier WallPostEmailNotifier+ if len(emailNotifiers) > 0 {+ emailNotifier = emailNotifiers[0]+ }authDeps := authDeps{UserAuthRepo: userAuthRepo,LinksRepo: repos.Links,@@ -26,7 +30,7 @@ func NewModule(repos *repo.Module, userAuthRepo *baserepo.UserAuthRepository) *M}return &Module{Walls: &WallsController{WallsRepo: repos.Walls, AssetsRepo: repos.Assets, auth: authDeps},- Posts: &PostsController{PostsRepo: repos.Posts, WallsRepo: repos.Walls, AssetsRepo: repos.Assets, ReadMarkersRepo: repos.Read, auth: authDeps},+ Posts: &PostsController{PostsRepo: repos.Posts, WallsRepo: repos.Walls, FriendsRepo: repos.Friends, AssetsRepo: repos.Assets, ReadMarkersRepo: repos.Read, EmailNotifier: emailNotifier, auth: authDeps},Friends: &FriendsController{FriendsRepo: repos.Friends, WallsRepo: repos.Walls, auth: authDeps},Messages: &MessagesController{MessagesRepo: repos.Messages, PostsRepo: repos.Posts, WallsRepo: repos.Walls, FriendsRepo: repos.Friends, ReadMarkersRepo: repos.Read, auth: authDeps},Links: &LinksController{LinksRepo: repos.Links, WallsRepo: repos.Walls, auth: authDeps},diff --git a/server/wall/controller/notifications.go b/server/wall/controller/notifications.gonew file mode 100644index 0000000000..552ec0b402--- /dev/null+++ b/server/wall/controller/notifications.go@@ -0,0 +1,92 @@+package controller++import (+ "fmt"+ "strings"++ baserepo "github.com/ente-io/museum/pkg/repo"+ emailutil "github.com/ente-io/museum/pkg/utils/email"+ log "github.com/sirupsen/logrus"+ "github.com/spf13/viper"+)++const wallPostCreatedTemplate = "wall_post_created.html"++var sendWallPostCreatedEmail = emailutil.SendTemplatedEmail++type WallPostEmailNotifier interface {+ OnWallPostCreated(authorSlug string, recipientUserIDs []int64)+}++type WallEmailNotifier struct {+ UserRepo *baserepo.UserRepository+}++func (n *WallEmailNotifier) OnWallPostCreated(authorSlug string, recipientUserIDs []int64) {+ if n == nil || n.UserRepo == nil || len(recipientUserIDs) == 0 {+ return+ }+ authorSlug = strings.TrimSpace(authorSlug)+ if authorSlug == "" {+ authorSlug = "A friend"+ }+ recipientUserIDs = uniqueUserIDs(recipientUserIDs)+ if len(recipientUserIDs) == 0 {+ return+ }+ users, err := n.UserRepo.GetActiveUsersForIds(recipientUserIDs)+ if err != nil {+ log.WithError(err).Error("Error fetching users for wall post email")+ return+ }++ subject := fmt.Sprintf("%s has shared a new post", authorSlug)+ templateData := map[string]interface{}{+ "Author": authorSlug,+ "AppURL": socialAppURL(),+ }+ for _, userID := range recipientUserIDs {+ user := users[userID]+ if user == nil || strings.TrimSpace(user.Email) == "" {+ continue+ }+ if err := sendWallPostCreatedEmail(+ []string{user.Email},+ "Ente",+ "[email protected]",+ subject,+ wallPostCreatedTemplate,+ templateData,+ nil,+ ); err != nil {+ log.WithFields(log.Fields{+ "user_id": userID,+ "email": user.Email,+ }).WithError(err).Error("Error sending wall post email")+ }+ }+}++func uniqueUserIDs(userIDs []int64) []int64 {+ seen := make(map[int64]struct{}, len(userIDs))+ out := make([]int64, 0, len(userIDs))+ for _, userID := range userIDs {+ if userID <= 0 {+ continue+ }+ if _, ok := seen[userID]; ok {+ continue+ }+ seen[userID] = struct{}{}+ out = append(out, userID)+ }+ return out+}++func socialAppURL() string {+ origin := strings.TrimRight(strings.TrimSpace(viper.GetString("apps.social")), "/")+ if origin == "" {+ origin = "https://ente.gg"+ }+ return origin + "/app"+}diff --git a/server/wall/controller/posts.go b/server/wall/controller/posts.goindex 45fd05b1cd..67d3eeae64 100644--- a/server/wall/controller/posts.go+++ b/server/wall/controller/posts.go@@ -1,6 +1,7 @@package controllerimport (+ "context""database/sql""errors""strconv"@@ -11,13 +12,16 @@ import ("github.com/ente-io/museum/wall/repo""github.com/ente-io/stacktrace""github.com/gin-gonic/gin"+ log "github.com/sirupsen/logrus")type PostsController struct {PostsRepo *repo.PostsRepositoryWallsRepo *repo.WallsRepository+ FriendsRepo *repo.FriendsRepositoryAssetsRepo *repo.AssetsRepositoryReadMarkersRepo *repo.ReadMarkersRepository+ EmailNotifier WallPostEmailNotifierauth authDeps}@@ -64,9 +68,33 @@ func (c *PostsController) Create(ctx *gin.Context, req models.CreatePostRequest)}return nil, err}+ c.notifyFriendsOfNewPost(wall.WallID, wall.WallSlug)return &models.CreatePostResponse{PostID: postID}, nil}+func (c *PostsController) notifyFriendsOfNewPost(wallID, wallSlug string) {+ if c.EmailNotifier == nil || c.FriendsRepo == nil {+ return+ }+ go func() {+ friends, err := c.FriendsRepo.ListFriendsForWall(context.Background(), wallID)+ if err != nil {+ log.WithField("wall_id", wallID).WithError(err).Error("Failed to list friends for wall post email")+ return+ }+ recipientUserIDs := make([]int64, 0, len(friends))+ for _, friend := range friends {+ if friend.Friend.UserID > 0 {+ recipientUserIDs = append(recipientUserIDs, friend.Friend.UserID)+ }+ }+ if len(recipientUserIDs) == 0 {+ return+ }+ c.EmailNotifier.OnWallPostCreated(wallSlug, recipientUserIDs)+ }()+}+func (c *PostsController) List(ctx *gin.Context, req models.ListPostsRequest) (*models.PostPage, error) {viewer, err := c.auth.resolveViewer(ctx)if err != nil {