feat(notification): Add a notification when replying to a comment.

This commit is contained in:
LinkinStars
2024-03-04 18:00:24 +08:00
parent bee1f5624e
commit fd6c2b1cd5
+35 -3
View File
@@ -21,6 +21,8 @@ package comment
import (
"context"
"time"
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/pager"
"github.com/apache/incubator-answer/internal/base/reason"
@@ -40,7 +42,6 @@ import (
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
"time"
)
// CommentRepo comment repository
@@ -211,7 +212,8 @@ func (cs *CommentService) addCommentNotification(
resp.ReplyUserDisplayName = replyUser.DisplayName
resp.ReplyUserStatus = replyUser.Status
}
cs.notificationCommentReply(ctx, replyUser.ID, comment.ID, req.UserID)
cs.notificationCommentReply(ctx, replyUser.ID, comment.ID, req.UserID,
objInfo.QuestionID, objInfo.Title, comment.OriginalText)
alreadyNotifiedUserID[replyUser.ID] = true
return nil, nil
}
@@ -579,7 +581,8 @@ func (cs *CommentService) notificationAnswerComment(ctx context.Context,
cs.externalNotificationQueueService.Send(ctx, externalNotificationMsg)
}
func (cs *CommentService) notificationCommentReply(ctx context.Context, replyUserID, commentID, commentUserID string) {
func (cs *CommentService) notificationCommentReply(ctx context.Context, replyUserID, commentID, commentUserID,
questionID, questionTitle, commentSummary string) {
msg := &schema.NotificationMsg{
ReceiverUserID: replyUserID,
TriggerUserID: commentUserID,
@@ -589,6 +592,35 @@ func (cs *CommentService) notificationCommentReply(ctx context.Context, replyUse
msg.ObjectType = constant.CommentObjectType
msg.NotificationAction = constant.NotificationReplyToYou
cs.notificationQueueService.Send(ctx, msg)
// Send external notification.
receiverUserInfo, exist, err := cs.userRepo.GetByUserID(ctx, replyUserID)
if err != nil {
log.Error(err)
return
}
if !exist {
log.Warnf("user %s not found", replyUserID)
return
}
externalNotificationMsg := &schema.ExternalNotificationMsg{
ReceiverUserID: receiverUserInfo.ID,
ReceiverEmail: receiverUserInfo.EMail,
ReceiverLang: receiverUserInfo.Language,
}
rawData := &schema.NewCommentTemplateRawData{
QuestionTitle: questionTitle,
QuestionID: questionID,
CommentID: commentID,
CommentSummary: commentSummary,
UnsubscribeCode: token.GenerateToken(),
}
commentUser, _, _ := cs.userCommon.GetUserBasicInfoByID(ctx, commentUserID)
if commentUser != nil {
rawData.CommentUserDisplayName = commentUser.DisplayName
}
externalNotificationMsg.NewCommentTemplateRawData = rawData
cs.externalNotificationQueueService.Send(ctx, externalNotificationMsg)
}
func (cs *CommentService) notificationMention(