作者 郑周

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

@@ -2,6 +2,7 @@ package comment @@ -2,6 +2,7 @@ package comment
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
5 6
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -82,12 +83,12 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -82,12 +83,12 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
82 } 83 }
83 } 84 }
84 var atWhoList []*domain.User 85 var atWhoList []*domain.User
  86 + var atWhoIds = make([]int64, 0)
85 if len(req.AtWho) > 0 { 87 if len(req.AtWho) > 0 {
86 - uids := []int64{}  
87 for _, val := range req.AtWho { 88 for _, val := range req.AtWho {
88 - uids = append(uids, val.Id) 89 + atWhoIds = append(atWhoIds, val.Id)
89 } 90 }
90 - queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", uids) 91 + queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", atWhoIds)
91 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption) 92 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
92 if err != nil { 93 if err != nil {
93 return nil, xerr.NewErrMsgErr("检查@的人员失败", err) 94 return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
@@ -182,6 +183,21 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -182,6 +183,21 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
182 return err 183 return err
183 } 184 }
184 } 185 }
  186 +
  187 + // 创建回复消息
  188 + var atAllIds = make([]int64, 0)
  189 + atAllIds = append(atAllIds, newComment.ToUserId)
  190 + atAllIds = append(atAllIds, atWhoIds...)
  191 + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
  192 + if pComment != nil {
  193 + err = messageLogic.CommentReply(c, pComment.ArticleId, pComment.SectionId, pComment.Id, req.Content, atAllIds) // 对评论回复
  194 + } else {
  195 + err = messageLogic.CommentArticle(c, req.ArtitcleId, req.SectionId, req.Content, atAllIds) // 对文章回复
  196 + }
  197 + if err != nil {
  198 + return err
  199 + }
  200 +
185 return nil 201 return nil
186 }, true) 202 }, true)
187 203
@@ -207,23 +207,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -207,23 +207,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
207 } 207 }
208 208
209 // CommentArticle 评论文章 209 // CommentArticle 评论文章
210 -func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) {  
211 - return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at) 210 +func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, sectionId int64, content string, at []int64) (err error) {
  211 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, sectionId, 0, content, at)
212 } 212 }
213 213
214 // CommentReply 评论回复 214 // CommentReply 评论回复
215 -func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) {  
216 - return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at) 215 +func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, content string, at []int64) (err error) {
  216 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, sectionId, commentId, content, at)
217 } 217 }
218 218
219 // LikeArticle 点赞文章 219 // LikeArticle 点赞文章
220 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) { 220 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
221 - return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at}) 221 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, 0, "", []int64{at})
222 } 222 }
223 223
224 // LikeComment 点赞评论 224 // LikeComment 点赞评论
225 -func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {  
226 - return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at}) 225 +func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, at int64) (err error) {
  226 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, sectionId, commentId, "", []int64{at})
227 } 227 }
228 228
229 func (l *MiniBusinessLogic) createMessage( 229 func (l *MiniBusinessLogic) createMessage(
@@ -231,6 +231,7 @@ func (l *MiniBusinessLogic) createMessage( @@ -231,6 +231,7 @@ func (l *MiniBusinessLogic) createMessage(
231 msgType domain.MsgBusinessType, 231 msgType domain.MsgBusinessType,
232 optType domain.MsgBusinessOpt, 232 optType domain.MsgBusinessOpt,
233 articleId int64, 233 articleId int64,
  234 + sectionId int64,
234 commentId int64, 235 commentId int64,
235 content string, 236 content string,
236 at []int64) (err error) { 237 at []int64) (err error) {
@@ -245,6 +246,7 @@ func (l *MiniBusinessLogic) createMessage( @@ -245,6 +246,7 @@ func (l *MiniBusinessLogic) createMessage(
245 UserId: userToken.UserId, 246 UserId: userToken.UserId,
246 RecipientId: at[i], 247 RecipientId: at[i],
247 ArticleId: articleId, 248 ArticleId: articleId,
  249 + SectionId: sectionId,
248 CommentId: commentId, 250 CommentId: commentId,
249 Content: content, 251 Content: content,
250 } 252 }
@@ -17,6 +17,7 @@ type MessageBusiness struct { @@ -17,6 +17,7 @@ type MessageBusiness struct {
17 UserId int64 `json:"userId"` // 操作人用户ID 17 UserId int64 `json:"userId"` // 操作人用户ID
18 RecipientId int64 `json:"recipientId"` // 接收人用户ID 18 RecipientId int64 `json:"recipientId"` // 接收人用户ID
19 ArticleId int64 `json:"articleId,omitempty"` // 文章ID 19 ArticleId int64 `json:"articleId,omitempty"` // 文章ID
  20 + SectionId int64 `json:"sectionId,omitempty"` // 段落ID
20 CommentId int64 `json:"commentId,omitempty"` // 评论ID 21 CommentId int64 `json:"commentId,omitempty"` // 评论ID
21 Content string `json:"content,omitempty"` // 消息内容 22 Content string `json:"content,omitempty"` // 消息内容
22 CreatedAt int64 `json:",omitempty"` 23 CreatedAt int64 `json:",omitempty"`
@@ -13,6 +13,7 @@ type MessageBusiness struct { @@ -13,6 +13,7 @@ type MessageBusiness struct {
13 UserId int64 `json:"userId"` // 操作人用户ID 13 UserId int64 `json:"userId"` // 操作人用户ID
14 RecipientId int64 `json:"recipientId"` // 接收人用户ID 14 RecipientId int64 `json:"recipientId"` // 接收人用户ID
15 ArticleId int64 `json:"articleId"` // 文章ID 15 ArticleId int64 `json:"articleId"` // 文章ID
  16 + SectionId int64 `json:"sectionId"` // 段落ID
16 CommentId int64 `json:"commentId"` // 评论ID 17 CommentId int64 `json:"commentId"` // 评论ID
17 Content string `json:"content"` // 消息内容 18 Content string `json:"content"` // 消息内容
18 CreatedAt int64 `json:",omitempty"` 19 CreatedAt int64 `json:",omitempty"`
@@ -35,7 +36,7 @@ const ( @@ -35,7 +36,7 @@ const (
35 36
36 const ( 37 const (
37 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章 38 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
38 - OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论 39 + OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论()
39 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论 40 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
40 ) 41 )
41 42