A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(notification): check user status before sending notification
LinkinStarse8a6c3f1de60
diff --git a/internal/service/notification/external_notification.go b/internal/service/notification/external_notification.goindex 2a0fdd81..d6bdd2fb 100644--- a/internal/service/notification/external_notification.go+++ b/internal/service/notification/external_notification.go@@ -24,6 +24,7 @@ import ("github.com/apache/answer/internal/base/data""github.com/apache/answer/internal/base/translator"+ "github.com/apache/answer/internal/entity""github.com/apache/answer/internal/schema""github.com/apache/answer/internal/service/activity_common""github.com/apache/answer/internal/service/export"@@ -94,3 +95,16 @@ func (ns *ExternalNotificationService) Handler(ctx context.Context, msg *schema.log.Errorf("unknown notification message: %+v", msg)return nil}++func (ns *ExternalNotificationService) checkUserStatusBeforeNotification(ctx context.Context, userID string) (+ unavailable bool) {+ userInfo, exist, err := ns.userRepo.GetByUserID(ctx, userID)+ if err != nil {+ log.Errorf("get user %s info error: %v", userID, err)+ return true+ }+ if !exist || userInfo.Status != entity.UserStatusAvailable {+ return true+ }+ return false+}diff --git a/internal/service/notification/invite_answer_notification.go b/internal/service/notification/invite_answer_notification.goindex 0a72ae98..4e7c051c 100644--- a/internal/service/notification/invite_answer_notification.go+++ b/internal/service/notification/invite_answer_notification.go@@ -21,11 +21,12 @@ package notificationimport ("context"+ "time"+"github.com/apache/answer/internal/base/constant""github.com/apache/answer/internal/schema""github.com/segmentfault/pacman/i18n""github.com/segmentfault/pacman/log"- "time")func (ns *ExternalNotificationService) handleInviteAnswerNotification(ctx context.Context,@@ -54,6 +55,9 @@ func (ns *ExternalNotificationService) handleInviteAnswerNotification(ctx contexfunc (ns *ExternalNotificationService) sendInviteAnswerNotificationEmail(ctx context.Context,userID, email, lang string, rawData *schema.NewInviteAnswerTemplateRawData) {+ if unavailable := ns.checkUserStatusBeforeNotification(ctx, userID); unavailable {+ return+ }codeContent := &schema.EmailCodeContent{SourceType: schema.UnsubscribeSourceType,NotificationSources: []constant.NotificationSource{diff --git a/internal/service/notification/new_answer_notification.go b/internal/service/notification/new_answer_notification.goindex 8a842bef..91b7e2ae 100644--- a/internal/service/notification/new_answer_notification.go+++ b/internal/service/notification/new_answer_notification.go@@ -21,11 +21,12 @@ package notificationimport ("context"+ "time"+"github.com/apache/answer/internal/base/constant""github.com/apache/answer/internal/schema""github.com/segmentfault/pacman/i18n""github.com/segmentfault/pacman/log"- "time")func (ns *ExternalNotificationService) handleNewAnswerNotification(ctx context.Context,@@ -54,6 +55,9 @@ func (ns *ExternalNotificationService) handleNewAnswerNotification(ctx context.Cfunc (ns *ExternalNotificationService) sendNewAnswerNotificationEmail(ctx context.Context,userID, email, lang string, rawData *schema.NewAnswerTemplateRawData) {+ if unavailable := ns.checkUserStatusBeforeNotification(ctx, userID); unavailable {+ return+ }codeContent := &schema.EmailCodeContent{SourceType: schema.UnsubscribeSourceType,NotificationSources: []constant.NotificationSource{diff --git a/internal/service/notification/new_comment_notification.go b/internal/service/notification/new_comment_notification.goindex c02a008b..3ec99d13 100644--- a/internal/service/notification/new_comment_notification.go+++ b/internal/service/notification/new_comment_notification.go@@ -21,11 +21,12 @@ package notificationimport ("context"+ "time"+"github.com/apache/answer/internal/base/constant""github.com/apache/answer/internal/schema""github.com/segmentfault/pacman/i18n""github.com/segmentfault/pacman/log"- "time")func (ns *ExternalNotificationService) handleNewCommentNotification(ctx context.Context,@@ -54,6 +55,9 @@ func (ns *ExternalNotificationService) handleNewCommentNotification(ctx context.func (ns *ExternalNotificationService) sendNewCommentNotificationEmail(ctx context.Context,userID, email, lang string, rawData *schema.NewCommentTemplateRawData) {+ if unavailable := ns.checkUserStatusBeforeNotification(ctx, userID); unavailable {+ return+ }codeContent := &schema.EmailCodeContent{SourceType: schema.UnsubscribeSourceType,NotificationSources: []constant.NotificationSource{diff --git a/internal/service/notification/new_question_notification.go b/internal/service/notification/new_question_notification.goindex fd98b7f9..8911967a 100644--- a/internal/service/notification/new_question_notification.go+++ b/internal/service/notification/new_question_notification.go@@ -162,6 +162,9 @@ func (ns *ExternalNotificationService) checkSendNewQuestionNotificationEmailLimifunc (ns *ExternalNotificationService) sendNewQuestionNotificationEmail(ctx context.Context,userID string, rawData *schema.NewQuestionTemplateRawData) {+ if unavailable := ns.checkUserStatusBeforeNotification(ctx, userID); unavailable {+ return+ }userInfo, exist, err := ns.userRepo.GetByUserID(ctx, userID)if err != nil {log.Error(err)