Skip to content

fix(ui): skip markThreadRead for reply-less thread parents - #2807

Merged
xsahil03x merged 1 commit into
masterfrom
bug/skip_mark_thread_read_when_no_replies
Jul 13, 2026
Merged

fix(ui): skip markThreadRead for reply-less thread parents#2807
xsahil03x merged 1 commit into
masterfrom
bug/skip_mark_thread_read_when_no_replies

Conversation

@xsahil03x

@xsahil03x xsahil03x commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

Opening a thread on a parent with no replies produced a guaranteed StreamChatNetworkError 404 (Can't find thread with id ...) every time. _maybeMarkMessagesAsRead unconditionally called channel.markThreadRead(parentId) when in a thread, but the server-side thread object only exists after the first reply lands.

Guard added to _maybeMarkMessagesAsRead in thread mode: skip when the parent's replyCount is 0. Matches the iOS SDK's precedent in ChatThreadVC.shouldMarkThreadRead (if messageController.replies.isEmpty { return false }, comment: "If there are no replies, no thread is yet created").

Fixes #2806.

Why replyCount on the parent

  • replyCount is server-owned and populated via message.updated on the parent — nothing in the LLC bumps it locally, so it stays at 0 for optimistic-only replies too. Both "no replies" and "one local-only reply" produce the same replyCount == 0, and both cases want the same behavior: skip → no 404.
  • Alternative (channel.state.threads[parentId]?.isEmpty) is less robust — the client's thread map is only populated once thread messages are paged in.

Test plan

  • New regression test in mark_read_test.dart:
    • does NOT fire when parentMessage.replyCount is 0 — the load-bearing guard.
    • fires when parentMessage.replyCount > 0 — happy path.
    • does NOT fire markRead (channel-level) when in a thread — invariant guard.
  • Verified the regression test fails on master without the guard (MockChannel.markThreadRead(parent-id) was called) and passes with the guard.
  • dart analyze clean, dart format clean.

Follow-up

  • v9 backport is in a parallel PR (branch bug/skip_mark_thread_read_when_no_replies_v9).
  • Cross-SDK check: Android (MessageListController.markLastMessageReadInternal) has the same latent bug and no explicit guard — worth tracking as a separate ticket if not already.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed thread read-status marking so parent messages with no replies are no longer updated, preventing repeatable errors when opening a thread before the first reply.
    • Ensured thread views still correctly mark replies as read once the thread is available.
    • Confirmed thread mode no longer triggers channel-level read updates when thread-specific unread counts are present.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d52d7eca-2dcb-48c5-985c-28d6a66635cb

📥 Commits

Reviewing files that changed from the base of the PR and between b65a0c8 and fb21f13.

📒 Files selected for processing (3)
  • packages/stream_chat_flutter/CHANGELOG.md
  • packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart
  • packages/stream_chat_flutter/test/src/message_list_view/mark_read_test.dart
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/stream_chat_flutter/CHANGELOG.md
  • packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart

📝 Walkthrough

Walkthrough

StreamMessageListView now skips markThreadRead when a thread parent has no replies. Mark-read tests add thread state and verify reply-count gating, thread-level marking, and channel-level read suppression.

Changes

Thread read gating

Layer / File(s) Summary
Guard thread read marking
packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart, packages/stream_chat_flutter/CHANGELOG.md
Thread read marking returns early for reply-less parents, and the changelog records the fix.
Validate thread read gates
packages/stream_chat_flutter/test/src/message_list_view/mark_read_test.dart
Tests configure thread state and verify markThreadRead behavior based on replyCount, while channel-level markRead remains unused in threads.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • #2806 — Directly tracks the markThreadRead 404 fixed by the reply-count guard and accompanying tests.

Suggested reviewers: velikovpetar, renefloor

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: skipping markThreadRead for thread parents with no replies.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug/skip_mark_thread_read_when_no_replies

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.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.24%. Comparing base (3a8b672) to head (fb21f13).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2807      +/-   ##
==========================================
+ Coverage   71.08%   71.24%   +0.15%     
==========================================
  Files         429      429              
  Lines       26892    26893       +1     
==========================================
+ Hits        19117    19159      +42     
+ Misses       7775     7734      -41     

☔ 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.

Opening a thread on a parent with no replies produced a guaranteed
StreamChatNetworkError 404 (`Can't find thread with id ...`), because
the server-side thread object doesn't exist until the first reply
lands.

Guard `_maybeMarkMessagesAsRead` in thread mode against a zero
`replyCount` on the parent — matching the iOS SDK's precedent in
`ChatThreadVC.shouldMarkThreadRead`.

Fixes #2806.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
xsahil03x added a commit that referenced this pull request Jul 13, 2026
Opening a thread on a parent with no replies produced a guaranteed
StreamChatNetworkError 404 (`Can't find thread with id ...`), because
the server-side thread object doesn't exist until the first reply
lands.

Guard `_maybeMarkMessagesAsRead` in thread mode against a zero
`replyCount` on the parent — matching the iOS SDK's precedent in
`ChatThreadVC.shouldMarkThreadRead`.

v9 backport of #2807. Fixes #2806.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@xsahil03x
xsahil03x force-pushed the bug/skip_mark_thread_read_when_no_replies branch from b65a0c8 to fb21f13 Compare July 13, 2026 12:00
@xsahil03x
xsahil03x merged commit 249a92c into master Jul 13, 2026
26 checks passed
@xsahil03x
xsahil03x deleted the bug/skip_mark_thread_read_when_no_replies branch July 13, 2026 13:33
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.

MessageListView unconditionally calls markThreadRead in threads → guaranteed 404 when opening a thread with no replies

2 participants