The first step is to
import ChatUI and configure the SDK with the user id as follows:
let others: [String] = otherUsersIds Delivered.configure(for: "userId", otherUsers: others)
To configure with the database and messaging components, import the frameworks (
import ChatDatabase and
import Rooster) and call:
Delivered.configure(for: "userId", otherUsers: others, dbType: DeliveredDatabase.self, messagingType: Messaging.self)
The list of chats can be shown simply by presenting
let chats = ChatsListViewController() navigationController?.pushViewController(chats, animated: true)
There is also an alternative,
ChatsListInTabsViewController, which displays chats in multiple tabs grouped by type.
let chats = ChatsInTabsViewController(types: ChatType.private, .groups, .channels)
The user may further navigate into an individual from the list of chats; this needs no additional code.
It is normally recommended to display the list of chats, as it offers the user an overview of all chat activity. However, it is also possible to directly present a
ChatViewController, e.g., in cases where it is desirable to add a chat option to an existing profile or resource.
let chat = ChatViewController(with: chatId) navigationController?.pushViewController(chat, animated: true)
The chat identifier (
chatId in the code sample) can be obtained from either a user id, or from an arbitrary resource id (such as a URL, hashtag, image/video id, product id, etc).
let chatId = Chats.oneToOne(with: otherUserId)
let chatId = Chats.publicGroup(resourceId)
Both one-to-one chats and public groups have deterministic identifiers, which will not change or expire, and that can be created on the client side. It is not necessary to cache the ids, i.e., they can be created again as needed.