Skip to content

Commit 840dbb8

Browse files
committed
docs: eliminates duplication regarding how to enable offline support
1 parent fc69634 commit 840dbb8

File tree

2 files changed

+33
-122
lines changed

2 files changed

+33
-122
lines changed

docusaurus/docs/reactnative/basics/offline_support.mdx

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,47 @@ React Native Chat SDK provides OOTB support for offline mode, which means user w
88
with chat even when the network is off. This is an opt-in feature that needs to be explicitely enabled on application
99
level.
1010

11-
> Offline support is currently not supported for Expo package (stream-chat-expo).
11+
> Offline support is currently not implemented for Expo package (stream-chat-expo).
12+
1213

1314
## Features
15+
The offline storage implementation currently offers the following features:
16+
- Access to chat when Internet connection is disabled or low.
17+
- Faster startup times and loading, since initial data is loaded from offline storage before performing any network requests.
18+
- Syncing of the offline database using WebSocket events and Sync API.
19+
20+
The following features are currently **NOT** implemented. They will be implemented gradually as part of minor releases in v5.
1421

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
22+
- Optimistically update offline database during chat interactions, such as send message, add reaction, etc.
23+
- Access to threads in offline mode.
24+
- Offline caching of attachment images and profile images.
2025

2126
## How To Enable Offline Support
27+
First and foremost make sure to follow all steps from [Migrating to v5](./upgrade_helper.mdx) guide.
28+
To enable offline support, please follow the given steps:
2229

23-
- **Upgrade stream-chat dependency (optional)**
30+
1. **Upgrade stream-chat dependency (optional)**
2431

25-
If you have installed `stream-chat` dependency explicitely on your application, then upgrade it to v7
32+
If you have installed `stream-chat` dependency explicitly on your application, then upgrade it to v7:
2633

2734
```bash
2835
2936
```
3037

31-
- **Add `react-native-quick-sqlite` dependency**
38+
2. **Add `react-native-quick-sqlite` dependency**
3239

3340
```bash
34-
yarn add react-native-quick-sqlite
35-
npx pod-install
41+
yarn add react-native-quick-sqlite
42+
npx pod-install
3643
```
3744

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`.
45+
3. **Do not wait for `connectUser` call to succeed**
4346

44-
- **Do not wait for `connectUser` call to succeed**
47+
It is important that you call the `connectUser` method on the chat client, before you render Chat components.
48+
But you don't need to wait for `connectUser` to succeed before rendering Chat components. This is to ensure:
4549

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.
50+
- Chat components have access to current user information, which is important to store/access offline data.
51+
- In case of slow or no network access, Chat components will still load the chat data without waiting for `connectUser` to succeed.
5152

5253
```tsx {7,8,16}
5354
const chatClient = StreamChat.getInstance('API_KEY');
@@ -75,23 +76,23 @@ level.
7576
};
7677
```
7778

78-
- **Add `enableOfflineSupport` prop on Chat component**
79+
4. **Add `enableOfflineSupport` prop on Chat component**
7980

8081
```tsx
81-
import { Chat } from 'stream-chat-react-native';
82+
import { Chat } from 'stream-chat-react-native';
8283

83-
<Chat client={chatClient} enableOfflineSupport>
84-
...
85-
</Chat>;
84+
<Chat client={chatClient} enableOfflineSupport>
85+
...
86+
</Chat>;
8687
```
8788

88-
- **Reset the database when signing out the user**
89+
-5. **Reset the database when signing out the user**
8990

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()`
91+
Since the SDK doesn't handle app-level authentication logic, it's the application's responsibility
92+
to ensure the database is reset when a user gets logged out. This should generally be done before you
93+
call `client.disconnectUser()`.
9394

94-
```jsx
95+
```tsx
9596
import { QuickSqliteClient } from 'stream-chat-react-native';
9697

9798
// Sign out logic

docusaurus/docs/reactnative/basics/upgrade_helper.mdx

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -40,94 +40,4 @@ The following values in [`ImageGalleryContext`](https://getstream.io/chat/docs/s
4040

4141
## Enable Offline Support
4242

43-
Offline support is a major opt-in feature introduced in v5 of the Stream Chat React Native SDK.
44-
45-
> Offline support is currently not implemented for Expo package (stream-chat-expo).
46-
47-
The offline storage implementation currently offers the following features:
48-
49-
- Access to chat when Internet connection is disabled or low.
50-
- Faster startup times and loading, since initial data is loaded from offline storage before performing any network requests.
51-
- Syncing of the offline database using WebSocket events and Sync API.
52-
53-
The following features are currently **NOT** implemented. They will be implemented gradually as part of minor releases in v5.
54-
55-
- Optimistically update offline database during chat interactions, such as send message, add reaction, etc.
56-
- Access to threads in offline mode.
57-
- Offline caching of attachment images and profile images.
58-
59-
To enable offline support, please follow the given steps:
60-
61-
1. **Upgrade stream-chat dependency (optional)**
62-
63-
If you have installed `stream-chat` dependency explicitly on your application, then upgrade it to v7:
64-
65-
```bash
66-
67-
```
68-
69-
2. **Add `react-native-quick-sqlite` dependency**
70-
71-
```bash
72-
yarn add react-native-quick-sqlite
73-
npx pod-install
74-
```
75-
76-
3. **Do not wait for `connectUser` call to succeed**
77-
78-
It is important that you call the `connectUser` method on the chat client, before you render Chat components.
79-
But you don't need to wait for `connectUser` to succeed before rendering Chat components. This is to ensure:
80-
81-
- Chat components have access to current user information, which is important to store/access offline data.
82-
- In case of slow or no network access, Chat components will still load the chat data without waiting for `connectUser` to succeed.
83-
84-
```tsx {7,8,16}
85-
const chatClient = StreamChat.getInstance('API_KEY');
86-
const App = () => {
87-
const [isClientReady, setIsClientReady] = useState(false);
88-
89-
useEffect(() => {
90-
const startChat = async () => {
91-
const connectPromise = chatClient.connectUser(user, tokenOrTokenProvider);
92-
setIsClientReady(true); // this allows components to render
93-
await connectPromise();
94-
// Any other post-connectUser logic you may have goes here.
95-
};
96-
97-
startChat();
98-
}, []);
99-
100-
if (!isClientReady) return null; // or some loading indicator;
101-
102-
return (
103-
<Chat client={chatClient} enableOfflineSupport>
104-
...
105-
</Chat>
106-
);
107-
};
108-
```
109-
110-
4. **Add `enableOfflineSupport` prop on Chat component**
111-
112-
```tsx
113-
import { Chat } from 'stream-chat-react-native';
114-
115-
<Chat client={chatClient} enableOfflineSupport>
116-
...
117-
</Chat>;
118-
```
119-
120-
5. **Reset the database when signing out the user**
121-
122-
Since the SDK doesn't handle app-level authentication logic, it's the application's responsibility
123-
to ensure the database is reset when a user gets logged out. This should generally be done before you
124-
call `client.disconnectUser()`.
125-
126-
```jsx
127-
import { QuickSqliteClient } from 'stream-chat-react-native';
128-
129-
// Sign out logic
130-
QuickSqliteClient.resetDB();
131-
chatClient.disconnectUser();
132-
```
13343
To enable offline support please check the [Offline Support](./offline_support.mdx) guide.

0 commit comments

Comments
 (0)