This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer.git


The following commit(s) were added to refs/heads/dev by this push:
     new 4b9fd397 refactor: simplify operation type assignment logic in 
question handling
4b9fd397 is described below

commit 4b9fd397db8efc28ca477e961d947716525df0df
Author: Luffy <[email protected]>
AuthorDate: Tue Mar 4 12:41:23 2025 +0800

    refactor: simplify operation type assignment logic in question handling
---
 internal/service/question_common/question.go | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/internal/service/question_common/question.go 
b/internal/service/question_common/question.go
index 866f0486..a0a5f413 100644
--- a/internal/service/question_common/question.go
+++ b/internal/service/question_common/question.go
@@ -409,19 +409,18 @@ func (qs *QuestionCommon) FormatQuestionsPage(
                        }
                }
 
-               // if order condition is newest or nobody edited or nobody 
answered, only show question author
-               if orderCond == schema.QuestionOrderCondNewest || (!haveEdited 
&& !haveAnswered) {
-                       t.OperationType = 
schema.QuestionPageRespOperationTypeAsked
-                       t.OperatedAt = questionInfo.CreatedAt.Unix()
-                       t.Operator = &schema.QuestionPageRespOperator{ID: 
questionInfo.UserID}
-               } else {
-                       // if no one
+               // The default operation is to ask questions
+               t.OperationType = schema.QuestionPageRespOperationTypeAsked
+               t.OperatedAt = questionInfo.CreatedAt.Unix()
+               t.Operator = &schema.QuestionPageRespOperator{ID: 
questionInfo.UserID}
+
+               // If the order is active, the last operation time is the last 
edit or answer time if it exists
+               if orderCond == schema.QuestionOrderCondActive {
                        if haveEdited {
                                t.OperationType = 
schema.QuestionPageRespOperationTypeModified
                                t.OperatedAt = questionInfo.UpdatedAt.Unix()
                                t.Operator = 
&schema.QuestionPageRespOperator{ID: questionInfo.LastEditUserID}
                        }
-
                        if haveAnswered {
                                if t.LastAnsweredAt.Unix() > t.OperatedAt {
                                        t.OperationType = 
schema.QuestionPageRespOperationTypeAnswered
@@ -430,6 +429,7 @@ func (qs *QuestionCommon) FormatQuestionsPage(
                                }
                        }
                }
+
                formattedQuestions = append(formattedQuestions, t)
        }
 

Reply via email to