Skip to content
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

Add channel reads pagination support #3613

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

laevandus
Copy link
Contributor

@laevandus laevandus commented Mar 5, 2025

🔗 Issue Links

Resolves: IOS-666

🎯 Goal

Add support for paginating channel reads for accurate read counts in large channels

📝 Summary

Important

Channel reads pagination is only supported through channel query endpoint while paginating members (slightly hidden feature)

  • Use channel query endpoint in Chat.loadMembers(with:) and Chat.loadMoreMembers(limit:) which also paginates channel reads for these members
  • Update ChannelQuery to support setting pagination parameter for members
  • Do not reset ChannelDTO.reads when saving channel payloads, only reset it when loading the first page of messages using the same endpoint (aka ChatChannelController.synchronize or Chat.get(watch:))
  • Recalculate MessageDTO.readBy for existing messages when saving channel payloads
  • Add demo app debug command for loading more members

🛠 Implementation

We use ChatMessage.readBy for showing read counts for current user's messages. This property is updated using ChannelDTO.reads (manual filtering). Channel reads are fetched based on requested channel members and by default up to 100 channel members are fetches (and reads for these users). If there are many members and we would like to get accurate channel reads, we would need to paginate members using channel query endpoint (members endpoint does not give channel reads).
Chat already incorporates member pagination. Before it was using /members endpoint, but this PR changes it to use the channel query endpoint.
End result is that creating an instance of Chat and calling get(watch:) will automatically give access to channel members fetched using the regular channel query call (default is 100 members and their channel reads). If we want more, we just need to call loadMoreMembers(limit:) and we get next page of members and their channel read information.

let chat = client.makeChat(for: cid)
try await chat.get(watch: true)
let members = chat.state.members // first page, 100
let reads = chat.state.channel?.reads // first 100, `ChatMessage.readBy` is updated based on 100 reads
try await chat.loadMoreMembers(limit: 100)
let members2 = chat.state.members // 200
let reads2 = chat.state.channel?.reads // 200, `ChatMessage.readBy` is updated based on 200 reads

Open questions

  1. Should we paginate channel reads automatically in UI components? Config option? Gives accurate read receipts.

🎨 Showcase

🧪 Manual Testing Notes

☑️ 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

@laevandus laevandus added 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK ✅ Feature An issue or PR related to a feature labels Mar 5, 2025
@laevandus laevandus requested a review from a team as a code owner March 5, 2025 12:54
@laevandus laevandus changed the title Add channel reads pagination support [WIP] Add channel reads pagination support Mar 5, 2025
@laevandus laevandus changed the title [WIP] Add channel reads pagination support Add channel reads pagination support Mar 5, 2025
@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 3.34 ms 66.6% 🔼 🟢
Duration 2.6 s 2.56 s 1.54% 🔼 🟢
Hitch time ratio 4 ms per s 1.3 ms per s 67.5% 🔼 🟢
Frame rate 75 fps 78.78 fps 5.04% 🔼 🟢
Number of hitches 1 0.4 60.0% 🔼 🟢

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Mar 5, 2025

SDK Size

title develop branch diff status
StreamChat 7.4 MB 7.41 MB +17 KB 🟢
StreamChatUI 4.78 MB 4.78 MB 0 KB 🟢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Feature An issue or PR related to a feature 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants