Skip to content

fix(llc): keep reaction group while its count stays positive - #2859

Merged
xsahil03x merged 4 commits into
v9from
port/master-to-v9/FLU-663_keep-reaction-group-on-delete
Jul 31, 2026
Merged

fix(llc): keep reaction group while its count stays positive#2859
xsahil03x merged 4 commits into
v9from
port/master-to-v9/FLU-663_keep-reaction-group-on-delete

Conversation

@xsahil03x

@xsahil03x xsahil03x commented Jul 31, 2026

Copy link
Copy Markdown
Member

Port of #2858 to v9.

Summary

Message dropped an entire ReactionGroup in two places when a group's summed scores were non-positive, even though its count was still positive — so count-based reaction UIs lost other users' reactions:

  1. deleteMyReaction (optimistic delete) kept a group only when count > 0 && sumScores > 0. A group whose scores net to zero/negative vanished during the optimistic delete until the next server event.
  2. _maybeGetReactionGroups (derives groups from the deprecated reactionCounts/reactionScores) discarded a group when sumScores == 0, dropping a still-populated group.

Root cause / backend alignment

The backend derives reaction groups from the reactions table via count(type) / sum(score) grouped by (message_id, type). A group exists iff at least one reaction row remains (count >= 1); sum(score) is an independent aggregate that may legitimately be 0 or negative and never gates whether the group exists.

Both call sites now gate purely on the count.

Changes

  • deleteMyReaction: retain the group while updatedCount > 0.
  • _maybeGetReactionGroups: retain the group while count > 0 (guard count <= 0 so a malformed negative count can't build an invalid group).
  • Regression tests: realistic delete-path fixture (own score: 1, other score: -1) and a legacy-fields test (via the deprecated params) covering zero and negative score totals.
  • stream_chat CHANGELOG entries.

Testing

flutter test test/src/core/models/message_test.dart test/src/core/models/message_reaction_helper_test.dart — all pass.

Fixes FLU-663

🤖 Generated with Claude Code

Message.deleteMyReaction dropped the entire ReactionGroup whenever the
updated sumScores reached 0, even while the count was still greater than
zero, so count-based reaction UIs lost other users' reactions during the
optimistic delete until the next server event.

Gate the group's survival on count alone, mirroring the backend which
derives groups from the reaction count (sum of scores is an independent
aggregate that may legitimately be zero).

Port of #2858 to v9.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d4964e37-efea-4740-b9bf-60a3746fb062

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

xsahil03x and others added 3 commits July 31, 2026 13:11
The _maybeGetReactionGroups fallback that derives reaction groups from
the old reaction_counts/reaction_scores maps dropped a group when its
sum_scores was 0, discarding a still-populated group. Gate on count
only, matching the delete-path fix; the score sum may legitimately be
zero or negative. Also trims the reaction-group comments to one terse
line each.

Port of the review follow-up on #2858.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Guard the legacy synthesizer on count <= 0 so a malformed negative
  count can't build an invalid ReactionGroup.
- Use a realistic delete-path fixture (own score 1, other score -1)
  instead of unreachable score 0 reactions.
- Derive the legacy-payload test from the deprecated reactionCounts/
  reactionScores params (a real Message) covering a zero/negative total.

Port of the review follow-up on #2858.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@xsahil03x xsahil03x changed the title fix(llc): keep reaction group while count stays positive on delete fix(llc): keep reaction group while its count stays positive Jul 31, 2026
@xsahil03x
xsahil03x enabled auto-merge (squash) July 31, 2026 11:26
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v9@952c190). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff          @@
##             v9    #2859   +/-   ##
=====================================
  Coverage      ?   67.32%           
=====================================
  Files         ?      431           
  Lines         ?    27370           
  Branches      ?        0           
=====================================
  Hits          ?    18427           
  Misses        ?     8943           
  Partials      ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xsahil03x
xsahil03x merged commit 715e9d7 into v9 Jul 31, 2026
26 checks passed
@xsahil03x
xsahil03x deleted the port/master-to-v9/FLU-663_keep-reaction-group-on-delete branch July 31, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants