Skip to content

Commit 6358846

Browse files
vanGalileasanthoshvaivishalnarkhedemadsroskarNash0x7E2
authored
feat: offline support (#1670)
* feat: wip jump to a message after using the new around messages api * refactor: scroll to first unread channel * refactor: loading more recent messages should not rely on isUpToDate flag anymore * fix: set noMoreMessages flag to false when we are jumping to a message * fix: scroll to bottom button should not rely on isUpToDate flag * fix: show scroll to bottom button using the new hasNoMoreRecentMessages prop * fix: replace more isUpToDate calls with hasNoMoreRecentMessagesToLoad * feat: add documentation for hasNoMoreRecentMessagesToLoad * feat: update stream-chat-js to 6.3.0 * chore: remove unused import of Text * fix: readd the removed console log of error * feat: add documentation for loadChannelAroundMessage * chore: remove unneeded comment * chore: move scrollToDebounceTimeoutRef to the top of messageList * fix: remove unused variables * fix: update jest snapshot for the new prop addition for messageList * fix: remove unused useEffect in messageList * fix: fix the failing message list test * fix: channel unread indicator was showing up even when marked read * fix: scroll to bottom indicator must not be always shown on open * Revert "fix: fix the failing message list test" This reverts commit d605744. * fix: sometimes the channel was not loaded to the latest message * feat: add maxToRenderPerBatch prop to the messageList this reduces the scrollToIndex failure rate * fix: when scrolling to a non rendered item, highlight was not shown * fix: update snapshot to fix unit test * fix: scroll to messageId didnt work if scrollToFirstUnreadMsg is set * fix: ensure setTargetedMessage happens after messages array is copied * fix: simplified channel logic of messageId scroll * fix: remove unnecessary console log * docs: create a new version of docs for v5 (#1596) * docs: upgrade helper guide (#1605) * docs: cut a new version of docs for v5 * docs: upgrade helper guide * docs: drop v5 changes from v4 docs * docs: add reason for cameraroll fork replacement * docs: make removing cameraroll to be non-optional Co-authored-by: Santhosh Vaiyapuri <[email protected]> * feat: offline support (#1527) * feat: offline support * refactor: drop un-used function pragmaUserVersion * refactor: reverting changes to ChannelPreview * fix: fixing migration code issue * refactor: drop limits from queries * refactor: handling of message.read events and reads entity * refactor: added members to separate table * refactor: relative explicit query with left join to enrich users * refactor: cleanup and reorganizing * refactor: added index and foreign key constraints * refactor: changes to be compatible with js client * test: mocking sqlite * refactor: added missing fields on channels table * refactor: changes to be in sync with event from js client * refactor: renaming table and cleanup of columns * refactor: moving all quick-sqlite logic to separate class * test: added simple test for offline support * refactor: handle member related events * refactor: added usage of sync api * refactor: cleaning up un-necessary packages * refactor: fixed issue with update message foreign key constraint failure * refactor: cleanup * refactor: cleanup * tests: writing tests for offline feature * refactor: removed dev-menu package and usage * refactor: remove unused initDevMenu import * refactor: remove un-used flipper packages * docs: adding code comments * refactor: removing unnecessary generics * refactor: cleanup of mapper functions * refactor: renaming offlineChannelsActive to staticChannelsActive * refactor: removed metro config changes * buiild: fixed issue with manual release script * refactor: cleanup of handleEventToSyncDB * refactor: fixing lint issue * fix: removed redundant usage of useStreami18n hook * fix: issue with message not displayed in static state * build: updating stream-chat version * fix: issue with appendWhereClause and undefined value * fix: issue with members state initialization * build: do not format on save * fix: issue mapping memberCount to api response * build: upgrading stream-chat version * fix: reposition image error indicator * refactor: use network error handling to useLoadingImage * fix: image loading issue after network is recovered * fix: logic for sync api and lint issues * feat: point cameraroll dependency to the stream fork version * fix: message.new event handling * refactor: remove unnecessary client as hook dep * refactor: code review changes * refactor: moving offline support logic to Chat component * refactor: fix lint and typescript issues * refactor: handle quick-sqlite not being installed in better way * docs: lint fixes Co-authored-by: Mads Røskar <[email protected]> Co-authored-by: stevegalili <[email protected]> Co-authored-by: Santhosh Vaiyapuri <[email protected]> * build: fix the doc paths * docs: update upgrade helper doc * docs: update upgrade helper doc with logout logic changes * docs: change rc to beta in version label * docs: add pod install command to upgrade helper * build: update target branch name * fix: flipper database plugin setup * fix: handling of createSelectQuery function * build: upgrade better sqlite and quick sqlite dev dep * fix: open the selected image when pressed in the image grid (#1585) * refactor!: rename gallery state objects to match their data * fix: open the selected image when pressed in the image grid * style: reorder object keys to be alphabetic * chore: rename image grid props * fix: rename setters to match new names * test: update snapshots * test: move bettersqlite test utils to src/test-utils * test: gitignore locally generated database files * style: reorder imports * style: remove redundant whitespace * refactor: export store apis * fix: set an initial image index for the ImageGallery (#1639) * docs: update upgrade helper guide * docs: rename setImages and setImage * docs: fix broken mdx imports * docs: remove unintended newline in import * docs: update upgrade helper guide * feat: upgrade stream-chat to 7.0.0-offline-support.4 * docs: update upgrade helper guide * docs: offline support docs * ignore intelliJ files. * Update broken external URLs * Update broken internal links * docs: replace cameraroll to our fork in install steps * docs: upgrading v4 dopcs * build: connection docusaurus gh action to develop and main * feat: remove cameraroll fork and use v5 original cameraroll * feat: upgrade stream-chat to v7 stable Co-authored-by: Santhosh Vaiyapuri <[email protected]> Co-authored-by: Vishal Narkhede <[email protected]> Co-authored-by: Mads Røskar <[email protected]> Co-authored-by: Mads Røskar <[email protected]> Co-authored-by: nash0x7e2 <[email protected]>
1 parent a11b5b0 commit 6358846

File tree

627 files changed

+21750
-2592
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

627 files changed

+21750
-2592
lines changed

.github/workflows/docusaurus.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ name: docusaurus
33
on:
44
push:
55
branches:
6-
# - main # default branch name for each repo that docs should be push from
7-
# - develop
8-
- v5.0.0-beta
6+
- main # default branch name for each repo that docs should be push from
7+
- develop
98
paths:
109
- docusaurus/**
1110
jobs:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ artifacts
44
e2e/.env
55
*.log
66
.DS_STORE
7+
*.db
8+
.idea

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"editor.formatOnSave": true
3-
}
3+
}

bin/release.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ cd ..
3030
sed -e 's|"version": "[^"]*"|"version": "'"$1"'"|g' -i.bak src/version.json
3131
rm src/version.json.bak
3232

33+
git add package.json
3334
git add {expo,native}-package/package.json
3435
git add src/version.json
3536

37+
git add yarn.lock
3638
git add expo-package/yarn.lock
3739
git add native-package/yarn.lock
3840

39-
npm version "$1" --force
41+
npm version --no-git-tag-version "$1"
4042

4143
npm publish --tag="$tag"
4244

@@ -45,6 +47,4 @@ npm publish --tag="$tag"
4547

4648

4749
cd ../expo-package
48-
npm publish --tag="$tag"
49-
50-
git push --follow-tags
50+
npm publish --tag="$tag"

docusaurus/docs/reactnative/basics/getting_started.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Stream Chat has a number of peer dependencies that are required to take advantag
4747
It is suggested you follow the install instructions for each package to ensure it is properly setup.
4848
Most if not all of the required packages now support auto-linking so setup should be minimal. Those with known [additional steps](#additional-steps) have been noted.
4949

50-
- [`@react-native-community/cameraroll`](https://github.com/react-native-cameraroll/react-native-cameraroll)
50+
- [`@react-native-camera-roll/camera-roll`](https://github.com/react-native-cameraroll/react-native-cameraroll)
5151
- [`@react-native-community/netinfo`](https://github.com/react-native-netinfo/react-native-netinfo)
5252
- [`@stream-io/flat-list-mvcp`](https://github.com/GetStream/flat-list-mvcp)
5353
- [`react-native-document-picker`](https://github.com/rnmods/react-native-document-picker)
@@ -71,14 +71,14 @@ Most if not all of the required packages now support auto-linking so setup shoul
7171
<TabItem value='yarn'>
7272

7373
```bash
74-
yarn add @react-native-community/cameraroll @react-native-community/netinfo @stream-io/flat-list-mvcp react-native-document-picker react-native-fs react-native-gesture-handler react-native-haptic-feedback react-native-haptic-feedback react-native-image-crop-picker react-native-image-resizer react-native-reanimated react-native-safe-area-context react-native-share react-native-svg
74+
yarn add @react-native-camera-roll/camera-roll @react-native-community/netinfo @stream-io/flat-list-mvcp react-native-document-picker react-native-fs react-native-gesture-handler react-native-haptic-feedback react-native-haptic-feedback react-native-image-crop-picker react-native-image-resizer react-native-reanimated react-native-safe-area-context react-native-share react-native-svg
7575
```
7676

7777
</TabItem>
7878
<TabItem value='npm'>
7979

8080
```bash
81-
npm install @react-native-community/cameraroll @react-native-community/netinfo @stream-io/flat-list-mvcp react-native-document-picker react-native-fs react-native-gesture-handler react-native-haptic-feedback react-native-haptic-feedback react-native-image-crop-picker react-native-image-resizer react-native-reanimated react-native-safe-area-context react-native-share react-native-svg
81+
npm install @react-native-camera-roll/camera-roll @react-native-community/netinfo @stream-io/flat-list-mvcp react-native-document-picker react-native-fs react-native-gesture-handler react-native-haptic-feedback react-native-haptic-feedback react-native-image-crop-picker react-native-image-resizer react-native-reanimated react-native-safe-area-context react-native-share react-native-svg
8282
```
8383

8484
</TabItem>
@@ -151,7 +151,7 @@ For some of the packages listed below, there are additional steps required to se
151151

152152
- `react-native` - [additional installation steps](https://reactnative.dev/docs/image#gif-and-webp-support-on-android)
153153
- `react-native-image-crop-picker` - [additional installation steps](https://github.com/ivpusic/react-native-image-crop-picker#step-3)
154-
- `react-native-cameraroll` - [additional installation steps](https://github.com/react-native-cameraroll/react-native-cameraroll#permissions)
154+
- `react-native-camera-roll` - [additional installation steps](https://github.com/react-native-cameraroll/react-native-cameraroll#permissions)
155155

156156
:::note
157157

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
id: offline-support
3+
sidebar_position: 6
4+
title: Offline Support
5+
---
6+
7+
React Native Chat SDK provides OOTB support for offline mode, which means user will be able to access and interact
8+
with chat even when the network is off. This is an opt-in feature that needs to be explicitely enabled on application
9+
level.
10+
11+
> Offline support is currently not supported for Expo package (stream-chat-expo).
12+
13+
## Features
14+
15+
- ✅ Access to channel list and message list without network
16+
- ✅ Faster loading of chat since chat gets loaded from offline storage first before loading data from network
17+
- ✅ Syncing the local database using websocket events and sync api (once network is recovered)
18+
- ❌ Caching of image attachments
19+
- ❌ Optimistic updates to database on user action in offline mode e.g., send message, add reaction etc
20+
21+
## How To Enable Offline Support
22+
23+
- **Upgrade stream-chat dependency (optional)**
24+
25+
If you have installed `stream-chat` dependency explicitely on your application, then upgrade it to v7
26+
27+
```bash
28+
29+
```
30+
31+
- **Add `react-native-quick-sqlite` dependency**
32+
33+
```bash
34+
yarn add react-native-quick-sqlite
35+
npx pod-install
36+
```
37+
38+
- **Ensure unique instance of Chat component**
39+
40+
Until v4, you could provide separate `Chat` component for each usage of `Channel` component or `ChannelList` component.
41+
But from v5, it is necessary that you provide only one instance of `Chat` component within your application.
42+
This component needs to be a parent for all the chat related components such as `ChannelList`, `Channel` or `Thread`.
43+
44+
- **Do not wait for `connectUser` call to succeed**
45+
46+
It is important that you call `connectUser` method on chat client, before you render Chat components.
47+
But you don't need to wait for `connectUser` to succeed before rendering Chat components. This is to ensure:
48+
49+
- Chat components have access to current user information, which is important to store/access offline data.
50+
- In case or slow or no network, Chat components will still load the chat data without waiting for connectUser to succeed.
51+
52+
```tsx {7,8,16}
53+
const chatClient = StreamChat.getInstance('API_KEY');
54+
const App = () => {
55+
const [isClientReady, setIsClientReady] = useState(false);
56+
57+
useEffect(() => {
58+
const startChat = async () => {
59+
const connectPromise = chatClient.connectUser(user, tokenOrTokenProvider);
60+
setIsClientReady(true); // this allows components to render
61+
await connectPromise();
62+
// Any other post-connectUser logic you may have goes here.
63+
};
64+
65+
startChat();
66+
}, []);
67+
68+
if (!isClientReady) return null; // or some loading indicator;
69+
70+
return (
71+
<Chat client={chatClient} enableOfflineSupport>
72+
...
73+
</Chat>
74+
);
75+
};
76+
```
77+
78+
- **Add `enableOfflineSupport` prop on Chat component**
79+
80+
```tsx
81+
import { Chat } from 'stream-chat-react-native';
82+
83+
<Chat client={chatClient} enableOfflineSupport>
84+
...
85+
</Chat>;
86+
```
87+
88+
- **Reset the database when signing out the user**
89+
90+
Since SDK doesn't handle the app level authentication logic, its application's responsibility
91+
to ensure resetting database when user gets logged out. This should be generally done before you
92+
call `client.disconnectUser()`
93+
94+
```jsx
95+
import { QuickSqliteClient } from 'stream-chat-react-native';
96+
97+
// Sign out logic
98+
QuickSqliteClient.resetDB();
99+
chatClient.disconnectUser();
100+
```

docusaurus/docs/reactnative/basics/translations.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ const { t, tDateTimeParser } = await streami18n.getTranslators();
392392
Allows you to register a custom translation, this will override a translation if one already exists for the given language code.
393393
The third parameter, which is optional, is a Day.js locale, which is structured the same as [dayjsLocaleConfigForLanguage](#dayjslocaleconfigforlanguage).
394394

395-
It is suggested you look at the [`enTranslations` json file](https://github.com/GetStream/stream-chat-react-native/tree/main/src/i18n) exported from `stream-chat-react-native` for a current list of used translation keys.
395+
It is suggested you look at the [`enTranslations` json file](https://github.com/GetStream/stream-chat-react/blob/master/src/i18n/en.json) exported from `stream-chat-react-native` for a current list of used translation keys.
396396

397397
```ts
398398
streami18n.registerTranslation('mr', {

docusaurus/docs/reactnative/basics/troubleshooting.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: troubleshooting
3-
sidebar_position: 6
3+
sidebar_position: 7
44
title: Troubleshooting
55
---
66

0 commit comments

Comments
 (0)