mirror of https://gitee.com/answerdev/answer.git
fix(timeline): fix the wrong TriggerUserID when accept answer
This commit is contained in:
parent
86aa282b85
commit
a3b033b9df
|
@ -2,6 +2,7 @@ package schema
|
||||||
|
|
||||||
// AcceptAnswerOperationInfo accept answer operation info
|
// AcceptAnswerOperationInfo accept answer operation info
|
||||||
type AcceptAnswerOperationInfo struct {
|
type AcceptAnswerOperationInfo struct {
|
||||||
|
TriggerUserID string
|
||||||
QuestionObjectID string
|
QuestionObjectID string
|
||||||
QuestionUserID string
|
QuestionUserID string
|
||||||
AnswerObjectID string
|
AnswerObjectID string
|
||||||
|
|
|
@ -33,23 +33,24 @@ func NewAnswerActivityService(
|
||||||
|
|
||||||
// AcceptAnswer accept answer change activity
|
// AcceptAnswer accept answer change activity
|
||||||
func (as *AnswerActivityService) AcceptAnswer(ctx context.Context,
|
func (as *AnswerActivityService) AcceptAnswer(ctx context.Context,
|
||||||
answerObjID, questionObjID, questionUserID, answerUserID string, isSelf bool) (err error) {
|
loginUserID, answerObjID, questionObjID, questionUserID, answerUserID string, isSelf bool) (err error) {
|
||||||
operationInfo := as.createAcceptAnswerOperationInfo(ctx,
|
operationInfo := as.createAcceptAnswerOperationInfo(ctx, loginUserID,
|
||||||
answerObjID, questionObjID, questionUserID, answerUserID, isSelf)
|
answerObjID, questionObjID, questionUserID, answerUserID, isSelf)
|
||||||
return as.answerActivityRepo.SaveAcceptAnswerActivity(ctx, operationInfo)
|
return as.answerActivityRepo.SaveAcceptAnswerActivity(ctx, operationInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelAcceptAnswer cancel accept answer change activity
|
// CancelAcceptAnswer cancel accept answer change activity
|
||||||
func (as *AnswerActivityService) CancelAcceptAnswer(ctx context.Context,
|
func (as *AnswerActivityService) CancelAcceptAnswer(ctx context.Context,
|
||||||
answerObjID, questionObjID, questionUserID, answerUserID string) (err error) {
|
loginUserID, answerObjID, questionObjID, questionUserID, answerUserID string) (err error) {
|
||||||
operationInfo := as.createAcceptAnswerOperationInfo(ctx,
|
operationInfo := as.createAcceptAnswerOperationInfo(ctx, loginUserID,
|
||||||
answerObjID, questionObjID, questionUserID, answerUserID, false)
|
answerObjID, questionObjID, questionUserID, answerUserID, false)
|
||||||
return as.answerActivityRepo.SaveCancelAcceptAnswerActivity(ctx, operationInfo)
|
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 {
|
answerObjID, questionObjID, questionUserID, answerUserID string, isSelf bool) *schema.AcceptAnswerOperationInfo {
|
||||||
operationInfo := &schema.AcceptAnswerOperationInfo{
|
operationInfo := &schema.AcceptAnswerOperationInfo{
|
||||||
|
TriggerUserID: loginUserID,
|
||||||
QuestionObjectID: questionObjID,
|
QuestionObjectID: questionObjID,
|
||||||
QuestionUserID: questionUserID,
|
QuestionUserID: questionUserID,
|
||||||
AnswerObjectID: answerObjID,
|
AnswerObjectID: answerObjID,
|
||||||
|
@ -79,11 +80,11 @@ func (as *AnswerActivityService) getActivities(ctx context.Context, op *schema.A
|
||||||
|
|
||||||
if action == activity_type.AnswerAccept {
|
if action == activity_type.AnswerAccept {
|
||||||
t.ActivityUserID = op.QuestionUserID
|
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.
|
t.OriginalObjectID = op.QuestionObjectID // if activity is 'accept' means this question is accept the answer.
|
||||||
} else {
|
} else {
|
||||||
t.ActivityUserID = op.AnswerUserID
|
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.
|
t.OriginalObjectID = op.AnswerObjectID // if activity is 'accepted' means this answer was accepted.
|
||||||
}
|
}
|
||||||
activities = append(activities, t)
|
activities = append(activities, t)
|
||||||
|
|
|
@ -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 this question is already been answered, should cancel old answer rank
|
||||||
if oldAnswerInfo != nil {
|
if oldAnswerInfo != nil {
|
||||||
err := as.answerActivityService.CancelAcceptAnswer(
|
err := as.answerActivityService.CancelAcceptAnswer(ctx, userID,
|
||||||
ctx, questionInfo.AcceptedAnswerID, questionInfo.ID, questionInfo.UserID, oldAnswerInfo.UserID)
|
questionInfo.AcceptedAnswerID, questionInfo.ID, questionInfo.UserID, oldAnswerInfo.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if newAnswerInfo.ID != "" {
|
if newAnswerInfo.ID != "" {
|
||||||
err := as.answerActivityService.AcceptAnswer(
|
err := as.answerActivityService.AcceptAnswer(ctx, userID, newAnswerInfo.ID,
|
||||||
ctx, newAnswerInfo.ID, questionInfo.ID, questionInfo.UserID, newAnswerInfo.UserID, newAnswerInfo.UserID == userID)
|
questionInfo.ID, questionInfo.UserID, newAnswerInfo.UserID, newAnswerInfo.UserID == userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue