Skip to content

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Aug 12, 2025

🔗 Issue Links

https://linear.app/stream/issue/IOS-1069/handle-user-banned-events-in-livestream-controlloer

🎯 Goal

Handle user-banned events in the livestream controller

🧪 Manual Testing Notes

  1. Open Channel List with Leia Organa
  2. Open Channel "LiveX Controller" with Han Solo and with "Show as Livestream Controller"
  3. With Leia Organa, Ban Han Solo
  4. Han Solo device should see "Can't send message" in Composer
  5. With Leia Organa, Unban Han Solo
  6. Han Solo should be able to send messages again

☑️ 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
    • Composer now refreshes automatically when the livestream channel updates.
  • Bug Fixes
    • Livestream chat refreshes channel state on ban/unban events so membership status is current.
    • Message sending is disabled for users banned from a channel.
  • Documentation
    • Added changelog entry noting handling of user banned events in livestream channels.
  • Tests
    • Added tests verifying membership reflects ban/unban after related events.

@nuno-vieira nuno-vieira requested a review from a team as a code owner August 12, 2025 13:45
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Adds handling for UserBannedEvent and UserUnbannedEvent in LivestreamChannelController to refresh channel state from the datastore; updates demo UI to refresh the composer and disable sending for banned users; adds tests validating membership ban/unban state; updates CHANGELOG. No public API changes.

Changes

Cohort / File(s) Summary
Docs
CHANGELOG.md
Adds an Upcoming entry noting handling of user banned events in LivestreamChannelController (documentation-only).
Livestream demo UI
DemoApp/Screens/Livestream/DemoLivestreamChatChannelVC.swift
Calls messageComposerVC.updateContent() when channel updates and overrides isSendMessageEnabled to disable sending if the user is banned from the channel.
Controller event handling
Sources/StreamChat/Controllers/ChannelController/LivestreamChannelController.swift
Handles UserBannedEvent and UserUnbannedEvent by invoking updateChannelFromDataStore() when events pertain to the current channel.
Tests
Tests/StreamChatTests/Controllers/ChannelController/LivestreamChannelController_Tests.swift
Adds tests that assert in-memory channel membership isBannedFromChannel reflects datastore changes after banned/unbanned events are delivered.

Sequence Diagram(s)

sequenceDiagram
  participant EventBus
  participant LivestreamChannelController as Controller
  participant DataStore
  participant DemoUI

  EventBus->>Controller: UserBannedEvent / UserUnbannedEvent (for channel)
  Controller->>DataStore: updateChannelFromDataStore()
  DataStore-->>Controller: Channel + Membership (updated ban flag)
  Controller-->>DemoUI: Channel state updated
  DemoUI->>DemoUI: Refresh composer / disable or enable send
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Handle User Banned Events in Livestream Controller (IOS-1069)

Possibly related PRs

Suggested labels

🐞 Bug, 🤞 Ready For QA

Suggested reviewers

  • martinmitrevski
  • laevandus

Poem

I hop where livestreams hum and play,
A banned flag drops — I pause to stay.
Event hops in, the store replies,
Composer quiets, then re-opens eyes.
Carrots saved, the send button sings—hooray! 🥕✨


📜 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 40e3df7 and ed7c918.

