Skip to content

Commit e75142a

Browse files
committed
fix(answer): fix incorrect notification's triggerUserID when cancel accepted answer
1 parent dd4b706 commit e75142a

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

internal/base/middleware/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (am *AuthUserMiddleware) AdminAuth() gin.HandlerFunc {
126126
return
127127
}
128128
userInfo, err := am.authService.GetAdminUserCacheInfo(ctx, token)
129-
if err != nil {
129+
if err != nil || userInfo == nil {
130130
handler.HandleResponse(ctx, errors.Forbidden(reason.UnauthorizedError), nil)
131131
ctx.Abort()
132132
return

internal/repo/activity/answer_repo.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func (ar *AnswerActivityRepo) SaveAcceptAnswerActivity(ctx context.Context, op *
5555
return nil
5656
}
5757

58-
ar.data.DB.ShowSQL(true)
5958
// save activity
6059
_, err = ar.data.DB.Transaction(func(session *xorm.Session) (result any, err error) {
6160
session = session.Context(ctx)
@@ -311,12 +310,11 @@ func (ar *AnswerActivityRepo) sendAcceptAnswerNotification(
311310
Type: schema.NotificationTypeAchievement,
312311
ObjectID: op.AnswerObjectID,
313312
ReceiverUserID: act.ActivityUserID,
313+
TriggerUserID: act.TriggerUserID,
314314
}
315315
if act.ActivityUserID == op.QuestionUserID {
316-
msg.TriggerUserID = op.AnswerUserID
317316
msg.ObjectType = constant.AnswerObjectType
318317
} else {
319-
msg.TriggerUserID = op.QuestionUserID
320318
msg.ObjectType = constant.AnswerObjectType
321319
}
322320
if msg.TriggerUserID != msg.ReceiverUserID {
@@ -329,9 +327,9 @@ func (ar *AnswerActivityRepo) sendAcceptAnswerNotification(
329327
ReceiverUserID: act.ActivityUserID,
330328
Type: schema.NotificationTypeInbox,
331329
ObjectID: op.AnswerObjectID,
330+
TriggerUserID: op.TriggerUserID,
332331
}
333332
if act.ActivityUserID != op.QuestionUserID {
334-
msg.TriggerUserID = op.QuestionUserID
335333
msg.ObjectType = constant.AnswerObjectType
336334
msg.NotificationAction = constant.NotificationAcceptAnswer
337335
ar.notificationQueueService.Send(ctx, msg)
@@ -343,15 +341,14 @@ func (ar *AnswerActivityRepo) sendCancelAcceptAnswerNotification(
343341
ctx context.Context, op *schema.AcceptAnswerOperationInfo) {
344342
for _, act := range op.Activities {
345343
msg := &schema.NotificationMsg{
344+
TriggerUserID: act.TriggerUserID,
346345
ReceiverUserID: act.ActivityUserID,
347346
Type: schema.NotificationTypeAchievement,
348347
ObjectID: op.AnswerObjectID,
349348
}
350349
if act.ActivityUserID == op.QuestionObjectID {
351-
msg.TriggerUserID = op.AnswerObjectID
352350
msg.ObjectType = constant.QuestionObjectType
353351
} else {
354-
msg.TriggerUserID = op.QuestionObjectID
355352
msg.ObjectType = constant.AnswerObjectType
356353
}
357354
if msg.TriggerUserID != msg.ReceiverUserID {

0 commit comments

Comments
 (0)