diff --git a/internal/core/gen.go b/internal/core/gen.go index f712b8d1c..9fdf2cb77 100644 --- a/internal/core/gen.go +++ b/internal/core/gen.go @@ -63,7 +63,7 @@ func Gen(genType string, specificPath string, overwrite bool) { logrus.Info("File Generated: " + absPath) } -var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*") +var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*1234567890") func RandStringRunes(n int) string { b := make([]rune, n) diff --git a/internal/entity/notify.go b/internal/entity/notify.go index 380f15372..344de8951 100644 --- a/internal/entity/notify.go +++ b/internal/entity/notify.go @@ -1,11 +1,10 @@ package entity import ( - "fmt" + "math/rand" "sync" "time" - "github.com/ArtalkJS/Artalk/internal/utils" "gorm.io/gorm" ) @@ -36,5 +35,10 @@ func (n *Notify) SetComment(comment Comment) { // 操作时的验证密钥(判断是否本人操作) func (n *Notify) GenerateKey() { - n.Key = utils.GetMD5Hash(fmt.Sprintf("%v %v %v", n.UserID, n.CommentID, time.Now().Unix())) + letterRunes := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") + b := make([]rune, 5) + for i := range b { + b[i] = letterRunes[rand.Intn(len(letterRunes))] + } + n.Key = string(b) } diff --git a/internal/query/query_find.go b/internal/query/query_find.go index 236980e03..77837e015 100644 --- a/internal/query/query_find.go +++ b/internal/query/query_find.go @@ -174,9 +174,9 @@ func FindNotify(userID uint, commentID uint) entity.Notify { return notify } -func FindNotifyByKey(key string) entity.Notify { +func FindNotifyForComment(commentID uint, key string) entity.Notify { var notify entity.Notify - DB().Where(entity.Notify{Key: key}).First(¬ify) + DB().Where(entity.Notify{CommentID: commentID, Key: key}).First(¬ify) return notify } diff --git a/server/handler/mark_read.go b/server/handler/mark_read.go index a129d876f..1cfc62a7c 100644 --- a/server/handler/mark_read.go +++ b/server/handler/mark_read.go @@ -8,6 +8,7 @@ import ( ) type ParamsMarkRead struct { + CommentID uint `form:"comment_id"` NotifyKey string `form:"notify_key"` Name string `form:"name"` @@ -22,7 +23,8 @@ type ParamsMarkRead struct { // @Summary Notify Mark Read // @Description Mark specific notification as read for user // @Tags Notify -// @Param notify_key formData string true "the notify key you want to mark as read" +// @Param comment_id formData int true "the comment id of the notify you want to mark as read" +// @Param notify_key formData string true "the key of the notify" // @Param name formData string false "the username" // @Param email formData string false "the user email" // @Param all_read formData bool false "the option if mark all user's notify as read" @@ -55,7 +57,7 @@ func MarkRead(router fiber.Router) { } // find notify - notify := query.FindNotifyByKey(p.NotifyKey) + notify := query.FindNotifyForComment(p.CommentID, p.NotifyKey) if notify.IsEmpty() { return common.RespError(c, i18n.T("{{name}} not found", Map{"name": i18n.T("Notify")})) } diff --git a/ui/packages/artalk/src/api/user.ts b/ui/packages/artalk/src/api/user.ts index d0f0cb891..4846c66db 100644 --- a/ui/packages/artalk/src/api/user.ts +++ b/ui/packages/artalk/src/api/user.ts @@ -56,12 +56,14 @@ export default class UserApi extends ApiBase { } /** 已读标记 */ - public markRead(notifyKey: string, readAll = false) { + public markRead(commentID: number, notifyKey: string, readAll = false) { const params: any = { + comment_id: commentID, notify_key: notifyKey, } if (readAll) { + delete params.comment_id delete params.notify_key params.read_all = true params.name = User.data.nick diff --git a/ui/packages/artalk/src/list/list.ts b/ui/packages/artalk/src/list/list.ts index 89df00c4e..158f993df 100644 --- a/ui/packages/artalk/src/list/list.ts +++ b/ui/packages/artalk/src/list/list.ts @@ -142,7 +142,7 @@ export default class List extends ListLite { // 已阅 API const notifyKey = Utils.getQueryParam('atk_notify_key') if (notifyKey) { - this.ctx.getApi().user.markRead(notifyKey) + this.ctx.getApi().user.markRead(commentId, notifyKey) .then(() => { this.unread = this.unread.filter(o => o.comment_id !== commentId) this.updateUnread(this.unread)