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

fix: properly sync own reads while offline mode is enabled #2901

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

isekovanic
Copy link
Contributor

🎯 Goal

Fixes this Zendesk issue.

🛠 Implementation details

It appears that this underlying issue may represent itself in various manners, all appearing in integrations where enableOfflineSupport={true}:

  • If you receive messages across multiple channels while the ChannelList specifically is open, reading one will break the state for all others
  • Sometimes, channel reads get stuck in a weird state where it's not possible to trigger a read
  • Receiving a new message while not at the bottom of MessageList (which count as unread) while having it open will cause these to not be counted in the ChannelPreviews if we go back to our ChannelList

Although the issues seem different, they all have the same underlying cause - the fact that we don't update reads whenever we receive new messages within the SDK, but rather we update them only whenever we query channels. This leads to the following happening:

  • We open the app and first load the data from the offline DB
  • We then query channels, which updates the local DB with up to date data (which does not contain any unreads yet)
  • We receive messages in a couple of channels (this does NOT update the offline DB)
  • We try to read a channel and then go back
  • Steps 1 and 2 are repeated, as we need to resync the ChannelList
  • However, the offline DB data is now stale and does not have any unreads so everything resets in the ChannelList

The reason why the second channels query did not update the ChannelList either is due to an improper list of dependencies in our hooks as well as bad values used for memoization. So the underlying causes were 2 issues:

  • Bad memo/hook dependency management
  • Not writing to the offline DB whenever we receive a new message

Both of these issues should be fixed.

🎨 UI Changes

iOS
Before After
Android
Before After

🧪 Testing

☑️ Checklist

  • I have signed the Stream CLA (required)
  • PR targets the develop branch
  • Documentation is updated
  • New code is tested in main example apps, including all possible scenarios
    • SampleApp iOS and Android
    • Expo iOS and Android

@Stream-SDK-Bot
Copy link
Contributor

Stream-SDK-Bot commented Jan 22, 2025

SDK Size

title develop branch diff status
js_bundle_size 463 KB 463 KB 0 B 🟢

@isekovanic isekovanic merged commit 4df41c4 into develop Jan 23, 2025
5 checks passed
@isekovanic isekovanic deleted the fix/offline-storage-reads-sync branch January 23, 2025 09:51
isekovanic added a commit that referenced this pull request Jan 23, 2025
* fix: properly sync own reads while offline mode is enabled

* fix: use proper unreadCount

* fix: use countUnread() api for brevity
@isekovanic isekovanic mentioned this pull request Jan 23, 2025
6 tasks
@github-actions github-actions bot mentioned this pull request Jan 27, 2025
6 tasks
@stream-ci-bot
Copy link
Contributor

🎉 This PR is included in version 6.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants