diff --git a/pkg/controller/api/likes.go b/pkg/controller/api/likes.go index c7333b0..f436a5c 100644 --- a/pkg/controller/api/likes.go +++ b/pkg/controller/api/likes.go @@ -104,7 +104,7 @@ func Likes() http.HandlerFunc { if targetUser != nil { notif := &models.Notification{ UserID: targetUser.ID, - User: *currentUser, + AboutUser: *currentUser, Type: models.NotificationLike, TableName: req.TableName, TableID: req.TableID, diff --git a/pkg/controller/friend/request.go b/pkg/controller/friend/request.go index 0163e47..cdbf993 100644 --- a/pkg/controller/friend/request.go +++ b/pkg/controller/friend/request.go @@ -5,6 +5,7 @@ import ( "net/http" "strings" + "git.kirsle.net/apps/gosocial/pkg/log" "git.kirsle.net/apps/gosocial/pkg/models" "git.kirsle.net/apps/gosocial/pkg/session" "git.kirsle.net/apps/gosocial/pkg/templates" @@ -76,6 +77,16 @@ func AddFriend() http.HandlerFunc { session.FlashError(w, r, "Couldn't send friend request: %s.", err) } else { if verdict == "approve" { + // Notify the requestor they'd been approved. + notif := &models.Notification{ + UserID: user.ID, + AboutUser: *currentUser, + Type: models.NotificationFriendApproved, + } + if err := models.CreateNotification(notif); err != nil { + log.Error("Couldn't create approved notification: %s", err) + } + session.Flash(w, r, "You accepted the friend request from %s!", username) templates.Redirect(w, "/friends?view=requests") return diff --git a/pkg/controller/photo/certification.go b/pkg/controller/photo/certification.go index ad484ea..cf79266 100644 --- a/pkg/controller/photo/certification.go +++ b/pkg/controller/photo/certification.go @@ -76,6 +76,7 @@ func Certification() http.HandlerFunc { } cert.Status = models.CertificationPhotoNeeded + cert.AdminComment = "" cert.Save() // Removing your photo = not certified again. @@ -252,6 +253,17 @@ func AdminCertification() http.HandlerFunc { user.Certified = false user.Save() + // Notify the user about this rejection. + notif := &models.Notification{ + UserID: user.ID, + AboutUser: *user, + Type: models.NotificationCertRejected, + Message: comment, + } + if err := models.CreateNotification(notif); err != nil { + log.Error("Couldn't create rejection notification: %s", err) + } + // Notify the user via email. if err := mail.Send(mail.Message{ To: user.Email, @@ -281,6 +293,16 @@ func AdminCertification() http.HandlerFunc { user.Certified = true user.Save() + // Notify the user about this approval. + notif := &models.Notification{ + UserID: user.ID, + AboutUser: *user, + Type: models.NotificationCertApproved, + } + if err := models.CreateNotification(notif); err != nil { + log.Error("Couldn't create approval notification: %s", err) + } + // Notify the user via email. if err := mail.Send(mail.Message{ To: user.Email, diff --git a/pkg/models/notification.go b/pkg/models/notification.go index cf34d72..5c8ce2d 100644 --- a/pkg/models/notification.go +++ b/pkg/models/notification.go @@ -12,7 +12,7 @@ type Notification struct { ID uint64 `gorm:"primaryKey"` UserID uint64 `gorm:"index"` // who it belongs to AboutUserID *uint64 `form:"index"` // the other party of this notification - User User `gorm:"foreignKey:about_user_id"` + AboutUser User `gorm:"foreignKey:about_user_id"` Type NotificationType // like, comment, ... Read bool `gorm:"index"` TableName string // on which of your tables (photos, comments, ...) @@ -24,15 +24,18 @@ type Notification struct { // Preload related tables for the forum (classmethod). func (n *Notification) Preload() *gorm.DB { - return DB.Preload("User.ProfilePhoto") + return DB.Preload("AboutUser.ProfilePhoto") } type NotificationType string const ( - NotificationLike NotificationType = "like" - NotificationComment = "comment" - NotificationCustom = "custom" // custom message pushed + NotificationLike NotificationType = "like" + NotificationFriendApproved = "friendship_approved" + NotificationComment = "comment" + NotificationCertRejected = "cert_rejected" + NotificationCertApproved = "cert_approved" + NotificationCustom = "custom" // custom message pushed ) // CreateNotification diff --git a/web/templates/account/dashboard.html b/web/templates/account/dashboard.html index e55d47f..3fa07b7 100644 --- a/web/templates/account/dashboard.html +++ b/web/templates/account/dashboard.html @@ -176,10 +176,10 @@ NEW! {{end}} - +
- {{if .User.ProfilePhoto.ID}} - + {{if .AboutUser.ProfilePhoto.ID}} + {{else}} {{end}} @@ -191,7 +191,7 @@ {{if eq .Type "like"}} - {{.User.Username}} + {{.AboutUser.Username}} liked your {{if eq .TableName "photos"}} photo. @@ -201,11 +201,34 @@ {{.TableName}}. {{end}} + {{else if eq .Type "friendship_approved"}} + + + {{.AboutUser.Username}} + accepted your friend request! + + {{else if eq .Type "cert_approved"}} + + + Your certification photo was approved! + + {{else if eq .Type "cert_rejected"}} + + + Your certification photo was rejected! + {{else}} - {{.User.Username}} {{.Type}} {{.TableName}} {{.TableID}} + {{.AboutUser.Username}} {{.Type}} {{.TableName}} {{.TableID}} {{end}} + + {{if .Message}} +
+ {{ToMarkdown .Message}} +
+ {{end}} + {{if $Body.Photo}}