Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(question): If user edit question, update last edit user id

LinkinStar6b9fa98e483c
diff --git a/internal/base/middleware/accept_language.go b/internal/base/middleware/accept_language.go
index 01cdcdab..9397f351 100644
--- a/internal/base/middleware/accept_language.go
+++ b/internal/base/middleware/accept_language.go
@@ -4,10 +4,35 @@ import (
"github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/base/handler"
"github.com/gin-gonic/gin"
+ "github.com/segmentfault/pacman/i18n"
+)
+
+var (
+ langMapping = map[i18n.Language]bool{
+ i18n.LanguageChinese: true,
+ i18n.LanguageChineseTraditional: true,
+ i18n.LanguageEnglish: true,
+ i18n.LanguageGerman: true,
+ i18n.LanguageSpanish: true,
+ i18n.LanguageFrench: true,
+ i18n.LanguageItalian: true,
+ i18n.LanguageJapanese: true,
+ i18n.LanguageKorean: true,
+ i18n.LanguagePortuguese: true,
+ i18n.LanguageRussian: true,
+ i18n.LanguageVietnamese: true,
+ }
)
// ExtractAndSetAcceptLanguage extract accept language from header and set to context
func ExtractAndSetAcceptLanguage(ctx *gin.Context) {
+ // The language of our front-end configuration, like en_US
lang := handler.GetLang(ctx)
- ctx.Set(constant.AcceptLanguageFlag, lang)
+ if langMapping[lang] {
+ ctx.Set(constant.AcceptLanguageFlag, lang)
+ return
+ }
+
+ // default language
+ ctx.Set(constant.AcceptLanguageFlag, i18n.LanguageEnglish)
}
diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go
index 451e1fa1..f9fb6b07 100644
--- a/internal/service/question_common/question.go
+++ b/internal/service/question_common/question.go
@@ -297,20 +297,20 @@ func (qs *QuestionCommon) FormatQuestionsPage(
t.OperationType = askedOp
t.OperatedAt = questionInfo.CreatedAt.Unix()
t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.UserID}
- }
-
- // if no one
- if haveEdited {
- t.OperationType = modifiedOp
- t.OperatedAt = questionInfo.UpdatedAt.Unix()
- t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.LastEditUserID}
- }
+ } else {
+ // if no one
+ if haveEdited {
+ t.OperationType = modifiedOp
+ t.OperatedAt = questionInfo.UpdatedAt.Unix()
+ t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.LastEditUserID}
+ }
- if haveAnswered {
- if t.LastAnsweredAt.Unix() > t.OperatedAt {
- t.OperationType = answeredOp
- t.OperatedAt = t.LastAnsweredAt.Unix()
- t.Operator = &schema.QuestionPageRespOperator{ID: t.LastAnsweredUserID}
+ if haveAnswered {
+ if t.LastAnsweredAt.Unix() > t.OperatedAt {
+ t.OperationType = answeredOp
+ t.OperatedAt = t.LastAnsweredAt.Unix()
+ t.Operator = &schema.QuestionPageRespOperator{ID: t.LastAnsweredUserID}
+ }
}
}
formattedQuestions = append(formattedQuestions, t)
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index a5b48556..41a7f409 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -476,11 +476,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
question.UpdatedAt = now
question.PostUpdateTime = now
question.UserID = dbinfo.UserID
-
- question.LastEditUserID = "0"
- if dbinfo.UserID != req.UserID {
- question.LastEditUserID = req.UserID
- }
+ question.LastEditUserID = req.UserID
oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
if tagerr != nil {