Skip to content

Clear the channel list and message search when the user logs out or another user connects - #6861

Merged
gpunto merged 9 commits into
developfrom
fix/and-1667-channel-list-clear-on-user-change
Oct 22, 2026
Merged

gpunto merged 9 commits into
developfrom
fix/and-1667-channel-list-clear-on-user-change

Conversation

@gpunto

@gpunto gpunto commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Goal

A channel list or message search kept alive across a logout kept the previous user's data. After disconnect, their chats stayed on screen, and when the next user connected they showed for about a second until the new result landed. The previous user's queries were also sent again for the new user.

Part of AND-1667

Implementation

  • New internal ClientState.userSessionEnds() in ui-common: emits when the connected user disconnects or is replaced by a different one. A first connect, the same user connecting again and profile updates emit nothing.
  • Compose and XML ChannelListViewModel and the XML SearchViewModel use it to drop the previous user's data and stop their queries and load-more requests right away, then reload once the next user is connected. Until then the list shows the same loading state as before the first connect.
  • Each query's state now lives as long as the query, so replaced queries stop instead of being sent again when a user connects.
  • With no filter passed, the default filter is rebuilt for the new user, unless the app called setFilters. An explicit filter that contains the user's id is replaced with setFilters before the list reloads; predefined filter values can't be, so those apps need a new view model per user.
  • Apps that disconnect and reconnect the same user now see the list reload.
  • The KDoc of both ChannelListViewModelFactorys says a view model serves one user at a time, and that a filter containing a user id should be replaced with setFilters before the list reloads for the next user.

Testing

  • ClientStateExtensionsTest, both ChannelListViewModelTests and SearchViewModelTest cover logout, a switch (including one racing a disconnect), the same user connecting again, the default filter versus a filter set by the app, old queries not being sent again, and load-more and searches in flight during a switch.
  • On an emulator, with the Compose and XML samples: the same user connecting again keeps the list, logout clears it, the previous user's chats never come back, and the next user gets their own channels (with no filter passed, before they got only the one shared channel).

Summary by CodeRabbit

  • Bug Fixes
    • Channel lists now reset and reload correctly when users disconnect or switch accounts.
    • App-selected filters are preserved across user-session changes, while default filters update for the connected user.
    • Stale channel queries, selections, pagination results, and searches are cleared during transitions.
    • Message searches wait until initialization completes and return a failure when no user is connected.
  • New Features
    • Added support for detecting when a user session ends.
  • Documentation
    • Clarified how channel lists and user-specific filters behave when users change.

@gpunto gpunto added the pr:bug Bug fix label Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 6.25 MB 6.25 MB 0.00 MB 🟢
stream-chat-android-ui-components 11.57 MB 11.57 MB 0.00 MB 🟢
stream-chat-android-compose 13.23 MB 13.24 MB 0.00 MB 🟢
stream-chat-android-ai-compose 2.07 MB 2.07 MB 0.00 MB 🟢
stream-chat-android-ai-ondevice 1.67 MB 1.67 MB 0.00 MB 🟢

@gpunto
gpunto force-pushed the fix/and-1667-channel-list-clear-on-user-change branch from e1138fb to ffcd6c5 Compare October 21, 2026 10:48
@gpunto
gpunto marked this pull request as ready for review October 21, 2026 12:31
@gpunto
gpunto requested a review from a team as a code owner October 21, 2026 12:31
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 551b9df2-544a-475c-a21f-2490d7397720
📥 Commits

Reviewing files that changed from the base of the PR and between b939d97 and b08f9a0.

📒 Files selected for processing: 6
  • stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/viewmodel/channels/ChannelListViewModel.kt
  • stream-chat-android-compose/src/test/kotlin/io/getstream/chat/android/compose/viewmodel/channels/ChannelListViewModelTest.kt
  • stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/viewmodel/channels/ChannelListViewModel.kt
  • stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/viewmodel/search/SearchViewModel.kt
  • stream-chat-android-ui-components/src/test/kotlin/io/getstream/chat/android/ui/viewmodels/channels/ChannelListViewModelTest.kt
  • stream-chat-android-ui-components/src/test/kotlin/io/getstream/chat/android/ui/viewmodels/search/SearchViewModelTest.kt
💤 Files with no reviewable changes: 1
  • stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/viewmodel/search/SearchViewModel.kt
🚧 Files skipped from review as they are similar to previous changes: 1
  • stream-chat-android-ui-components/src/test/kotlin/io/getstream/chat/android/ui/viewmodels/search/SearchViewModelTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Walkthrough

The change adds a flow extension that detects when a user session ends. Channel-list view models clear user-specific state and reload after the next user is ready, while preserving app-provided filters. SearchViewModel waits for initialization before searching and handles the absence of a connected user with a failure result. Tests cover disconnects, reconnects, user changes, searches, and pagination.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to b08f9

The reported filter and search-pagination concerns do not block merging. Normal checks remain appropriate.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 13.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 80 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: clearing channel-list and message-search data when the user logs out or another user connects.
Description check Passed The description includes all required sections: Goal, Implementation, Testing, and Checklist. It explains the problem, implementation details, limitations, and test coverage. The checklist items are p…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes all required sections: Goal, Implementation, Testing, and Checklist. It explains the problem, implementation details, limitations, and test coverage. The checklist items are present, although they remain unchecked.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit watched the user stream,
Then cleared old channels from the dream.
New filters hopped in place,
Searches resumed their race.
Tests fenced each session’s trail,
While pagination stayed on the rail.

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

@sonarqubecloud

Copy link
Copy Markdown

@gpunto

gpunto commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@gpunto
gpunto enabled auto-merge October 22, 2026 08:10
@gpunto
gpunto added this pull request to the merge queue Oct 22, 2026
Merged via the queue into develop with commit c1ddb1a Oct 22, 2026
26 checks passed
@gpunto
gpunto deleted the fix/and-1667-channel-list-clear-on-user-change branch October 22, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants