You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/03/04 10:30:45 UTC

(incubator-answer) 01/02: feat(notification): Add a notification when replying to a comment.

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.3.0/notifiaction
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit fd6c2b1cd5898db5e9deb76e10b4bf8700ca5013
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Mon Mar 4 18:00:24 2024 +0800

    feat(notification): Add a notification when replying to a comment.
---
 internal/service/comment/comment_service.go | 38 ++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/internal/service/comment/comment_service.go b/internal/service/comment/comment_service.go
index 0caa2a14..f9e3a56f 100644
--- a/internal/service/comment/comment_service.go
+++ b/internal/service/comment/comment_service.go
@@ -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(