You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/06/07 08:50:43 UTC

(incubator-answer) branch fix/1.3.5/question updated: fix(question): update latest reactions when removing

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

linkinstar pushed a commit to branch fix/1.3.5/question
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/fix/1.3.5/question by this push:
     new e3b48351 fix(question): update latest reactions when removing
e3b48351 is described below

commit e3b483519ebcae31effae05695b89c13944145d2
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Fri Jun 7 16:49:51 2024 +0800

    fix(question): update latest reactions when removing
---
 internal/schema/meta_schema.go | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/internal/schema/meta_schema.go b/internal/schema/meta_schema.go
index 60f32ba0..286e2e7d 100644
--- a/internal/schema/meta_schema.go
+++ b/internal/schema/meta_schema.go
@@ -68,18 +68,24 @@ func (r *ReactionsSummaryMeta) AddReactionSummary(emoji, userID string) {
 
 // RemoveReactionSummary remove user operation from reaction summary
 func (r *ReactionsSummaryMeta) RemoveReactionSummary(emoji, userID string) {
+	updatedReactions := make([]*ReactionSummaryMeta, 0)
 	for _, reaction := range r.Reactions {
-		if reaction.Emoji != emoji {
+		if reaction.Emoji != emoji && len(reaction.UserIDs) > 0 {
+			updatedReactions = append(updatedReactions, reaction)
 			continue
 		}
-		updated := make([]string, 0, len(r.Reactions))
+		updatedUserIDs := make([]string, 0, len(r.Reactions))
 		for _, id := range reaction.UserIDs {
 			if id != userID {
-				updated = append(updated, id)
+				updatedUserIDs = append(updatedUserIDs, id)
 			}
 		}
-		reaction.UserIDs = updated
+		if len(updatedUserIDs) > 0 {
+			reaction.UserIDs = updatedUserIDs
+			updatedReactions = append(updatedReactions, reaction)
+		}
 	}
+	r.Reactions = updatedReactions
 }
 
 // CheckUserInReactionSummary check user's operation if in reaction summary