AI Integration Quick Reference
AI Integration Quick Reference
Offline support is available from React Native UI Kit 5.6.0 with React Native Chat SDK 4.2.1 or later. It is off by default.
Overview
Works offline- Conversations, users, groups, group members, messages and threads the user has opened before appear at once from the device, then the server’s page merges into them in place when it arrives.
- New messages (text and custom messages, voice notes, and media messages whose files have already uploaded) are queued on the device, survive an app restart, and are sent automatically when the connection returns.
- A message that could not be sent shows Not sent. Tap to retry, with Retry and Delete.
- Images, videos, audio and files the device has already saved are shown from the device.
- Attachments staged in the composer survive leaving the chat and an app restart.
- When the connection returns, everything that changed while the device was away (new messages, and edits, deletes and reactions made by others) syncs into the lists.
- The first load of a chat, list or page that was never opened on this device.
- Keyword search with no saved match, message information, call logs, calls and AI streamed replies.
- Editing, deleting and reacting to messages that are already sent. These are not queued offline. See Edits, deletes and reactions.
- Uploading files picked in the composer tray. A file picked while offline is not queued; see Attachments and media.
- Media the device never downloaded.
Requirements
The UI Kit’s peer dependency on the Chat SDK stays
*. On the CometChatUIKit.init() path the kit checks at runtime whether the installed SDK supports offline, so an app on an older SDK keeps working online only and the offline setting is ignored. CometChatUIKit.initFromSettings() does not make that check: it passes the offline setting straight to the Chat SDK, so on an SDK older than 4.2.1 the result depends on what that SDK does with it. Install Chat SDK 4.2.1 or later either way, and use the latest release, which includes the newest offline fixes.
Install the native dependencies
Offline support stores data in a local database, which the Chat SDK opens through native modules that you install in your app:op-sqlite release that supports your React Native version.
Rebuild the native app
These packages are native modules, and the UI Kit itself also ships native code (5.6.0 adds native file-copy code so Download and Share can use a saved file). After you install or upgrade, rebuild the native app; a JavaScript reload is not enough.- iOS
- Android
Android: compileSdk and media3
The UI Kit’s Android module plays voice notes withandroidx.media3 1.8.0, which needs compileSdkVersion 35 or later. If your app must stay on compileSdkVersion 34, pin an older media3 release with the RNVideo_media3Version key (the same key react-native-video reads) in the ext block of your project-level android/build.gradle:
android/build.gradle
Expo
The UI Kit and the offline database are native modules, so offline support runs in a development build or afterexpo prebuild, not in Expo Go. See Expo Integration.
Enable Offline Support
Add theoffline field to the UIKitSettings you pass to CometChatUIKit.init(). The UI Kit hands it to the Chat SDK’s AppSettingsBuilder.setOfflineConfig(...) for you.
- TypeScript
- JavaScript
offline accepts three forms:
If you leave
offline out, or set it to false, offline support stays off and the UI Kit works exactly as before.
With initFromSettings
If you initialize with CometChatUIKit.initFromSettings(), pass the same value as its second argument, or put it under chatSDK.offline in the settings. A value passed as the argument replaces the one in the settings.
Check that it is running
The UI Kit never reads back the value you configured. It asks the SDK withCometChat.isOfflineEnabled() each time it needs to, because offline support can be inactive even when you enabled it: before anyone logs in, when the local database cannot open, or when it is turned off for your app remotely. Do the same in your own code.
How the Components Behave Offline
Everything in this section applies only while offline support is running. With it off, every component behaves as before.Lists
The same rule applies to Conversations, Users, Groups, Group Members (banned members too), the Message List and threads, Search, the reactions list, Pinned Messages, Saved Messages and the Notification Feed:- Saved rows show at once. The server’s page then merges into them in place, with no flicker or reload.
- Offline with rows on screen: a load that fails because there is no connection leaves the rows on screen, with no error view.
- Offline with nothing saved: the list shows its offline state: an icon and Connect to load chats (or users, groups, members, messages, reactions, notifications), with no Retry button. If you passed your own
ErrorView, it shows instead. On lists that takehideError(Conversations, Users, Groups, Group Members, Message List),hideErrorhides it too. - Online, the server returns nothing: the empty view (yours, if you passed one).
- Online, a real error: the error view with Retry when nothing is on screen, as before; rows already on screen stay.
- On reconnect: rows update in place. A list reloads once by itself only if it was showing the offline state or an offline search.
Search
A keyword search offline shows the saved matches. With no saved match it shows Connect to search, with the second line Search needs an internet connection. If you passed your own empty view, it shows instead. When the connection returns, the search runs again once. Only a real keyword counts as a search. A list opened with only a filter (for example, online users only, a tags filter, or a request builder without a keyword) is a plain list, and offline with nothing saved it shows that list’s Connect to load … text. On the Search screen, with nothing saved, Connect to search shows when a keyword could not reach the server, or when neither the chats search nor the messages search could. A filter-only search where only one of them could not reach the server shows the plain empty state.Message list and threads
- A chat or thread opened before shows its saved messages at once.
- At the older end of the saved history, the list shows a tappable Connect to load more row. After a jump to a message, the same row can also appear at the newer end. When the connection returns, the page behind each blocked edge loads once by itself, older pages first. Tapping or scrolling there works too.
- A failed older page (a server error or no connection) never ends the list; only an empty server page does.
- Start from the first unread (
startFromUnreadMessages) and a jump to a message land on the right message before the list pages or follows new messages. After a jump to an older message, scrolling to the end (or “latest”) loads the rest, so no message is skipped. - On reconnect the message and conversation lists use the SDK’s catch-up instead of making their own requests. Pull-to-refresh on the conversation list asks the SDK to sync.
- The thread header counts the user’s own reply once, when it is queued, and takes it back if the reply is removed before it was sent.
Sending messages
- A message sent offline appears in the list straight away with a clock icon and Not sent yet, and is queued on the device, even if the app is closed. It is sent automatically when the connection returns. A queued message is not a failure.
- A message that could not be sent shows an error icon and Not sent. Tap to retry. Failures come from the SDK’s message status, so they survive an app restart.
- Every unsent message (waiting, sending or failed) offers Retry and Delete in its menu, and nothing else, because the other actions need a message that reached the server. For a queued message, Retry asks the SDK to send that same message again rather than creating a new one. A message that failed before it was queued is sent again as a new message. If the SDK no longer holds the message (for example, its chat was removed from the device after the send failed), Retry removes the row, because there is nothing left to send. Delete removes it from the device for good.
- If the message is being sent at that moment, Retry and Delete change nothing and the UI Kit shows Sending… try again in a moment for about four seconds.
- When the device’s outbox is full, the send is refused and the UI Kit shows Too many messages waiting to send once for that message. A file too large to queue shows File too large to send offline. See Queue Limits for the SDK’s limits.
- The conversation’s row in Conversations shows the same clock or error icon while its last message is waiting or failed.
- If offline support is turned off for your app remotely while messages are waiting, those rows turn failed at the next connection change, with one notice. Retry then sends them as new messages.
Attachments and media
- Attachments staged in the composer tray (both the Message Composer and the Compact Message Composer) survive leaving the chat and an app restart. Files that finished uploading stay done; interrupted files come back failed with a retry button. Nothing uploads by itself.
- A file picked in the tray uploads right away, which needs a connection. Picked while offline, its upload fails and the tile shows a retry button; the file is not queued and nothing is sent. Retry it once the connection returns, then send. A voice note goes out as a message straight away, so the SDK queues it like any other message (see Send While Offline).
- Images, videos, audio and files come from the SDK’s saved copy when it has one, with
mediaCachingset toAUTO(the default). See Media Caching. - Media the device never downloaded shows Available when online while offline. Tapping it online asks the SDK to download and save it.
- Download, “Download all” and Share in the media viewer use the saved file when there is one, without fetching it again. Offline with no saved copy, they show Available when online.
- Download and Share copy a file that is already on the device only from the Chat SDK’s offline media folder. Any other local file a message points to is refused and nothing is copied.
Edits, deletes and reactions
Editing or deleting a sent message and adding or removing a reaction are not queued offline: they go to the server when the user acts and fail without a connection (see the SDK’s rules). The UI Kit handles the failure for you:- An edit that fails offline leaves the message with its old text. The composer clears and leaves edit mode when the edit is sent, as it does online, and the edited text is not put back. The error goes to the composer’s
onError. - A reaction that fails is rolled back; the message shows what it showed before the tap.
- A failed edit, delete or reaction shows the UI Kit’s “Something went wrong” notice.
Presence
While the SDK is disconnected, nobody shows online: no “Online” subtitle, no green status dot and no typing text, in every list and header. Presence comes back when the connection returns.Pinned, Saved, Reactions and Notifications
Pinned Messages, Saved Messages, the reactions list and the Notification Feed follow the list rule: saved rows first, and Connect to load messages, Connect to load reactions or Connect to load notifications when nothing is saved.Group changes while offline
If the user was kicked, banned or removed from a group while the device was offline, the conversation list drops that conversation when the catch-up arrives, as the message header and the groups list do.Logout and user switch
The SDK keeps one cache per user. On logout, a user switch or a cache reset, the UI Kit clears every list and composer tray. On logout and a user switch, the SDK also deletes that user’s cached data, cached media and queued messages. Restarting the app while the same user stays logged in keeps the cache. You don’t need to clear anything yourself. On logout and a user switch, aCometChatUIKit.send* call still waiting is rejected quietly with ERROR_OFFLINE_MESSAGE_DISCARDED; for a cache reset, see CometChatUIKit.send* promises. See One cache per user.
Offline States and Texts
These texts appear only with offline support running. Each one has a localization key you can override (see Change the texts). They are translated in all 18 locales of the UI Kit.
Keys with a count have
_ONE and _OTHER forms; {count} is replaced with the number.
Errors and Callbacks
When onError fires
The reactions list, Pinned and Saved have no
onError prop, so they show the state only.
CometChatUIKit.send* promises
With offline support running, the promise returned by CometChatUIKit.sendTextMessage, sendMediaMessage and sendCustomMessage:
- resolves when the message reaches the server, also when it was queued first;
- rejects on a final failure, with the SDK’s error as it is:
error.code, anderror.reasonwith the failure reason when there is one. For example, a message refused because the outbox is full rejects withERROR_PENDING_QUEUE_LIMITand the reasonQUEUE_FULL; - never rejects just because the message was queued;
- rejects with the error code
DISCARDEDwhen a message that was already queued is dropped: the user deletes the unsent row, an outbox overflow evicts it, its conversation is removed from the device, or a cache reset the SDK can count loses it. The error’sreasonisQUEUE_OVERFLOWfor an eviction andDISCARDEDotherwise. For the cases the SDK drives (eviction, conversation removal, cache reset), the UI Kit also handles the message like an unsent message that was removed: the row goes,ccMessageSentfires with theerrorstatus,ccMessageSendStateChangedfires with"discarded"and the “unsent message was removed” notice shows. A cache reset then adds its own notice when it lost messages, except forENCRYPTION_CHANGED. The composer’sonErroris not called for a removed conversation, a cache reset or a user delete; for an eviction it receives the SDK’sERROR_PENDING_QUEUE_LIMITerror; - rejects with
ERROR_OFFLINE_MESSAGE_DISCARDEDwhen the user logs out or switches user while the send is waiting. There is no failed row, no notice, noccMessageSenterror event and noonError, and the composer stays usable. A cache reset whose lost messages the SDK cannot count (for example when the encryption key was lost) also rejects a waiting queued send with this code, quietly: the only thing shown is the reset’s “Some unsent messages may not have been sent” notice, except for anENCRYPTION_CHANGEDreset, which shows no notice at all.
ERROR_OFFLINE_MESSAGE_DISCARDED and DISCARDED as “the message was never sent and there is nothing to show”, not as a failure to show the user. Any other code is a real failure.
Offline events
The UI Kit emits two events on the existing message event bus. Both are new and never emitted with offline support off.ccMessageSent keeps its meaning.
The event names are on
OfflineMessageEvents, and the payload types are exported from the package.
- TypeScript
- JavaScript
Customization
Hide the offline notices
CometChatMessageList and CometChatConversations take hideOfflineNotices (default false). It hides all the one-line offline notices, such as an unsent message removed, the outbox full, a file too large to send offline, Sending… try again in a moment, Available when online, and the cache rebuilt or unsent messages lost. It has no effect with offline support off. The Not sent rows, the offline states and Connect to load more still show.
Your own error and empty views
If you pass your ownErrorView to a list, it shows instead of the UI Kit’s Connect to load … state, and, on lists that take hideError (Conversations, Users, Groups, Group Members, Message List), hideError hides that state. If you pass your own EmptyView, it shows instead of Connect to search.
Style the offline states
SetmessageListStyles.offlineStyles in your theme. Everything is optional: anything you leave out uses the theme’s existing error and date styles. These styles are used by the message list, the conversation list (its notice) and the media bubbles.
Change the texts
Override any key from the table above withCometChatI18nProvider. See Localization for how keys and language codes resolve.
With Offline Support Turned Off
If you don’t setoffline, none of the behavior on this page runs: no offline states, no queued sends, no new events, and no new request, timer, connectivity check, file or storage. Upgrading to 5.6.0 still changes a few things for every app:
- Retry on a failed text or custom message works. It used to do nothing. It now sends again through the same
CometChatUIKit.send*path and emitsccMessageSent(in progress, then success or error) again. - A message rejected by moderation keeps its error icon and no longer offers Retry.
- A failed reaction is rolled back, so the message shows what it showed before the tap.
- Edits always update the right message. Two messages without a
muidcould match each other before. - Reconnect catch-up pages forward. A full page is followed by the next one instead of fetching the same page again.
- Lists reload with your current request builder on reconnect, not the one from their first render.
- Download and Share copy a local file only from the Chat SDK’s offline media folder. When a message’s attachment points to any other file on the device, nothing is copied (on Android the UI Kit shows File download failed.).
- Android
compileSdkVersion35. The UI Kit’s Android module plays voice notes withandroidx.media31.8.0, which is new in 5.6.0 and needscompileSdkVersion35 or later, whether or not offline is on. See Android: compileSdk and media3 for theRNVideo_media3Versionescape hatch if your app must stay on 34. - iOS file bubbles open a preview. Tapping a file message on iOS now downloads it and opens a full-screen preview instead of going through the share sheet. This also fixes a crash on iPad, where the share sheet had no anchor.
- Automation identifiers: the composer input has the
testIDcc-composer-input. View-snapshot tests that include it may change.
Limitations
- The cache holds only what the user loaded while online, plus what the catch-up brings in on reconnect. A user who has never been online on this device has nothing to show offline.
- Keyword search with no saved match, message information, call logs, calls and AI streamed replies need a connection.
- Edits, deletes and reactions on sent messages are not queued offline.
- Encrypting the cache needs a secure key store on the device: install
react-native-keychain. The message database can be encrypted; downloaded media files are stored unencrypted. See Encrypt the Cache.
Next Steps
SDK Offline Support
How caching, the send outbox and catch-up work in the Chat SDK
Configuration & API Reference
Every OfflineConfig option, method, listener and error code
Send While Offline
The outbox, retry and discard, and queue limits
Core Features
See how the components power each chat feature