fix(timeline): fix the wrong TriggerUserID when accept answer

This commit is contained in:
LinkinStars 2023-07-20 19:20:40 +08:00
parent 86aa282b85
commit a3b033b9df
3 changed files with 13 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package schema
// AcceptAnswerOperationInfo accept answer operation info
type AcceptAnswerOperationInfo struct {
TriggerUserID string
QuestionObjectID string
QuestionUserID string
AnswerObjectID string

View File

@ -33,23 +33,24 @@ func NewAnswerActivityService(
// AcceptAnswer accept answer change activity
func (as *AnswerActivityService) AcceptAnswer(ctx context.Context,
answerObjID, questionObjID, questionUserID, answerUserID string, isSelf bool) (err error) {
operationInfo := as.createAcceptAnswerOperationInfo(ctx,
loginUserID, answerObjID, questionObjID, questionUserID, answerUserID string, isSelf bool) (err error) {
operationInfo := as.createAcceptAnswerOperationInfo(ctx, loginUserID,
answerObjID, questionObjID, questionUserID, answerUserID, isSelf)
return as.answerActivityRepo.SaveAcceptAnswerActivity(ctx, operationInfo)
}
// CancelAcceptAnswer cancel accept answer change activity
func (as *AnswerActivityService) CancelAcceptAnswer(ctx context.Context,
answerObjID, questionObjID, questionUserID, answerUserID string) (err error) {
operationInfo := as.createAcceptAnswerOperationInfo(ctx,
loginUserID, answerObjID, questionObjID, questionUserID, answerUserID string) (err error) {
operationInfo := as.createAcceptAnswerOperationInfo(ctx, loginUserID,
answerObjID, questionObjID, questionUserID, answerUserID, false)
return as.answerActivityRepo.SaveCancelAcceptAnswerActivity(ctx, operationInfo)
}
func (as *AnswerActivityService) createAcceptAnswerOperationInfo(ctx context.Context,
func (as *AnswerActivityService) createAcceptAnswerOperationInfo(ctx context.Context, loginUserID,
answerObjID, questionObjID, questionUserID, answerUserID string, isSelf bool) *schema.AcceptAnswerOperationInfo {
operationInfo := &schema.AcceptAnswerOperationInfo{
TriggerUserID: loginUserID,
QuestionObjectID: questionObjID,
QuestionUserID: questionUserID,
AnswerObjectID: answerObjID,
@ -79,11 +80,11 @@ func (as *AnswerActivityService) getActivities(ctx context.Context, op *schema.A
if action == activity_type.AnswerAccept {
t.ActivityUserID = op.QuestionUserID
t.TriggerUserID = op.AnswerUserID
t.TriggerUserID = op.TriggerUserID
t.OriginalObjectID = op.QuestionObjectID // if activity is 'accept' means this question is accept the answer.
} else {
t.ActivityUserID = op.AnswerUserID
t.TriggerUserID = op.AnswerUserID
t.TriggerUserID = op.TriggerUserID
t.OriginalObjectID = op.AnswerObjectID // if activity is 'accepted' means this answer was accepted.
}
activities = append(activities, t)

View File

@ -390,15 +390,15 @@ func (as *AnswerService) updateAnswerRank(ctx context.Context, userID string,
) {
// if this question is already been answered, should cancel old answer rank
if oldAnswerInfo != nil {
err := as.answerActivityService.CancelAcceptAnswer(
ctx, questionInfo.AcceptedAnswerID, questionInfo.ID, questionInfo.UserID, oldAnswerInfo.UserID)
err := as.answerActivityService.CancelAcceptAnswer(ctx, userID,
questionInfo.AcceptedAnswerID, questionInfo.ID, questionInfo.UserID, oldAnswerInfo.UserID)
if err != nil {
log.Error(err)
}
}
if newAnswerInfo.ID != "" {
err := as.answerActivityService.AcceptAnswer(
ctx, newAnswerInfo.ID, questionInfo.ID, questionInfo.UserID, newAnswerInfo.UserID, newAnswerInfo.UserID == userID)
err := as.answerActivityService.AcceptAnswer(ctx, userID, newAnswerInfo.ID,
questionInfo.ID, questionInfo.UserID, newAnswerInfo.UserID, newAnswerInfo.UserID == userID)
if err != nil {
log.Error(err)
}