Skip to content

Conversation

@xsahil03x
Copy link
Member

@xsahil03x xsahil03x commented Jul 3, 2025

Submit a pull request

Linear: FLU-180

Github Issue: #2083

Screenshots / Videos

Before After
Screen.Recording.2025-07-03.at.14.48.58.mov
Screen.Recording.2025-07-03.at.14.31.17.mov

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced message pagination options, allowing filtering by message creation time for more precise message retrieval.
  • Bug Fixes

    • Resolved an issue where cached messages were incorrectly cleared from channels with unread messages when accessed offline.
  • Documentation

    • Updated changelogs to reflect the latest bug fix and upcoming changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

This update modifies message pagination and state management logic in the chat client and UI packages. It removes the clearing of cached messages when querying around a message or timestamp, especially for channels with unread messages accessed offline. Additional pagination fields based on message creation time are introduced for enhanced querying.

Changes

File(s) Change Summary
packages/stream_chat/lib/src/core/api/requests.dart Added five new createdAt* fields to PaginationParams for advanced creation time filtering.
packages/stream_chat/lib/src/client/channel.dart Updated Channel.query to conditionally truncate state only for "around" queries, avoiding message loss.
packages/stream_chat_flutter_core/lib/src/stream_channel.dart Removed truncate() calls from _queryAtMessage and _queryAtTimestamp methods.
packages/stream_chat/CHANGELOG.md, packages/stream_chat_flutter_core/CHANGELOG.md Added bug fix entries referencing issue #2083 regarding cached messages and offline access.
packages/stream_chat/test/src/client/channel_test.dart Added tests verifying state truncation behavior when querying with idAround or createdAtAround.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant StreamChannelState
    participant Channel
    participant ChannelState

    UI->>StreamChannelState: Access channel with unread messages (offline)
    StreamChannelState->>Channel: Query messages at message/timestamp
    Channel->>ChannelState: (No truncate) Update state with new data
    ChannelState-->>StreamChannelState: Return updated messages (cached preserved)
    StreamChannelState-->>UI: Render messages
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent cached messages from being cleared in channels with unread messages when accessed offline (FLU-180)
Remove unnecessary truncate() calls that clear state and disrupt message loading (FLU-180)
Ensure isUpToDate flag logic does not interfere with markReadWhenAtTheBottom (FLU-180)

Suggested reviewers

  • renefloor

Poem

A channel once lost all its chat,
When offline, unread—imagine that!
But now with a hop and a clever fix,
Cached messages stay, no more tricks.
The bunnies rejoice, the chats remain,
No more message loss, no more pain! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75196d1 and e2a1358.

📒 Files selected for processing (6)
  • packages/stream_chat/CHANGELOG.md (1 hunks)
  • packages/stream_chat/lib/src/client/channel.dart (1 hunks)
  • packages/stream_chat/lib/src/core/api/requests.dart (1 hunks)
  • packages/stream_chat/test/src/client/channel_test.dart (1 hunks)
  • packages/stream_chat_flutter_core/CHANGELOG.md (1 hunks)
  • packages/stream_chat_flutter_core/lib/src/stream_channel.dart (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/stream_chat_flutter_core/lib/src/stream_channel.dart
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/stream_chat_flutter_core/CHANGELOG.md
  • packages/stream_chat/lib/src/core/api/requests.dart
  • packages/stream_chat/lib/src/client/channel.dart
  • packages/stream_chat/CHANGELOG.md
  • packages/stream_chat/test/src/client/channel_test.dart
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: analyze
  • GitHub Check: test
  • GitHub Check: build (android)
  • GitHub Check: stream_chat_flutter
  • GitHub Check: stream_chat_localizations
  • GitHub Check: stream_chat_flutter_core
  • GitHub Check: analyze_legacy_versions
  • GitHub Check: stream_chat
  • GitHub Check: stream_chat_persistence

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@xsahil03x xsahil03x requested a review from renefloor July 3, 2025 12:52
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/stream_chat/CHANGELOG.md (1)

5-6: Refine wording for clarity and grammatical correctness

The sentence currently reads a bit awkwardly (“Fixed cached messages are cleared …”) and breaks subject/verb agreement. Align it with the usual changelog style (“Fixed an issue where …”):

- - Fixed cached messages are cleared from channels with unread messages when accessed
-   offline. [[#2083]](https://github.com/GetStream/stream-chat-flutter/issues/2083)
+ - Fixed an issue where cached messages were cleared from channels with unread messages
+   when accessed offline. [[#2083]](https://github.com/GetStream/stream-chat-flutter/issues/2083)
packages/stream_chat_flutter_core/CHANGELOG.md (1)

5-6: Mirror wording fix in core package changelog

Same grammatical issue here—use “Fixed an issue where …” for consistency and readability:

- - Fixed cached messages are cleared from channels with unread messages when accessed
-   offline. [[#2083]](https://github.com/GetStream/stream-chat-flutter/issues/2083)
+ - Fixed an issue where cached messages were cleared from channels with unread messages
+   when accessed offline. [[#2083]](https://github.com/GetStream/stream-chat-flutter/issues/2083)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb25cf and 2cda2fe.

📒 Files selected for processing (5)
  • packages/stream_chat/CHANGELOG.md (1 hunks)
  • packages/stream_chat/lib/src/client/channel.dart (1 hunks)
  • packages/stream_chat/lib/src/core/api/requests.dart (1 hunks)
  • packages/stream_chat_flutter_core/CHANGELOG.md (1 hunks)
  • packages/stream_chat_flutter_core/lib/src/stream_channel.dart (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/stream_chat_flutter_core/lib/src/stream_channel.dart
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: analyze_legacy_versions
  • GitHub Check: stream_chat_flutter
  • GitHub Check: stream_chat_localizations
  • GitHub Check: stream_chat
  • GitHub Check: stream_chat_flutter_core
  • GitHub Check: stream_chat_persistence
  • GitHub Check: build (ios)
  • GitHub Check: test
  • GitHub Check: build (android)
  • GitHub Check: analyze
🔇 Additional comments (2)
packages/stream_chat/lib/src/client/channel.dart (1)

1779-1790: LGTM! Well-implemented fix for message gap prevention.

The conditional truncation logic effectively addresses the core issue from the PR. The implementation is clean and follows best practices:

  • Modern switch expression syntax with appropriate pattern matching
  • Clear comments explaining the reasoning for truncation
  • Proper null-safe method calls
  • Correct sequencing (truncate before state update)

This change should successfully prevent message gaps when querying around specific messages or timestamps while preserving cached messages in other scenarios.

packages/stream_chat/lib/src/core/api/requests.dart (1)

140-144: LGTM! Well-implemented timestamp-based pagination fields.

The addition of the five new DateTime fields (createdAtAfterOrEqual, createdAtAfter, createdAtBeforeOrEqual, createdAtBefore, createdAtAround) is properly integrated across the entire class. The implementation correctly:

  • Includes all fields in the constructor, copyWith method, and equality comparison
  • Uses consistent nullable DateTime types and proper JsonKey annotations
  • Follows the established patterns for pagination parameters
  • Supports the PR objective of improving message querying around specific timestamps for offline scenarios

@codecov
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.45%. Comparing base (d6abb6d) to head (e2a1358).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2299      +/-   ##
==========================================
+ Coverage   63.43%   63.45%   +0.02%     
==========================================
  Files         408      408              
  Lines       25555    25561       +6     
==========================================
+ Hits        16211    16221      +10     
+ Misses       9344     9340       -4     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/stream_chat/test/src/client/channel_test.dart (1)

2753-2866: Consider reducing code duplication between the two tests.

While both tests serve distinct purposes (testing idAround vs createdAtAround), there's significant structural similarity between them. Consider extracting common setup logic into a helper method to improve maintainability.

Example refactor approach:

void testTruncationBehavior(
  String testName,
  PaginationParams pagination,
  String expectedTargetMessageId,
) {
  test(testName, () async {
    // Common setup logic
    final initialMessages = [
      Message(id: 'msg1', text: 'Hello 1'),
      Message(id: 'msg2', text: 'Hello 2'),
      Message(id: 'msg3', text: 'Hello 3'),
    ];
    
    // ... rest of common logic
    
    final res = await channel.query(messagesPagination: pagination);
    
    expect(res, isNotNull);
    expect(channel.state!.messages, hasLength(5));
    expect(channel.state!.messages[2].id, expectedTargetMessageId);
    // ... common assertions
  });
}

// Usage:
testTruncationBehavior(
  'should truncate state when querying around message id',
  const PaginationParams(idAround: 'target-message-id'),
  'target-message-id',
);

testTruncationBehavior(
  'should truncate state when querying around created date',
  PaginationParams(createdAtAround: targetDate),
  'target-message',
);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cda2fe and 75196d1.

📒 Files selected for processing (1)
  • packages/stream_chat/test/src/client/channel_test.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: stream_chat_flutter
  • GitHub Check: format
  • GitHub Check: build (ios)
  • GitHub Check: analyze_legacy_versions
  • GitHub Check: stream_chat_persistence
  • GitHub Check: build (android)
  • GitHub Check: stream_chat_localizations
  • GitHub Check: stream_chat_flutter_core
  • GitHub Check: analyze
  • GitHub Check: test
  • GitHub Check: stream_chat
🔇 Additional comments (2)
packages/stream_chat/test/src/client/channel_test.dart (2)

2753-2808: Well-structured test for idAround pagination functionality.

This test properly verifies the truncation and replacement behavior when querying messages around a specific message ID. The test setup, mocking, and assertions are all appropriate and follow good testing practices.


2810-2866: Good test coverage for createdAtAround pagination.

This test effectively verifies the timestamp-based pagination functionality. The test structure mirrors the previous test appropriately while testing a distinct feature.

@xsahil03x xsahil03x force-pushed the fix/empty-channel-when-offline branch from 75196d1 to e2a1358 Compare July 3, 2025 13:50
@xsahil03x xsahil03x merged commit 367d3f8 into master Jul 3, 2025
17 checks passed
@xsahil03x xsahil03x deleted the fix/empty-channel-when-offline branch July 3, 2025 14: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.

Cached messages are cleared from channels with unread messages when accessed while offline

3 participants