Skip to content

Add CurrentUserUnreads.totalUnreadCountByTeam #3733

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

Merged
merged 5 commits into from
Jul 21, 2025

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Jul 18, 2025

🔗 Issue Links

https://linear.app/stream/issue/IOS-977/unread-count-per-team-support-for-ios

🎯 Goal

Add CurrentUserUnreads.totalUnreadCountByTeam.

📝 Summary

  • Adds the new CurrentUserUnreads.totalUnreadCountByTeam when fetching all unreads.
  • Adds a view to the user profile to show all the unread counts.

🧪 Manual Testing Notes

  1. Open the Demo App
  2. Tap on the user profile (Left top corner)
  3. Tap "Show Profile"
  4. Tap "Unread Count Details"

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

Summary by CodeRabbit

  • New Features

    • Added a "Detailed Unread Counts" option in the user profile, allowing users to view unread messages broken down by total, channel type, thread, and team in a new detailed view.
    • Introduced a SwiftUI-based interface for displaying detailed unread counts with support for loading, errors, and data refresh.
    • Added unread counts grouped by team to enhance unread message tracking.
  • Bug Fixes

    • Improved test coverage to verify unread counts by team are correctly handled and displayed.
  • Tests

    • Updated tests to ensure accurate handling and display of unread counts grouped by team.

@nuno-vieira nuno-vieira requested a review from a team as a code owner July 18, 2025 16:15
Copy link

coderabbitai bot commented Jul 18, 2025

Walkthrough

A new feature was added to display detailed unread message counts, including unread counts per team, in the user profile UI. This involved extending data models, updating API payloads, integrating a SwiftUI view for detailed display, and enhancing related tests to verify the new unread-by-team functionality.

Changes

File(s) Change Summary
DemoApp/Screens/UserProfileViewController.swift Added detailed unread counts feature: new enum case, cell, SwiftUI view, and presentation logic.
Sources/StreamChat/APIClient/Endpoints/Payloads/UserPayloads.swift Added totalUnreadCountByTeam property to payload struct and coding keys.
Sources/StreamChat/Models/CurrentUser.swift Added totalUnreadCountByTeam property to model and updated conversion from payload.
Tests/StreamChatTests/Controllers/CurrentUserController/CurrentUserController_Tests.swift Updated test to verify unread counts by team in controller logic.
Tests/StreamChatTests/Workers/CurrentUserUpdater_Tests.swift Updated test to verify unread counts by team in API updater logic.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant UserProfileVC as UserProfileViewController
    participant SwiftUIView as UnreadDetailsView (SwiftUI)
    participant CurrentUserController as CurrentUserController
    participant API as API

    User->>UserProfileVC: Tap "View Details" on Detailed Unread Counts
    UserProfileVC->>SwiftUIView: Present UnreadDetailsView
    SwiftUIView->>CurrentUserController: loadAllUnreads()
    CurrentUserController->>API: Fetch unread counts (including by team)
    API-->>CurrentUserController: Return unread counts data
    CurrentUserController-->>SwiftUIView: Provide unread counts model
    SwiftUIView-->>User: Display detailed unread counts (by channel, thread, type, team)
Loading

Poem

A hop and a skip, unread counts in view,
Now by team and by channel, the numbers are true!
SwiftUI and UIKit, together they gleam,
With tests all updated, the code is a dream.
🐰📬✨
Detailed unreads—now easy to glean!


📜 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 2fa2826 and a1d86cb.

📒 Files selected for processing (1)
  • DemoApp/Screens/UserProfileViewController.swift (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • DemoApp/Screens/UserProfileViewController.swift
✨ Finishing Touches
  • 📝 Generate Docstrings

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

@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: 1

🧹 Nitpick comments (1)
DemoApp/Screens/UserProfileViewController.swift (1)

201-437: Consider breaking down the large SwiftUI view for better maintainability.

The UnreadDetailsView is quite large (200+ lines) and handles multiple responsibilities. Consider extracting each section into separate views for better code organization and reusability.

For example, you could create:

  • UnreadChannelsSection
  • UnreadThreadsSection
  • UnreadByTypeSection
  • UnreadByTeamSection

This would make the code more modular and easier to maintain.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1526065 and 65c5d9a.

📒 Files selected for processing (5)
  • DemoApp/Screens/UserProfileViewController.swift (5 hunks)
  • Sources/StreamChat/APIClient/Endpoints/Payloads/UserPayloads.swift (1 hunks)
  • Sources/StreamChat/Models/CurrentUser.swift (2 hunks)
  • Tests/StreamChatTests/Controllers/CurrentUserController/CurrentUserController_Tests.swift (2 hunks)
  • Tests/StreamChatTests/Workers/CurrentUserUpdater_Tests.swift (2 hunks)
🔇 Additional comments (5)
Tests/StreamChatTests/Workers/CurrentUserUpdater_Tests.swift (1)

744-784: LGTM! Test coverage for the new totalUnreadCountByTeam feature is properly implemented.

The test correctly:

  • Includes the new field in the payload simulation
  • Verifies the field is properly transformed and accessible in the result model
  • Maintains consistency with the existing test structure
Sources/StreamChat/Models/CurrentUser.swift (1)

129-130: LGTM! The totalUnreadCountByTeam property is correctly added to the model.

The implementation properly:

  • Declares the property as optional, which is appropriate for backward compatibility
  • Maps the value from the payload in the asModel() method
  • Maintains consistency with the existing model structure

Also applies to: 182-182

Tests/StreamChatTests/Controllers/CurrentUserController/CurrentUserController_Tests.swift (1)

804-836: LGTM! Controller test properly validates the new totalUnreadCountByTeam feature.

The test correctly verifies that the controller:

  • Receives the new property from the updater
  • Passes it through without modification
  • Maintains the expected data structure
Sources/StreamChat/APIClient/Endpoints/Payloads/UserPayloads.swift (1)

211-211: LGTM! API payload correctly implements the new totalUnreadCountByTeam field.

The implementation:

  • Uses the correct snake_case coding key following API conventions
  • Declares the property as optional for backward compatibility
  • Maintains consistency with the existing payload structure

Also applies to: 219-219

DemoApp/Screens/UserProfileViewController.swift (1)

110-114: LGTM! UI implementation correctly displays the new unread counts by team feature.

The implementation:

  • Properly integrates with the existing table view structure
  • Correctly handles async data loading with appropriate queue management
  • Displays the new totalUnreadCountByTeam data in a user-friendly format
  • Handles the optional nature of the team unread counts appropriately

Also applies to: 143-160, 353-377

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jul 18, 2025

SDK Size

title develop branch diff status
StreamChat 7.88 MB 7.88 MB 0 KB 🟢
StreamChatUI 4.84 MB 4.84 MB 0 KB 🟢

@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 8.35 ms 16.5% 🔼 🟢
Duration 2.6 s 2.54 s 2.31% 🔼 🟢
Hitch time ratio 4 ms per s 3.28 ms per s 18.0% 🔼 🟢
Frame rate 75 fps 78.09 fps 4.12% 🔼 🟢
Number of hitches 1 1.0 0.0% 🟰 🟢

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jul 18, 2025

SDK Size

title develop branch diff status
StreamChat 7.88 MB 7.88 MB 0 KB 🟢
StreamChatUI 4.84 MB 4.84 MB 0 KB 🟢

@nuno-vieira nuno-vieira merged commit a4a7932 into develop Jul 21, 2025
6 checks passed
@nuno-vieira nuno-vieira deleted the add/total-unread-count-by-team branch July 21, 2025 12:48
Copy link

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.

3 participants