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.

fix(question): update latest reactions when removing

LinkinStarse3b483519ebc
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