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

feat: optimistic DB and UI updates for reactions and messages #1758

Merged
merged 54 commits into from
Dec 1, 2022

Conversation

vishalnarkhede
Copy link
Contributor

@vishalnarkhede vishalnarkhede commented Oct 14, 2022

🎯 Goal

Implements #1709
Fixes #1773

🛠 Implementation details

  • Introduced sendReaction, deleteReaction and deleteMessage functions within Channel component, which will be passed down through context. These functions are responsible for optimistically updating the reaction or adding a new message to local state and DB.
  • Introduced DBSyncManager which is responsible for all the tasks regarding syncing channel states within local DB e.g., calling sync api and executing pending tasks etc.

How it works

  • When user updates the reaction
    • update the reaction within local state first
    • update the reaction within local DB
    • add a task (api call) for this within pendingTasks table
    • call the relevant api e.g., sendReaction or deleteReaction
    • If API is successful then remove the entry for this api call from pendingTasks table.

It works the same way for new messages or deleted messages

  • When app is opened
    • load the channels from local DB first
    • If the ws connection is already active
      • call the sync api
      • execute any pending api calls e.g., send reaction or delete reaction etc
      • reload channels from local DB again
      • call queryChannels api and get fresh set of channels
    • If the ws connection is not active yet
      • wait for connection.changed event with online value as true
      • call the sync api
      • execute any pending api calls e.g., send reaction or delete reaction etc
      • reload channels from local DB again
      • call queryChannels api and get fresh set of channels

🎨 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

@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from e96e3f1 to 55c68c1 Compare October 14, 2022 08:21
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from 55c68c1 to 7b8bbbe Compare October 14, 2022 18:13
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from 3dceb6a to 5cde25e Compare October 19, 2022 06:39
@vishalnarkhede vishalnarkhede marked this pull request as ready for review October 19, 2022 16:46
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch 2 times, most recently from e06c965 to 04257ce Compare October 20, 2022 11:33
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from 04257ce to f3812ff Compare October 20, 2022 11:49
@vishalnarkhede vishalnarkhede changed the title feat: optimistic DB and UI updates for reactions feat: optimistic DB and UI updates for reactions and messages Nov 1, 2022
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from be79ba2 to 0595af0 Compare November 1, 2022 10:40
@vanGalilea
Copy link
Contributor

vanGalilea commented Nov 2, 2022

Some of the findings/questions from my manual testing run

@vanGalilea
Copy link
Contributor

vanGalilea commented Nov 2, 2022

When sending a "/giphy cat" message (when offline), it's not possible to resend it when establishing an internet connection again. This results in an exclamation mark bubble for eternity.

Can we handle it in a more sustainable and user-friendly way?

@vanGalilea
Copy link
Contributor

When sending a message (messages 4,5,6) when offline (optimistically) the messages do not appear before a different message (that was sent by another user when online). Although they were sent optimistically before that "new message" message was sent.

I expected that the messages (4,5,6) that were sent offline would appear in their respective location (before the message that was sent by the other user "New message"). This can be confusing to some people.

@vishalnarkhede can you check how other SDKs have implemented this?

Screen.Recording.2022-11-02.at.10.52.41_compressed.mp4

@vanGalilea
Copy link
Contributor

When sending a message offline, the exclamation mark sometimes appears and in some cases, it doesn't can we be more consistent about it?

To reproduce send messages from both devices when offline, it happened mainly on android for me

@vishalnarkhede
Copy link
Contributor Author

When sending a "/giphy cat" message (when offline), it's not possible to resend it when establishing an internet connection again. This results in an exclamation mark bubble for eternity.

Can we handle it in a more sustainable and user-friendly way?

hmm good point. I think its best to simply not allow sending a giphy while offline

@vishalnarkhede
Copy link
Contributor Author

When sending a message (messages 4,5,6) when offline (optimistically) the messages do not appear before a different message (that was sent by another user when online). Although they were sent optimistically before that "new message" message was sent.

I expected that the messages (4,5,6) that were sent offline would appear in their respective location (before the message that was sent by the other user "New message"). This can be confusing to some people.

@vishalnarkhede can you check how other SDKs have implemented this?

Screen.Recording.2022-11-02.at.10.52.41_compressed.mp4

This is a technical limitation for us from backend side. We don't allow inserting the messages before latest message

@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from ff5e5f5 to 83278b6 Compare November 26, 2022 21:16
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

62.6% 62.6% Coverage
4.1% 4.1% Duplication

@vishalnarkhede vishalnarkhede marked this pull request as ready for review November 27, 2022 14:46
@vishalnarkhede vishalnarkhede marked this pull request as draft November 28, 2022 09:07
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from 54d5497 to 065ef21 Compare November 28, 2022 10:46
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from 76188d9 to 3323320 Compare November 28, 2022 14:05
@vishalnarkhede vishalnarkhede force-pushed the feat/optimistic-db-updates branch from bfe74b6 to daba536 Compare November 29, 2022 14:56
@vishalnarkhede vishalnarkhede marked this pull request as ready for review November 29, 2022 17:12
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 1, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

61.6% 61.6% Coverage
0.4% 0.4% Duplication

@vishalnarkhede vishalnarkhede merged commit abe2b70 into develop Dec 1, 2022
@vishalnarkhede vishalnarkhede deleted the feat/optimistic-db-updates branch December 1, 2022 14:40
@github-actions github-actions bot mentioned this pull request Dec 1, 2022
6 tasks
@vishalnarkhede
Copy link
Contributor Author

🎉 This PR is included in version 5.6.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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react-native-quick-sqlite issue for offline support
2 participants