-
Notifications
You must be signed in to change notification settings - Fork 368
feat(llc): add support for client.getUnreadCount()
#2300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis update introduces support for the Changes
Sequence Diagram(s)sequenceDiagram
participant ClientApp
participant StreamChatClient
participant UserApi
participant API_Server
ClientApp->>StreamChatClient: getUnreadCount()
StreamChatClient->>UserApi: getUnreadCount()
UserApi->>API_Server: GET /unread
API_Server-->>UserApi: GetUnreadCountResponse JSON
UserApi-->>StreamChatClient: GetUnreadCountResponse
StreamChatClient-->>ClientApp: GetUnreadCountResponse
Assessment against linked issues
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (11)
🚧 Files skipped from review as they are similar to previous changes (11)
⏰ Context from checks skipped due to timeout of 90000ms (10)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
packages/stream_chat/CHANGELOG.md
(1 hunks)packages/stream_chat/lib/src/client/client.dart
(1 hunks)packages/stream_chat/lib/src/core/api/responses.dart
(2 hunks)packages/stream_chat/lib/src/core/api/responses.g.dart
(1 hunks)packages/stream_chat/lib/src/core/api/user_api.dart
(1 hunks)packages/stream_chat/lib/src/core/models/unread_counts.dart
(1 hunks)packages/stream_chat/lib/src/core/models/unread_counts.g.dart
(1 hunks)packages/stream_chat/lib/stream_chat.dart
(1 hunks)packages/stream_chat/test/src/client/client_test.dart
(1 hunks)packages/stream_chat/test/src/core/api/user_api_test.dart
(1 hunks)packages/stream_chat/test/src/core/models/unread_counts_test.dart
(1 hunks)
🔇 Additional comments (11)
packages/stream_chat/lib/stream_chat.dart (1)
61-61
: LGTM! Clean export addition.The export statement correctly exposes the unread counts models following the established pattern and maintains alphabetical ordering.
packages/stream_chat/lib/src/core/api/user_api.dart (1)
92-97
: LGTM! Well-implemented API method.The
getUnreadCount()
method follows the established patterns in the codebase:
- Clear documentation
- Proper async/await usage
- Consistent endpoint pattern
- Standard response parsing with JSON deserialization
packages/stream_chat/lib/src/client/client.dart (1)
1550-1562
: LGTM! Well-implemented unread count method.The implementation correctly:
- Fetches unread count data from the API
- Updates the client state with the response data
- Uses array lengths for
unreadChannels
andunreadThreads
counts, which aligns with the response structure- Follows the established pattern for async client methods
The state update approach using
response.channels.length
andresponse.threads.length
is appropriate since these represent the actual unread channels and threads for the user.packages/stream_chat/lib/src/core/models/unread_counts.g.dart (1)
1-55
: Generated serialization code looks correct.The JSON serialization/deserialization functions follow the expected
json_serializable
patterns:
- Proper type conversions for numeric fields using
.toInt()
- Correct DateTime handling with
DateTime.parse()
and.toIso8601String()
- Appropriate field name mappings between snake_case and camelCase
No issues with the generated code.
packages/stream_chat/test/src/core/api/user_api_test.dart (1)
186-248
: Excellent comprehensive test coverage.The test thoroughly validates the
getUnreadCount
functionality:
- Mocks realistic response data with all expected fields
- Verifies proper deserialization of complex nested structures (channels, threads, channel types)
- Tests both simple fields (counts) and complex data (team mappings, arrays)
- Confirms correct HTTP method (GET) and endpoint path (
/unread
)- Uses proper verification patterns to ensure no unexpected interactions
The mock data structure closely matches what would be expected from the actual API, providing good confidence in the integration.
packages/stream_chat/test/src/client/client_test.dart (2)
2634-2652
: LGTM! Well-structured basic functionality test.The test properly covers the happy path scenario for
getUnreadCount()
with appropriate mocking, clear assertions, and proper API interaction verification.
2654-2696
: Excellent state management test coverage!This test effectively verifies that
getUnreadCount()
not only returns the correct response but also properly updates the client's current user state. The comprehensive mock data with realisticUnreadCountsChannel
andUnreadCountsThread
objects provides thorough coverage of the state update functionality.packages/stream_chat/lib/src/core/api/responses.g.dart (1)
471-491
: Generated JSON deserialization looks correct.The generated deserialization function properly handles the new unread count response fields. The nullable
totalUnreadCountByTeam
field is correctly handled with optional mapping, while required fields are directly cast as expected from the source model annotations.packages/stream_chat/test/src/core/models/unread_counts_test.dart (1)
1-127
: Excellent comprehensive test coverage!The tests thoroughly validate JSON serialization and deserialization for all three unread count models with realistic test data. The additional test for different channel types demonstrates good edge case consideration.
packages/stream_chat/lib/src/core/api/responses.dart (1)
21-21
: LGTM!The import for unread_counts.dart is properly added to support the new response model.
packages/stream_chat/lib/src/core/models/unread_counts.dart (1)
1-95
: Well-designed immutable data models!The three unread count model classes follow excellent design principles:
- Immutable design with
final
fields andconst
constructors- Comprehensive documentation with clear field descriptions
- Consistent API patterns across all models
- Appropriate type choices for each field
The models provide a clean abstraction for unread count data at different granularities (channel, thread, and channel type levels).
850a817
to
21ef438
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2300 +/- ##
==========================================
+ Coverage 63.45% 63.50% +0.04%
==========================================
Files 408 409 +1
Lines 25561 25584 +23
==========================================
+ Hits 16221 16247 +26
+ Misses 9340 9337 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Submit a pull request
Fixes: #2298
Summary by CodeRabbit