feat: added notifications for post reactions
This commit is contained in:
parent
f77bd72c57
commit
1c654ad7b5
|
|
@ -779,6 +779,58 @@ func (h *PostHandler) ToggleReaction(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if reaction was added (exists in myReactions)
|
||||||
|
reactionAdded := false
|
||||||
|
for _, r := range myReactions {
|
||||||
|
if r == emoji {
|
||||||
|
reactionAdded = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if reactionAdded {
|
||||||
|
go func() {
|
||||||
|
bgCtx := context.Background()
|
||||||
|
post, err := h.postRepo.GetPostByID(bgCtx, postID, userIDStr.(string))
|
||||||
|
if err != nil || post.AuthorID.String() == userIDStr.(string) {
|
||||||
|
return // Don't notify self
|
||||||
|
}
|
||||||
|
|
||||||
|
if h.notificationService != nil {
|
||||||
|
// Get actor details
|
||||||
|
actor, err := h.userRepo.GetProfileByID(bgCtx, userIDStr.(string))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata := map[string]interface{}{
|
||||||
|
"actor_name": actor.DisplayName,
|
||||||
|
"post_id": postID,
|
||||||
|
"emoji": emoji,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using "like" type for now, or "quip_reaction" if quip
|
||||||
|
notifType := "like"
|
||||||
|
if post.VideoURL != nil && *post.VideoURL != "" {
|
||||||
|
notifType = "quip_reaction"
|
||||||
|
metadata["post_type"] = "quip"
|
||||||
|
} else {
|
||||||
|
metadata["post_type"] = "post"
|
||||||
|
}
|
||||||
|
|
||||||
|
h.notificationService.CreateNotification(
|
||||||
|
bgCtx,
|
||||||
|
post.AuthorID.String(),
|
||||||
|
userIDStr.(string),
|
||||||
|
notifType,
|
||||||
|
&postID,
|
||||||
|
nil,
|
||||||
|
metadata,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"reactions": counts,
|
"reactions": counts,
|
||||||
"my_reactions": myReactions,
|
"my_reactions": myReactions,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue