作者 郑周

1 回复文章和评论增加 通知消息

... ... @@ -2,6 +2,7 @@ package comment
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -82,12 +83,12 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
}
}
var atWhoList []*domain.User
var atWhoIds = make([]int64, 0)
if len(req.AtWho) > 0 {
uids := []int64{}
for _, val := range req.AtWho {
uids = append(uids, val.Id)
atWhoIds = append(atWhoIds, val.Id)
}
queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", uids)
queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", atWhoIds)
_, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
... ... @@ -182,6 +183,21 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
return err
}
}
// 创建回复消息
var atAllIds = make([]int64, 0)
atAllIds = append(atAllIds, newComment.ToUserId)
atAllIds = append(atAllIds, atWhoIds...)
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
if pComment != nil {
err = messageLogic.CommentReply(c, pComment.ArticleId, pComment.SectionId, pComment.Id, req.Content, atAllIds) // 对评论回复
} else {
err = messageLogic.CommentArticle(c, req.ArtitcleId, req.SectionId, req.Content, atAllIds) // 对文章回复
}
if err != nil {
return err
}
return nil
}, true)
... ...
... ... @@ -207,23 +207,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
}
// CommentArticle 评论文章
func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at)
func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, sectionId int64, content string, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, sectionId, 0, content, at)
}
// CommentReply 评论回复
func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at)
func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, content string, at []int64) (err error) {
return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, sectionId, commentId, content, at)
}
// LikeArticle 点赞文章
func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at})
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, 0, "", []int64{at})
}
// LikeComment 点赞评论
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at})
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, sectionId, commentId, "", []int64{at})
}
func (l *MiniBusinessLogic) createMessage(
... ... @@ -231,6 +231,7 @@ func (l *MiniBusinessLogic) createMessage(
msgType domain.MsgBusinessType,
optType domain.MsgBusinessOpt,
articleId int64,
sectionId int64,
commentId int64,
content string,
at []int64) (err error) {
... ... @@ -245,6 +246,7 @@ func (l *MiniBusinessLogic) createMessage(
UserId: userToken.UserId,
RecipientId: at[i],
ArticleId: articleId,
SectionId: sectionId,
CommentId: commentId,
Content: content,
}
... ...
... ... @@ -17,6 +17,7 @@ type MessageBusiness struct {
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId,omitempty"` // 文章ID
SectionId int64 `json:"sectionId,omitempty"` // 段落ID
CommentId int64 `json:"commentId,omitempty"` // 评论ID
Content string `json:"content,omitempty"` // 消息内容
CreatedAt int64 `json:",omitempty"`
... ...
... ... @@ -13,6 +13,7 @@ type MessageBusiness struct {
UserId int64 `json:"userId"` // 操作人用户ID
RecipientId int64 `json:"recipientId"` // 接收人用户ID
ArticleId int64 `json:"articleId"` // 文章ID
SectionId int64 `json:"sectionId"` // 段落ID
CommentId int64 `json:"commentId"` // 评论ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:",omitempty"`
... ... @@ -35,7 +36,7 @@ const (
const (
OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论
OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论()
OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
)
... ...