Skip to content

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.

update Notification

aichy1260a4f75323c83
diff --git a/internal/base/constant/notification.go b/internal/base/constant/notification.go
index 165c4c01..e4d193e6 100644
--- a/internal/base/constant/notification.go
+++ b/internal/base/constant/notification.go
@@ -38,3 +38,26 @@ const (
// NotificationInvitedYouToAnswer invited you to answer
NotificationInvitedYouToAnswer = "notification.action.invited_you_to_answer"
)
+
+var (
+ NotificationMsgTypeMapping = map[string]int{
+ NotificationUpdateQuestion: 1,
+ NotificationAnswerTheQuestion: 1,
+ NotificationUpVotedTheQuestion: 2,
+ NotificationDownVotedTheQuestion: 2,
+ NotificationUpdateAnswer: 1,
+ NotificationAcceptAnswer: 1,
+ NotificationUpVotedTheAnswer: 2,
+ NotificationDownVotedTheAnswer: 2,
+ NotificationCommentQuestion: 1,
+ NotificationCommentAnswer: 1,
+ NotificationUpVotedTheComment: 2,
+ NotificationReplyToYou: 1,
+ NotificationMentionYou: 1,
+ NotificationYourQuestionIsClosed: 1,
+ NotificationYourQuestionWasDeleted: 1,
+ NotificationYourAnswerWasDeleted: 1,
+ NotificationYourCommentWasDeleted: 1,
+ NotificationInvitedYouToAnswer: 3,
+ }
+)
diff --git a/internal/entity/notification_entity.go b/internal/entity/notification_entity.go
index d16fa06a..19433e50 100644
--- a/internal/entity/notification_entity.go
+++ b/internal/entity/notification_entity.go
@@ -11,6 +11,7 @@ type Notification struct {
ObjectID string `xorm:"not null default 0 INDEX BIGINT(20) object_id"`
Content string `xorm:"not null TEXT content"`
Type int `xorm:"not null default 0 INT(11) type"`
+ MsgType int `xorm:"not null default 0 INT(11) msg_type"`
IsRead int `xorm:"not null default 1 INT(11) is_read"`
Status int `xorm:"not null default 1 INT(11) status"`
}
diff --git a/internal/migrations/v13.go b/internal/migrations/v13.go
index 877469b2..d5df039f 100644
--- a/internal/migrations/v13.go
+++ b/internal/migrations/v13.go
@@ -21,6 +21,7 @@ func updateCount(x *xorm.Engine) error {
updateUserQuestionCount(x)
updateUserAnswerCount(x)
inviteAnswer(x)
+ inBoxData(x)
return nil
}
@@ -337,3 +338,44 @@ func inviteAnswer(x *xorm.Engine) error {
return nil
}
+
+// inBoxData Classify messages
+func inBoxData(x *xorm.Engine) error {
+ type Notification struct {
+ ID string `xorm:"not null pk autoincr BIGINT(20) id"`
+ CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
+ UpdatedAt time.Time `xorm:"TIMESTAMP updated_at"`
+ UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`
+ ObjectID string `xorm:"not null default 0 INDEX BIGINT(20) object_id"`
+ Content string `xorm:"not null TEXT content"`
+ Type int `xorm:"not null default 0 INT(11) type"`
+ MsgType int `xorm:"not null default 0 INT(11) msg_type"`
+ IsRead int `xorm:"not null default 1 INT(11) is_read"`
+ Status int `xorm:"not null default 1 INT(11) status"`
+ }
+ err := x.Sync(new(Notification))
+ if err != nil {
+ return err
+ }
+ msglist := make([]entity.Notification, 0)
+ err = x.Find(&msglist, &entity.Notification{})
+ if err != nil {
+ return fmt.Errorf("get Notification failed: %w", err)
+ }
+ for _, v := range msglist {
+ Content := &schema.NotificationContent{}
+ err := json.Unmarshal([]byte(v.Content), Content)
+ if err != nil {
+ continue
+ }
+ _, ok := constant.NotificationMsgTypeMapping[Content.NotificationAction]
+ if ok {
+ v.MsgType = constant.NotificationMsgTypeMapping[Content.NotificationAction]
+ if _, err = x.Update(v, &entity.Notification{ID: v.ID}); err != nil {
+ log.Errorf("update %+v Notification failed: %s", v.ID, err)
+ }
+ }
+ }
+
+ return nil
+}
diff --git a/internal/service/notification_common/notification.go b/internal/service/notification_common/notification.go
index 5deda1de..b22f6853 100644
--- a/internal/service/notification_common/notification.go
+++ b/internal/service/notification_common/notification.go
@@ -164,6 +164,10 @@ func (ns *NotificationCommon) AddNotification(ctx context.Context, msg *schema.N
if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
}
+ _, ok := constant.NotificationMsgTypeMapping[req.NotificationAction]
+ if ok {
+ info.MsgType = constant.NotificationMsgTypeMapping[req.NotificationAction]
+ }
info.Content = string(content)
err = ns.notificationRepo.AddNotification(ctx, info)
if err != nil {