📒 Files selected for processing (1)
  • Tests/StreamChatTests/Controllers/ChannelController/LivestreamChannelController_Tests.swift (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Tests/StreamChatTests/Controllers/ChannelController/LivestreamChannelController_Tests.swift
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build Test App and Frameworks
  • GitHub Check: Automated Code Review
  • GitHub Check: Metrics
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add/handle-banned-events-in-livestream-controller

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

github-actions bot commented Aug 12, 2025

Public Interface

🚀 No changes affecting the public interface.

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Aug 12, 2025

SDK Size

title develop branch diff status
StreamChat 8.04 MB 8.04 MB 0 KB 🟢
StreamChatUI 4.86 MB 4.86 MB 0 KB 🟢

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 (2)
Sources/StreamChat/Controllers/ChannelController/LivestreamChannelController.swift (1)

917-919: Narrow ban/unban handling to current user to avoid unnecessary refreshes

Right now we refresh the channel for any user’s ban/unban. To reduce redundant datastore reads and UI updates, only refresh when the affected user is the current user.

Apply this diff:

-        case is UserBannedEvent,
-             is UserUnbannedEvent:
-            updateChannelFromDataStore()
+        case let e as UserBannedEvent:
+            if let me = currentUserId, e.user.id == me {
+                updateChannelFromDataStore()
+            }
+        case let e as UserUnbannedEvent:
+            if let me = currentUserId, e.user.id == me {
+                updateChannelFromDataStore()
+            }
DemoApp/Screens/Livestream/DemoLivestreamChatChannelVC.swift (1)

510-515: Disable send when banned: consider also disabling input and surfacing copy

The override correctly disables sending. For a clearer UX (“Can’t send message”), consider also disabling text input and setting a placeholder when banned.

Apply this additional override in DemoLivestreamComposerVC:

+    override open func updatePlaceholderLabel() {
+        super.updatePlaceholderLabel()
+        if livestreamChannelController?.channel?.membership?.isBannedFromChannel == true {
+            composerView.inputMessageView.textView.isEditable = false
+            composerView.inputMessageView.placeholderLabel.text = "Can't send message"
+        } else {
+            composerView.inputMessageView.textView.isEditable = true
+        }
+    }

Note: Since this is the demo app, hardcoded copy is acceptable; otherwise consider adding a localization key.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 31ca27b and 40e3df7.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • DemoApp/Screens/Livestream/DemoLivestreamChatChannelVC.swift (2 hunks)
  • Sources/StreamChat/Controllers/ChannelController/LivestreamChannelController.swift (1 hunks)
  • Tests/StreamChatTests/Controllers/ChannelController/LivestreamChannelController_Tests.swift (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
DemoApp/Screens/Livestream/DemoLivestreamChatChannelVC.swift (2)
Sources/StreamChatUI/ChatMessageList/ChatMessageListView.swift (1)
  • updateContent (76-76)
Sources/StreamChatUI/Composer/ComposerVC.swift (1)
  • updateContent (559-585)
Tests/StreamChatTests/Controllers/ChannelController/LivestreamChannelController_Tests.swift (6)
TestTools/StreamChatTestTools/TestData/DummyData/ChannelDetailPayload.swift (1)
  • dummy (11-56)
DemoApp/Screens/Livestream/DemoLivestreamChatChannelVC.swift (2)
  • channel (220-222)
  • eventsController (397-410)
Tests/StreamChatTests/Database/DTOs/ChannelDTO_Tests.swift (1)
  • channel (1772-1774)
TestTools/StreamChatTestTools/SpyPattern/Spy/DatabaseContainer_Spy.swift (1)
  • writeSynchronously (175-182)
Sources/StreamChat/Controllers/ChannelController/LivestreamChannelController.swift (2)
  • synchronize (215-226)
  • eventsController (748-754)
TestTools/StreamChatTestTools/SpyPattern/Spy/APIClient_Spy.swift (1)
  • test_simulateResponse (108-111)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Automated Code Review
  • GitHub Check: Build LLC + UI (Xcode 15)
  • GitHub Check: Metrics
🔇 Additional comments (3)
CHANGELOG.md (1)

10-10: Changelog entry aligns with implementation

The entry is accurate and scoped correctly to LivestreamChannelController. No further action needed.

DemoApp/Screens/Livestream/DemoLivestreamChatChannelVC.swift (1)

358-359: Composer refresh on channel update looks good

Updating the composer content after channel changes ensures the send-state is recalculated promptly. This directly supports the ban/unban UX.

Tests/StreamChatTests/Controllers/ChannelController/LivestreamChannelController_Tests.swift (1)

1360-1408: LGTM: Ban event test verifies datastore-driven membership refresh

This test correctly seeds membership, flips isMemberBanned in the store, emits UserBannedEvent, and asserts in-memory state. Solid coverage.

@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 6.68 ms 33.2% 🔼 🟢
Duration 2.6 s 2.56 s 1.54% 🔼 🟢
Hitch time ratio 4 ms per s 2.6 ms per s 35.0% 🔼 🟢
Frame rate 75 fps 78.45 fps 4.6% 🔼 🟢
Number of hitches 1 0.8 20.0% 🔼 🟢

@Stream-SDK-Bot
Copy link
Collaborator

SDK Size

title develop branch diff status
StreamChat 8.04 MB 8.04 MB 0 KB 🟢
StreamChatUI 4.86 MB 4.86 MB 0 KB 🟢

Copy link

@testableapple testableapple added the 🟢 QAed A PR that was QAed label Aug 12, 2025
@nuno-vieira nuno-vieira merged commit 5cfb6d1 into develop Aug 12, 2025
14 checks passed
@nuno-vieira nuno-vieira deleted the add/handle-banned-events-in-livestream-controller branch August 12, 2025 15:19
@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🟢 QAed A PR that was QAed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants