@@ -21,7 +21,10 @@ package comment
21
21
22
22
import (
23
23
"context"
24
+
24
25
"github.com/apache/answer/internal/service/event_queue"
26
+ "github.com/apache/answer/internal/service/review"
27
+
25
28
"time"
26
29
27
30
"github.com/apache/answer/internal/base/constant"
@@ -50,6 +53,7 @@ type CommentRepo interface {
50
53
AddComment (ctx context.Context , comment * entity.Comment ) (err error )
51
54
RemoveComment (ctx context.Context , commentID string ) (err error )
52
55
UpdateCommentContent (ctx context.Context , commentID string , original string , parsedText string ) (err error )
56
+ UpdateCommentStatus (ctx context.Context , commentID string , status int ) (err error )
53
57
GetComment (ctx context.Context , commentID string ) (comment * entity.Comment , exist bool , err error )
54
58
GetCommentPage (ctx context.Context , commentQuery * CommentQuery ) (
55
59
comments []* entity.Comment , total int64 , err error )
@@ -88,6 +92,7 @@ type CommentService struct {
88
92
externalNotificationQueueService notice_queue.ExternalNotificationQueueService
89
93
activityQueueService activity_queue.ActivityQueueService
90
94
eventQueueService event_queue.EventQueueService
95
+ reviewService * review.ReviewService
91
96
}
92
97
93
98
// NewCommentService new comment service
@@ -103,6 +108,7 @@ func NewCommentService(
103
108
externalNotificationQueueService notice_queue.ExternalNotificationQueueService ,
104
109
activityQueueService activity_queue.ActivityQueueService ,
105
110
eventQueueService event_queue.EventQueueService ,
111
+ reviewService * review.ReviewService ,
106
112
) * CommentService {
107
113
return & CommentService {
108
114
commentRepo : commentRepo ,
@@ -116,6 +122,7 @@ func NewCommentService(
116
122
externalNotificationQueueService : externalNotificationQueueService ,
117
123
activityQueueService : activityQueueService ,
118
124
eventQueueService : eventQueueService ,
125
+ reviewService : reviewService ,
119
126
}
120
127
}
121
128
@@ -160,14 +167,21 @@ func (cs *CommentService) AddComment(ctx context.Context, req *schema.AddComment
160
167
return nil , err
161
168
}
162
169
170
+ comment .Status = cs .reviewService .AddCommentReview (ctx , comment , req .IP , req .UserAgent )
171
+ if err := cs .commentRepo .UpdateCommentStatus (ctx , comment .ID , comment .Status ); err != nil {
172
+ return nil , err
173
+ }
174
+
163
175
resp = & schema.GetCommentResp {}
164
176
resp .SetFromComment (comment )
165
177
resp .MemberActions = permission .GetCommentPermission (ctx , req .UserID , resp .UserID ,
166
178
time .Now (), req .CanEdit , req .CanDelete )
167
179
168
- commentResp , err := cs .addCommentNotification (ctx , req , resp , comment , objInfo )
169
- if err != nil {
170
- return commentResp , err
180
+ if comment .Status == entity .CommentStatusAvailable {
181
+ commentResp , err := cs .addCommentNotification (ctx , req , resp , comment , objInfo )
182
+ if err != nil {
183
+ return commentResp , err
184
+ }
171
185
}
172
186
173
187
// get user info
0 commit comments