feat(notifications): make push messages more specific and include chosen reaction emoji
This commit is contained in:
parent
0531e8f878
commit
3c91dc64c9
|
|
@ -465,6 +465,7 @@ func (h *PostHandler) LikePost(c *gin.Context) {
|
||||||
userIDStr.(string),
|
userIDStr.(string),
|
||||||
postID,
|
postID,
|
||||||
postType,
|
postType,
|
||||||
|
"❤️",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,15 @@ func NewNotificationService(notifRepo *repository.NotificationRepository, pushSv
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// NotifyLike sends a notification when someone likes a post
|
// NotifyLike sends a notification when someone likes a post
|
||||||
func (s *NotificationService) NotifyLike(ctx context.Context, postAuthorID, actorID, postID string, postType string) error {
|
func (s *NotificationService) NotifyLike(ctx context.Context, postAuthorID, actorID, postID string, postType string, emoji string) error {
|
||||||
if postAuthorID == actorID {
|
if postAuthorID == actorID {
|
||||||
return nil // Don't notify self
|
return nil // Don't notify self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if emoji == "" {
|
||||||
|
emoji = "❤️"
|
||||||
|
}
|
||||||
|
|
||||||
return s.sendNotification(ctx, models.PushNotificationRequest{
|
return s.sendNotification(ctx, models.PushNotificationRequest{
|
||||||
UserID: uuid.MustParse(postAuthorID),
|
UserID: uuid.MustParse(postAuthorID),
|
||||||
Type: models.NotificationTypeLike,
|
Type: models.NotificationTypeLike,
|
||||||
|
|
@ -43,6 +47,9 @@ func (s *NotificationService) NotifyLike(ctx context.Context, postAuthorID, acto
|
||||||
PostType: postType,
|
PostType: postType,
|
||||||
GroupKey: fmt.Sprintf("like:%s", postID), // Group likes on same post
|
GroupKey: fmt.Sprintf("like:%s", postID), // Group likes on same post
|
||||||
Priority: models.PriorityNormal,
|
Priority: models.PriorityNormal,
|
||||||
|
Metadata: map[string]interface{}{
|
||||||
|
"emoji": emoji,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,28 +329,28 @@ func (s *NotificationService) buildPushPayload(req models.PushNotificationReques
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract optional emoji
|
// Extract optional emoji
|
||||||
emoji, _ := req.Metadata["emoji"].(string)
|
emoji := getString(req.Metadata, "emoji")
|
||||||
|
|
||||||
switch req.Type {
|
switch req.Type {
|
||||||
case models.NotificationTypeLike:
|
case models.NotificationTypeLike:
|
||||||
if emoji != "" {
|
if emoji != "" {
|
||||||
title = fmt.Sprintf("%s %s", actorName, emoji)
|
title = fmt.Sprintf("%s %s", actorName, emoji)
|
||||||
body = fmt.Sprintf("%s reacted %s to your %s", actorName, emoji, s.formatPostType(req.PostType))
|
body = fmt.Sprintf("%s %s your %s", actorName, emoji, s.formatPostType(req.PostType))
|
||||||
} else {
|
} else {
|
||||||
title = "New Like"
|
title = "New Like"
|
||||||
body = fmt.Sprintf("%s liked your %s", actorName, s.formatPostType(req.PostType))
|
body = fmt.Sprintf("%s liked your %s", actorName, s.formatPostType(req.PostType))
|
||||||
}
|
}
|
||||||
|
|
||||||
case models.NotificationTypeComment:
|
case models.NotificationTypeComment:
|
||||||
title = "New Comment"
|
title = fmt.Sprintf("%s 💬", actorName)
|
||||||
body = fmt.Sprintf("%s commented on your %s", actorName, s.formatPostType(req.PostType))
|
body = fmt.Sprintf("%s commented on your %s", actorName, s.formatPostType(req.PostType))
|
||||||
|
|
||||||
case models.NotificationTypeReply:
|
case models.NotificationTypeReply:
|
||||||
title = "New Reply"
|
title = fmt.Sprintf("%s 💬", actorName)
|
||||||
body = fmt.Sprintf("%s replied to your comment", actorName)
|
body = fmt.Sprintf("%s replied to your comment", actorName)
|
||||||
|
|
||||||
case models.NotificationTypeMention:
|
case models.NotificationTypeMention:
|
||||||
title = "You Were Mentioned"
|
title = "Mentioned"
|
||||||
body = fmt.Sprintf("%s mentioned you in a post", actorName)
|
body = fmt.Sprintf("%s mentioned you in a post", actorName)
|
||||||
|
|
||||||
case models.NotificationTypeFollow:
|
case models.NotificationTypeFollow:
|
||||||
|
|
@ -373,7 +380,7 @@ func (s *NotificationService) buildPushPayload(req models.PushNotificationReques
|
||||||
body = fmt.Sprintf("%s saved your %s", actorName, s.formatPostType(req.PostType))
|
body = fmt.Sprintf("%s saved your %s", actorName, s.formatPostType(req.PostType))
|
||||||
|
|
||||||
case models.NotificationTypeMessage:
|
case models.NotificationTypeMessage:
|
||||||
title = "New Message"
|
title = fmt.Sprintf("%s ✉️", actorName)
|
||||||
body = fmt.Sprintf("%s sent you a message", actorName)
|
body = fmt.Sprintf("%s sent you a message", actorName)
|
||||||
|
|
||||||
case models.NotificationTypeBeaconVouch:
|
case models.NotificationTypeBeaconVouch:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue