Skip to content

Conversation

xsahil03x
Copy link
Member

@xsahil03x xsahil03x commented Jul 2, 2025

Description of the pull request

The SortOption.new constructor is now deprecated in favor of the more explicit SortOption.desc and SortOption.asc named constructors. This change improves code readability by making the sorting direction immediately clear.

This commit updates all usages of SortOption.new across the codebase to use the new named constructors.

Summary by CodeRabbit

  • New Features

    • Added an "Upcoming" section to the changelog highlighting the deprecation of the SortOption.new constructor in favor of SortOption.desc and SortOption.asc.
  • Refactor

    • Updated sorting syntax throughout the app and examples to use explicit asc and desc constructors for improved clarity.
    • Changed default sorting for channel and user lists to descending order by most recent activity or creation date.
  • Bug Fixes

    • Adjusted sorting in test cases and UI to ensure channels and messages are prioritized by most recent updates.
  • Style

    • Streamlined code by replacing verbose sort option declarations with concise static constructors.

The `SortOption.new` constructor is now deprecated in favor of the more explicit `SortOption.desc` and `SortOption.asc` named constructors. This change improves code readability by making the sorting direction immediately clear.

This commit updates all usages of `SortOption.new` across the codebase to use the new named constructors.
Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

Walkthrough

This update deprecates the default SortOption constructor in favor of explicit .asc and .desc constructors, updating all usages throughout the codebase and tests. Sorting order is now always explicitly specified, with default sorts changed from ascending to descending in several areas. Documentation and changelogs were updated accordingly.

Changes

File(s) Change Summary
packages/stream_chat/CHANGELOG.md Added "Upcoming" section; announced deprecation of SortOption.new constructor.
packages/stream_chat/lib/src/core/api/sort_order.dart Deprecated SortOption default constructor; recommend .asc/.desc instead.
packages/stream_chat/test/... (all test files) Refactored all SortOption usages to use .asc/.desc; removed test for default constructor.
packages/stream_chat_flutter/example/lib/... (all example files) Updated channel list sorting to use SortOption.desc('last_message_at').
packages/stream_chat_flutter/lib/src/autocomplete/stream_mention_autocomplete_options.dart Changed user query sort to use SortOption.asc('id').
packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart Default channel sort changed to descending (.desc).
packages/stream_chat_flutter_core/lib/src/stream_member_list_controller.dart Default member sort refactored to use .asc constructor.
packages/stream_chat_flutter_core/lib/src/stream_poll_vote_list_controller.dart Default poll vote sort refactored to use .asc constructor.
packages/stream_chat_flutter_core/lib/src/stream_user_list_controller.dart Default user sort changed to descending (.desc).
sample_app/lib/pages/new_group_chat_screen.dart User list sort refactored to use SortOption.asc('name').
sample_app/lib/pages/user_mentions_page.dart Message search sort refactored to use SortOption.asc('created_at').
sample_app/lib/widgets/channel_list.dart Updated sort options to use .asc/.desc constructors explicitly.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant Controller
    participant API

    UI->>Controller: Request sorted data (e.g., channels)
    Controller->>API: Query with SortOption.asc/desc(field)
    API-->>Controller: Return sorted data
    Controller-->>UI: Display sorted data
Loading

Suggested reviewers

  • renefloor

Poem

A rabbit hopped through fields of sort,
Deprecated paths it did report.
Now asc and desc lead the way,
With clear intent in code we play.
Sorting channels, users, too—
Explicit order, bright and new!
🐇✨


📜 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 83a4afb and 4e67090.

📒 Files selected for processing (25)
  • packages/stream_chat/CHANGELOG.md (1 hunks)
  • packages/stream_chat/lib/src/core/api/sort_order.dart (1 hunks)
  • packages/stream_chat/test/src/client/channel_test.dart (2 hunks)
  • packages/stream_chat/test/src/client/client_test.dart (2 hunks)
  • packages/stream_chat/test/src/core/api/channel_api_test.dart (1 hunks)
  • packages/stream_chat/test/src/core/api/general_api_test.dart (5 hunks)
  • packages/stream_chat/test/src/core/api/polls_api_test.dart (2 hunks)
  • packages/stream_chat/test/src/core/api/reminders_api_test.dart (1 hunks)
  • packages/stream_chat/test/src/core/api/sort_order_test.dart (0 hunks)
  • packages/stream_chat/test/src/core/api/user_api_test.dart (1 hunks)
  • packages/stream_chat_flutter/example/lib/main.dart (1 hunks)
  • packages/stream_chat_flutter/example/lib/split_view.dart (1 hunks)
  • packages/stream_chat_flutter/example/lib/tutorial_part_2.dart (1 hunks)
  • packages/stream_chat_flutter/example/lib/tutorial_part_3.dart (1 hunks)
  • packages/stream_chat_flutter/example/lib/tutorial_part_4.dart (1 hunks)
  • packages/stream_chat_flutter/example/lib/tutorial_part_5.dart (1 hunks)
  • packages/stream_chat_flutter/example/lib/tutorial_part_6.dart (1 hunks)
  • packages/stream_chat_flutter/lib/src/autocomplete/stream_mention_autocomplete_options.dart (1 hunks)
  • packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart (1 hunks)
  • packages/stream_chat_flutter_core/lib/src/stream_member_list_controller.dart (1 hunks)
  • packages/stream_chat_flutter_core/lib/src/stream_poll_vote_list_controller.dart (1 hunks)
  • packages/stream_chat_flutter_core/lib/src/stream_user_list_controller.dart (1 hunks)
  • sample_app/lib/pages/new_group_chat_screen.dart (1 hunks)
  • sample_app/lib/pages/user_mentions_page.dart (1 hunks)
  • sample_app/lib/widgets/channel_list.dart (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/stream_chat/test/src/core/api/sort_order_test.dart
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: stream_chat_localizations
  • GitHub Check: stream_chat_flutter
  • GitHub Check: stream_chat_flutter_core
  • GitHub Check: build (android)
  • GitHub Check: stream_chat_persistence
  • GitHub Check: stream_chat
  • GitHub Check: build (ios)
  • GitHub Check: test
  • GitHub Check: analyze
  • GitHub Check: analyze_legacy_versions
🔇 Additional comments (26)
packages/stream_chat/lib/src/core/api/sort_order.dart (1)

44-44: Well-implemented deprecation with clear migration path.

The deprecation annotation provides clear guidance to developers on which constructors to use instead. This maintains backward compatibility while encouraging migration to more explicit APIs.

packages/stream_chat/CHANGELOG.md (1)

1-6: Clear and well-formatted changelog entry.

The changelog properly documents the deprecation and provides clear migration guidance for developers.

sample_app/lib/pages/new_group_chat_screen.dart (1)

32-32: Excellent migration to explicit sort constructor.

The change from the deprecated constructor to SortOption.asc('name') makes the sorting intention clear and explicit while maintaining the same functional behavior.

packages/stream_chat_flutter_core/lib/src/stream_user_list_controller.dart (1)

12-14: Migration to explicit constructor with intentional behavior change.

The change correctly uses the new SortOption.desc() constructor and makes the sorting direction explicit. Note that this changes the default sort behavior from ascending to descending order for user creation dates. Ensure this behavioral change is intentional and consistent with the overall product design.

packages/stream_chat/test/src/core/api/user_api_test.dart (1)

28-28: Proper test migration to explicit sort constructor.

The test correctly migrates from the deprecated constructor to SortOption<User>.desc('test-field'), making the sort direction explicit while maintaining test functionality.

sample_app/lib/pages/user_mentions_page.dart (1)

23-23: LGTM! Correct usage of the new explicit constructor.

The refactor from SortOption('created_at') to SortOption.asc('created_at') is correct and improves code readability by explicitly indicating ascending sort order. Ascending order is appropriate for message search results to show chronological order.

packages/stream_chat_flutter/example/lib/tutorial_part_4.dart (1)

73-73: LGTM! Appropriate sort direction for channel list.

The refactor to SortOption.desc('last_message_at') is correct and improves the user experience by showing the most recently active channels first, which is the expected behavior for channel lists.

packages/stream_chat/test/src/core/api/reminders_api_test.dart (1)

71-71: LGTM! Test correctly updated with new constructor.

The refactor to SortOption<MessageReminder>.desc('remindAt') properly maintains the generic type parameter and uses descending sort order, which is appropriate for reminder queries where users typically want to see the most recent reminders first.

packages/stream_chat_flutter/example/lib/tutorial_part_2.dart (1)

91-91: LGTM! Consistent with other tutorial examples.

The refactor to SortOption.desc('last_message_at') is consistent with other tutorial files and provides better UX by prioritizing recently active channels in the list.

packages/stream_chat_flutter/example/lib/split_view.dart (1)

110-110: LGTM! Enhances split view user experience.

The refactor to SortOption.desc('last_message_at') is consistent with other examples and particularly beneficial for the split view layout where showing the most recently active channels first improves navigation efficiency.

packages/stream_chat/test/src/core/api/polls_api_test.dart (1)

334-334: LGTM! Correctly implements the new SortOption API.

The changes properly replace the deprecated constructor with explicit .desc() factory methods. The syntax is correct and maintains the same sorting logic for the test cases.

Also applies to: 384-384

packages/stream_chat_flutter_core/lib/src/stream_member_list_controller.dart (1)

13-13: LGTM! Clean refactor to the new SortOption API.

The change correctly replaces the verbose constructor with the concise .asc() factory method while maintaining appropriate ascending sort order for member creation date.

packages/stream_chat_flutter/lib/src/autocomplete/stream_mention_autocomplete_options.dart (1)

163-163: LGTM! Properly updates to the new explicit SortOption syntax.

The change correctly replaces the deprecated constructor with .asc() factory method. Ascending order by 'id' is appropriate for autocomplete functionality to ensure predictable user ordering.

packages/stream_chat_flutter_core/lib/src/stream_poll_vote_list_controller.dart (1)

13-13: LGTM! Correct implementation of the new SortOption API.

The change properly refactors from the deprecated constructor to the explicit .asc() factory method. Ascending order by creation date is appropriate for poll votes to maintain chronological ordering.

packages/stream_chat_flutter/example/lib/tutorial_part_3.dart (1)

87-87: LGTM! Great refactor with improved UX.

The change correctly adopts the new .desc() factory method and improves user experience by sorting channels with the most recent messages first, which is the expected behavior in chat applications.

packages/stream_chat_flutter/example/lib/tutorial_part_6.dart (1)

120-120: LGTM! Improved readability and better UX.

The change from SortOption('last_message_at') to SortOption.desc('last_message_at') makes the sorting direction explicit and provides better user experience by showing channels with the most recent messages first.

packages/stream_chat_flutter/example/lib/tutorial_part_5.dart (1)

77-77: LGTM! Consistent with deprecation pattern.

The explicit .desc constructor improves code readability and aligns with the deprecation of the default SortOption constructor. Sorting channels by most recent messages first provides better UX.

packages/stream_chat/test/src/core/api/channel_api_test.dart (1)

125-125: LGTM! Test updated for new SortOption syntax.

The change maintains test coverage while using the explicit .desc constructor, aligning with the deprecation of the default SortOption constructor.

packages/stream_chat/test/src/core/api/general_api_test.dart (1)

89-89: LGTM! All test cases updated consistently.

All instances of SortOption have been updated to use the explicit .desc constructor, maintaining test coverage while aligning with the deprecation of the default constructor. The changes preserve type parameters correctly.

Also applies to: 106-106, 145-145, 190-190, 237-237

packages/stream_chat_flutter/example/lib/main.dart (1)

192-192: LGTM! Main example updated consistently.

The change to SortOption.desc('last_message_at') improves code clarity and provides better user experience by prioritizing channels with recent activity. This maintains consistency across all example applications.

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

1276-1276: Confirm .asc is declared const; otherwise drop the const keyword

The test declares

const sort = [SortOption.asc('test-sort-field')];

which requires SortOption.asc to be a const constructor. If the constructor is not marked const, the analyzer will complain. Double-check SortOption.asc’s signature and, if necessary, make the list final instead:

-const sort = [SortOption.asc('test-sort-field')];
+final sort = [SortOption.asc('test-sort-field')];
packages/stream_chat/test/src/client/client_test.dart (2)

2246-2246: Explicit descending sort constructor correctly adopted

Switching to SortOption<Poll>.desc('created_at') aligns the test with the new API and makes the intended order obvious. No issues spotted.


2288-2288: Consistent update for poll-vote sort – looks good

The test now uses the desc named constructor for PollVote as well, maintaining consistency with the refactor.

packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart (1)

14-14: LGTM! Improved UX with explicit descending sort.

The refactoring to use SortOption.desc makes the sorting direction explicit and improves readability. The change from ascending to descending order for channel listing is a good UX improvement, as users typically expect to see their most recently active channels first.

sample_app/lib/widgets/channel_list.dart (2)

31-33: LGTM! Clear sorting logic for message search.

The explicit constructors improve readability. The sorting logic is sensible: pinned channels first (descending), then by creation date (ascending, oldest first).


60-65: LGTM! Consistent sorting for channel list.

The refactoring to explicit constructors improves code clarity. The descending sort for both pinnedAt and lastMessageAt ensures pinned channels appear first, followed by channels with the most recent activity - excellent UX for a chat application.


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.

Copy link

codecov bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 63.44%. Comparing base (83a4afb) to head (4e67090).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ocomplete/stream_mention_autocomplete_options.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2295   +/-   ##
=======================================
  Coverage   63.43%   63.44%           
=======================================
  Files         408      408           
  Lines       25555    25555           
=======================================
+ Hits        16211    16213    +2     
+ Misses       9344     9342    -2     

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

@xsahil03x xsahil03x merged commit 4eb25cf into master Jul 2, 2025
18 of 19 checks passed
@xsahil03x xsahil03x deleted the refactor/deprecate-primary-sort-option-constructor branch July 2, 2025 11:43
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