Skip to content

Conversation

@VelikovPetar
Copy link
Contributor

@VelikovPetar VelikovPetar commented Dec 24, 2025

🎯 Goal

Incoming messages from muted users don't increase the unread count server-side, so we shouldn't increase it client-side as well.

🛠 Implementation details

Add guard in ChannelStateLogic.updateCurrentUserRead preventing the unread count from increasing for messages from muted users.

🎨 UI Changes

Before After
muted_before.mov
muted_after.mov

🧪 Testing

  1. Open channel list with user A (ex. Petar Velikov)
  2. From a different device, send a message from a user muted by user A (ex. Lando Calrissian)
  3. User A should not have its unread count increased by the messages from the current user
  4. Verify this is correct by logging in and out - refreshing the channel list would give you the correct unread count from the server

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed an issue where unread message counts were incorrectly increasing when receiving messages from muted users. Messages from users on your mute list are now properly excluded from unread calculations. This ensures your channel unread counts and notification indicators remain accurate.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.25 MB 5.25 MB 0.00 MB 🟢
stream-chat-android-offline 5.48 MB 5.48 MB 0.00 MB 🟢
stream-chat-android-ui-components 10.60 MB 10.60 MB 0.00 MB 🟢
stream-chat-android-compose 12.81 MB 12.81 MB 0.00 MB 🟢

@sonarqubecloud
Copy link

@VelikovPetar VelikovPetar marked this pull request as ready for review December 25, 2025 04:31
@VelikovPetar VelikovPetar requested a review from a team as a code owner December 25, 2025 04:31
@coderabbitai
Copy link

coderabbitai bot commented Dec 25, 2025

Walkthrough

This PR fixes a bug where messages from globally muted users were incorrectly incrementing the channel's unread count. A guard condition in the updateCurrentUserRead method now skips processing messages from muted users, with a corresponding test added to verify the fix.

Changes

Cohort / File(s) Summary
Documentation & Changelog
CHANGELOG.md
Added entry documenting the fix for messages from muted users incrementing unread count.
Core Logic Fix
stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt
Added guard in updateCurrentUserRead to check if the message sender is a globally muted user via globalMutableState.muted. If muted, the message is marked as processed and the function returns early, preventing unread count updates.
Test Coverage
stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogicTest.kt
Added new test case verifying that unread count is not updated when a message originates from a globally muted user, asserting mutableState.upsertReads is never invoked.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • gpunto
  • testableapple

Poem

🐰 A muted voice now rests in peace,
No unread counts for those on cease,
Read receipts skip the silenced few,
Channel counts now honest and true! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly summarizes the main change: preventing messages from muted users from increasing the unread count.
Description check ✅ Passed The description covers the required sections with concrete goals, implementation details, UI demonstration videos, and testing steps. While some checklist items are not explicitly marked, the core descriptive content is complete and thorough.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/AND-989_fix_messages_from_muted_user_increasing_unread_count

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d6a612b and 4e66a2a.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt
  • stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogicTest.kt
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{kt,kts}

📄 CodeRabbit inference engine (AGENTS.md)

Format and apply Kotlin style with Spotless (4 spaces, no wildcard imports, licence headers)

Files:

  • stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt
  • stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogicTest.kt
**/*.kt

📄 CodeRabbit inference engine (AGENTS.md)

**/*.kt: Use @OptIn annotations explicitly; avoid suppressions unless documented
Document public APIs with KDoc, including thread expectations and state notes

Files:

  • stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt
  • stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogicTest.kt
**/src/test/**/*.kt

📄 CodeRabbit inference engine (AGENTS.md)

**/src/test/**/*.kt: Use backtick test names (for example: fun message list filters muted channels()) for readability
Use deterministic tests with runTest + virtual time for concurrency-sensitive logic (uploads, sync, message state)
Keep helper extensions private/internal in test files

Files:

  • stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogicTest.kt
🧬 Code graph analysis (1)
stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogicTest.kt (1)
stream-chat-android-core/src/testFixtures/kotlin/io/getstream/chat/android/Mother.kt (4)
  • randomUser (182-228)
  • randomChannelUserRead (485-501)
  • randomString (94-98)
  • randomMessage (302-399)
🔇 Additional comments (3)
CHANGELOG.md (1)

38-38: Changelog entry is clear and consistent.

The new bullet accurately describes the fix, is placed under the correct module and section, and follows the existing formatting/linking conventions.

stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt (1)

889-894: LGTM! Guard correctly prevents unread count increase for muted users.

The implementation correctly checks if the message author is in the global mute list and skips processing accordingly. The logic is consistent with other guards in this method, uses safe navigation appropriately, and is placed in a logical position in the guard sequence (after the current user check, before the shadowed check).

stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogicTest.kt (1)

564-597: LGTM! Well-structured test verifying muted user behavior.

The test correctly verifies that messages from globally muted users don't increase the unread count. It follows the coding guidelines with backtick naming, uses a clear Given-When-Then structure, and properly configures the global mute state to test the guard condition.


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 and usage tips.

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