fix(notification): missing unsubscribe code

This commit is contained in:
LinkinStars 2023-08-22 14:48:40 +08:00
parent 2bd8f7f771
commit 3b1324b83b
4 changed files with 13 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/answerdev/answer/pkg/token"
"time" "time"
"github.com/answerdev/answer/internal/base/constant" "github.com/answerdev/answer/internal/base/constant"
@ -22,7 +23,6 @@ import (
"github.com/answerdev/answer/internal/service/revision_common" "github.com/answerdev/answer/internal/service/revision_common"
"github.com/answerdev/answer/internal/service/role" "github.com/answerdev/answer/internal/service/role"
usercommon "github.com/answerdev/answer/internal/service/user_common" usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/answerdev/answer/pkg/encryption"
"github.com/answerdev/answer/pkg/uid" "github.com/answerdev/answer/pkg/uid"
"github.com/segmentfault/pacman/errors" "github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log" "github.com/segmentfault/pacman/log"
@ -626,7 +626,7 @@ func (as *AnswerService) notificationAnswerTheQuestion(ctx context.Context,
QuestionID: questionID, QuestionID: questionID,
AnswerID: answerID, AnswerID: answerID,
AnswerSummary: answerSummary, AnswerSummary: answerSummary,
UnsubscribeCode: encryption.MD5(receiverUserInfo.Pass), UnsubscribeCode: token.GenerateToken(),
} }
answerUser, _, _ := as.userCommon.GetUserBasicInfoByID(ctx, answerUserID) answerUser, _, _ := as.userCommon.GetUserBasicInfoByID(ctx, answerUserID)
if answerUser != nil { if answerUser != nil {

View File

@ -2,6 +2,7 @@ package comment
import ( import (
"context" "context"
"github.com/answerdev/answer/pkg/token"
"time" "time"
"github.com/answerdev/answer/internal/base/constant" "github.com/answerdev/answer/internal/base/constant"
@ -17,7 +18,6 @@ import (
"github.com/answerdev/answer/internal/service/object_info" "github.com/answerdev/answer/internal/service/object_info"
"github.com/answerdev/answer/internal/service/permission" "github.com/answerdev/answer/internal/service/permission"
usercommon "github.com/answerdev/answer/internal/service/user_common" usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/answerdev/answer/pkg/encryption"
"github.com/answerdev/answer/pkg/htmltext" "github.com/answerdev/answer/pkg/htmltext"
"github.com/answerdev/answer/pkg/uid" "github.com/answerdev/answer/pkg/uid"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
@ -508,7 +508,7 @@ func (cs *CommentService) notificationQuestionComment(ctx context.Context, quest
QuestionID: questionID, QuestionID: questionID,
CommentID: commentID, CommentID: commentID,
CommentSummary: commentSummary, CommentSummary: commentSummary,
UnsubscribeCode: encryption.MD5(receiverUserInfo.Pass), UnsubscribeCode: token.GenerateToken(),
} }
commentUser, _, _ := cs.userCommon.GetUserBasicInfoByID(ctx, commentUserID) commentUser, _, _ := cs.userCommon.GetUserBasicInfoByID(ctx, commentUserID)
if commentUser != nil { if commentUser != nil {
@ -556,7 +556,7 @@ func (cs *CommentService) notificationAnswerComment(ctx context.Context,
AnswerID: answerID, AnswerID: answerID,
CommentID: commentID, CommentID: commentID,
CommentSummary: commentSummary, CommentSummary: commentSummary,
UnsubscribeCode: encryption.MD5(receiverUserInfo.Pass), UnsubscribeCode: token.GenerateToken(),
} }
commentUser, _, _ := cs.userCommon.GetUserBasicInfoByID(ctx, commentUserID) commentUser, _, _ := cs.userCommon.GetUserBasicInfoByID(ctx, commentUserID)
if commentUser != nil { if commentUser != nil {

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/answerdev/answer/internal/base/constant" "github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/schema" "github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/pkg/token"
"github.com/segmentfault/pacman/i18n" "github.com/segmentfault/pacman/i18n"
"github.com/segmentfault/pacman/log" "github.com/segmentfault/pacman/log"
"time" "time"
@ -31,9 +32,11 @@ func (ns *ExternalNotificationService) handleNewQuestionNotification(ctx context
switch channel.Key { switch channel.Key {
case constant.EmailChannel: case constant.EmailChannel:
ns.sendNewQuestionNotificationEmail(ctx, subscriber.UserID, &schema.NewQuestionTemplateRawData{ ns.sendNewQuestionNotificationEmail(ctx, subscriber.UserID, &schema.NewQuestionTemplateRawData{
QuestionTitle: msg.NewQuestionTemplateRawData.QuestionTitle, QuestionTitle: msg.NewQuestionTemplateRawData.QuestionTitle,
QuestionID: msg.NewQuestionTemplateRawData.QuestionID, QuestionID: msg.NewQuestionTemplateRawData.QuestionID,
Tags: msg.NewQuestionTemplateRawData.Tags, UnsubscribeCode: token.GenerateToken(),
Tags: msg.NewQuestionTemplateRawData.Tags,
TagIDs: msg.NewQuestionTemplateRawData.TagIDs,
}) })
} }
} }

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/answerdev/answer/internal/service/notification" "github.com/answerdev/answer/internal/service/notification"
"github.com/answerdev/answer/internal/service/siteinfo_common" "github.com/answerdev/answer/internal/service/siteinfo_common"
"github.com/answerdev/answer/pkg/token"
"strings" "strings"
"time" "time"
@ -28,7 +29,6 @@ import (
tagcommon "github.com/answerdev/answer/internal/service/tag_common" tagcommon "github.com/answerdev/answer/internal/service/tag_common"
usercommon "github.com/answerdev/answer/internal/service/user_common" usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/answerdev/answer/pkg/converter" "github.com/answerdev/answer/pkg/converter"
"github.com/answerdev/answer/pkg/encryption"
"github.com/answerdev/answer/pkg/htmltext" "github.com/answerdev/answer/pkg/htmltext"
"github.com/answerdev/answer/pkg/uid" "github.com/answerdev/answer/pkg/uid"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
@ -663,7 +663,7 @@ func (qs *QuestionService) notificationInviteUser(
InviterDisplayName: inviter.DisplayName, InviterDisplayName: inviter.DisplayName,
QuestionTitle: questionTitle, QuestionTitle: questionTitle,
QuestionID: questionID, QuestionID: questionID,
UnsubscribeCode: encryption.MD5(receiverUserInfo.Pass), UnsubscribeCode: token.GenerateToken(),
} }
externalNotificationMsg.NewInviteAnswerTemplateRawData = rawData externalNotificationMsg.NewInviteAnswerTemplateRawData = rawData
qs.externalNotificationQueueService.Send(ctx, externalNotificationMsg) qs.externalNotificationQueueService.Send(ctx, externalNotificationMsg)