ChatClient

The ChatClient is the main entry point for all low-level operations on chat

Types

Link copied to clipboard
class Builder(apiKey: String, appContext: Context) : ChatClient.ChatClientBuilder

Builder to initialize the singleton ChatClient instance and configure its parameters.

Link copied to clipboard
abstract class ChatClientBuilder constructor
Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The list of plugins added once user is connected.

Link copied to clipboard

Functions

Link copied to clipboard
fun acceptInvite(channelType: String, channelId: String, message: String?): Call<Channel>
Link copied to clipboard
fun addDevice(device: Device): Call<Unit>
Link copied to clipboard
fun addMembers(channelType: String, channelId: String, memberIds: List<String>, systemMessage: Message? = null, hideHistory: Boolean? = null, skipPush: Boolean? = null): Call<Channel>

Adds members to a given channel.

Link copied to clipboard
Link copied to clipboard

Get the current settings of the app. Check AppSettings.

Link copied to clipboard
fun banUser(targetId: String, channelType: String, channelId: String, reason: String?, timeout: Int?): Call<Unit>
Link copied to clipboard

Block a user by ID.

Link copied to clipboard
fun castPollAnswer(messageId: String, pollId: String, answer: String): Call<Vote>
Link copied to clipboard
fun castPollVote(messageId: String, pollId: String, option: Option): Call<Vote>

Cast a vote for a poll in a message.

Link copied to clipboard

Returns a ChannelClient for given cid.

fun channel(channelType: String, channelId: String): ChannelClient

Returns a ChannelClient for given type and id.

Link copied to clipboard

Clear local data stored on the device from the current user.

Link copied to clipboard
fun closePoll(pollId: String): Call<Poll>

Close a poll in a message.

Link copied to clipboard
fun connectAnonymousUser(timeoutMilliseconds: Long? = null): Call<ConnectionData>
Link copied to clipboard
fun connectGuestUser(userId: String, username: String, timeoutMilliseconds: Long? = null): Call<ConnectionData>
Link copied to clipboard
fun connectUser(user: User, tokenProvider: TokenProvider, timeoutMilliseconds: Long? = null): Call<ConnectionData>

Initializes ChatClient for a specific user. The tokenProvider implementation is used for the initial token, and it's also invoked whenever the user's token has expired, to fetch a new token.

fun connectUser(user: User, token: String, timeoutMilliseconds: Long? = null): Call<ConnectionData>

Initializes ChatClient for a specific user using the given user token. Check ChatClient.connectUser with TokenProvider parameter for advanced use cases.

Link copied to clipboard
fun createChannel(channelType: String, channelId: String, memberIds: List<String>, extraData: Map<String, Any>): Call<Channel>

Creates the channel. You can either create an id-based channel by passing not blank channelId or member-based (distinct) channel by leaving channelId empty. Use memberIds list to create a channel together with members. Make sure the list is not empty in case of creating member-based channel! Extra channel's information, for example name, can be passed in the extraData map.

Link copied to clipboard
fun createVideoCall(channelType: String, channelId: String, callType: String, callId: String): Call<VideoCallInfo>

Creates a newly available video call, which belongs to a channel. The video call will be created based on the third-party video integration (Agora and 100ms) on your Stream Dashboard.

Link copied to clipboard
fun deleteChannel(channelType: String, channelId: String): Call<Channel>
Link copied to clipboard
fun deleteDevice(device: Device): Call<Unit>
Link copied to clipboard
fun deleteFile(channelType: String, channelId: String, url: String): Call<Unit>

Deletes the file represented by url from the given channel.

Link copied to clipboard
fun deleteImage(channelType: String, channelId: String, url: String): Call<Unit>

Deletes the image represented by url from the given channel.

Link copied to clipboard
fun deleteMessage(messageId: String, hard: Boolean = false): Call<Message>
Link copied to clipboard
fun deleteReaction(messageId: String, reactionType: String, cid: String? = null): Call<Message>

Deletes the reaction associated with the message with the given message id. cid parameter is being used in side effect functions executed by plugins. You can skip it if plugins are not being used.

Link copied to clipboard
fun devToken(userId: String): String

Generate a developer token that can be used to connect users while the app is using a development environment.

Link copied to clipboard
fun disableSlowMode(channelType: String, channelId: String): Call<Channel>

Disables slow mode for the channel.

Link copied to clipboard
fun disconnect(flushPersistence: Boolean): Call<Unit>

Disconnect the current user, stop all observers and clear user data. This method should only be used whenever the user logouts from the main app. You shouldn't call this method, if the user will continue using the Chat in the future.

Link copied to clipboard
Link copied to clipboard
fun dismissChannelNotifications(channelType: String, channelId: String)

Dismiss notifications from a given channelType and channelId. Be sure to initialize ChatClient before calling this method!

Link copied to clipboard
fun downloadFile(fileUrl: String): Call<ResponseBody>

Downloads the given file which can be fetched through the response body.

Link copied to clipboard
fun enableSlowMode(channelType: String, channelId: String, cooldownTimeInSeconds: Int): Call<Channel>

Enables slow mode for the channel. When slow mode is enabled, users can only send a message every cooldownTimeInSeconds time interval. The cooldownTimeInSeconds is specified in seconds, and should be between 1-MAX_COOLDOWN_TIME_SECONDS.

Link copied to clipboard

Enriches the given URL with Open Graph data.

Link copied to clipboard
fun fetchCurrentUser(): Call<User>

Fetches the current user. Works only if the user was previously set and the WS connections is closed.

Link copied to clipboard
fun flagMessage(messageId: String, reason: String?, customData: Map<String, String>): Call<Flag>
Link copied to clipboard
fun flagUser(userId: String, reason: String?, customData: Map<String, String>): Call<Flag>
Link copied to clipboard

Returns application settings from the server or the default ones as a fallback.

Link copied to clipboard
fun getChannel(cid: String, messageLimit: Int = 0, memberLimit: Int = 0, state: Boolean = false): Call<Channel>

Gets the channel from the server based on cid.

fun getChannel(channelType: String, channelId: String, messageLimit: Int = 0, memberLimit: Int = 0, state: Boolean = false): Call<Channel>

Gets the channel from the server based on channelType and channelId.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun getFileAttachments(channelType: String, channelId: String, offset: Int, limit: Int): Call<List<Attachment>>
Link copied to clipboard
fun getGuestToken(userId: String, userName: String): Call<GuestUser>
Link copied to clipboard
fun getImageAttachments(channelType: String, channelId: String, offset: Int, limit: Int): Call<List<Attachment>>
Link copied to clipboard
fun getMessage(messageId: String): Call<Message>

Fetches a single message from the backend.

Link copied to clipboard
fun getMessagesWithAttachments(channelType: String, channelId: String, offset: Int, limit: Int, types: List<String>): Call<List<Message>>

Returns a Call with messages that contain at least one desired type attachment but not necessarily all of them will have a specified type.

Link copied to clipboard
fun getNewerReplies(parentId: String, limit: Int, lastId: String? = null): Call<List<Message>>

Fetch replies to the specified message with id parentId that are newer than the message with lastId. If lastId is null, the oldest replies are returned.

Link copied to clipboard
fun getPinnedMessages(channelType: String, channelId: String, limit: Int, sort: QuerySorter<Message>, pagination: PinnedMessagesPagination): Call<List<Message>>

Returns a list of messages pinned in the channel. You can sort the list by specifying sort parameter. Keep in mind that for now we only support sorting by Message.pinnedAt. The list can be paginated in a few different ways using limit and pagination.

Link copied to clipboard
fun getReactions(messageId: String, offset: Int, limit: Int): Call<List<Reaction>>
Link copied to clipboard
fun getReplies(messageId: String, limit: Int): Call<List<Message>>
Link copied to clipboard
fun getRepliesMore(messageId: String, firstId: String, limit: Int): Call<List<Message>>
Link copied to clipboard
fun getSyncHistory(channelsIds: List<String>, lastSyncAt: Date): Call<List<ChatEvent>>

Returns all events that happened for a list of channels since last sync (while the user was not connected to the web-socket).

fun getSyncHistory(channelsIds: List<String>, lastSyncAt: String): Call<List<ChatEvent>>

Returns all events that happened for a list of channels since last sync (while the user was not connected to the web socket). lastSyncAt is in yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z' format. Use this version of getSyncHistory when high precision is necessary.

Link copied to clipboard
fun getThread(messageId: String, options: GetThreadOptions = GetThreadOptions()): Call<Thread>

Get a thread by message id.

Link copied to clipboard

Returns the currently available video call token.

Link copied to clipboard
fun hideChannel(channelType: String, channelId: String, clearHistory: Boolean = false): Call<Unit>

Hides the specified channel with side effects.

Link copied to clipboard
fun inheritScope(block: (Job) -> CoroutineContext): CoroutineScope

Inherits the UserScope and provides its Job as an anchor for children.

Link copied to clipboard
fun inviteMembers(channelType: String, channelId: String, memberIds: List<String>, systemMessage: Message? = null, skipPush: Boolean? = null): Call<Channel>

Invites members to a given channel.

Link copied to clipboard
Link copied to clipboard
fun keystroke(channelType: String, channelId: String, parentId: String? = null): Call<ChatEvent>

Sends a EventType.TYPING_START event to the backend.

Link copied to clipboard

Marks all the channel as read.

Link copied to clipboard
fun markMessageRead(channelType: String, channelId: String, messageId: String): Call<Unit>
Link copied to clipboard
fun markRead(channelType: String, channelId: String): Call<Unit>

Marks the specified channel as read.

Link copied to clipboard
fun markThreadRead(channelType: String, channelId: String, threadId: String): Call<Unit>

Marks a given thread as read.

Link copied to clipboard
fun markThreadUnread(channelType: String, channelId: String, threadId: String, messageId: String): Call<Unit>

Marks a given thread starting from the given message as unread.

Link copied to clipboard
fun markUnread(channelType: String, channelId: String, messageId: String): Call<Unit>

Marks the specified channel as unread.

Link copied to clipboard
fun muteChannel(channelType: String, channelId: String, expiration: Int? = null): Call<Unit>

Mutes a channel for the current user. Messages added to the channel will not trigger push notifications, and will not change the unread count for the users that muted it. By default, mutes stay in place indefinitely until the user removes it. However, you can optionally set an expiration time. Triggers notification.channel_mutes_updated event.

Link copied to clipboard
Link copied to clipboard
fun muteUser(userId: String, timeout: Int? = null): Call<Mute>

Mutes a user. Messages from muted users will not trigger push notifications. By default, mutes stay in place indefinitely until the user removes it. However, you can optionally set a mute timeout. Triggers notification.mutes_updated event.

Link copied to clipboard
fun partialUpdateMessage(messageId: String, set: Map<String, Any> = emptyMap(), unset: List<String> = emptyList()): Call<Message>

Partially updates specific Message fields retaining the fields which were set previously.

Link copied to clipboard
fun partialUpdateThread(messageId: String, set: Map<String, Any> = emptyMap(), unset: List<String> = emptyList()): Call<Thread>

Partially updates specific Thread fields retaining the fields which were set previously.

Link copied to clipboard
fun partialUpdateUser(id: String, set: Map<String, Any> = emptyMap(), unset: List<String> = emptyList()): Call<User>

Updates specific user fields retaining the custom data fields which were set previously.

Link copied to clipboard
fun pinMessage(message: Message, expirationDate: Date? = null): Call<Message>
fun pinMessage(message: Message, timeout: Int): Call<Message>

Pins the message.

Link copied to clipboard
fun queryBannedUsers(filter: FilterObject, sort: QuerySorter<BannedUsersSort> = QuerySortByField.ascByName("created_at"), offset: Int? = null, limit: Int? = null, createdAtAfter: Date? = null, createdAtAfterOrEqual: Date? = null, createdAtBefore: Date? = null, createdAtBeforeOrEqual: Date? = null): Call<List<BannedUser>>
Link copied to clipboard

Return na list of blocked users.

Link copied to clipboard
fun queryChannel(channelType: String, channelId: String, request: QueryChannelRequest, skipOnRequest: Boolean = false): Call<Channel>

Gets the channel from the server based on channelType, channelId and parameters from QueryChannelRequest. The call requires active socket connection if QueryChannelRequest.watch or QueryChannelRequest.presence is enabled, and will be automatically postponed and retried until the connection is established or the maximum number of attempts is reached.

Link copied to clipboard

Gets the channels from the server based on parameters from QueryChannelsRequest. The call requires active socket connection if QueryChannelsRequest.watch or QueryChannelsRequest.presence is enabled, and will be automatically postponed and retried until the connection is established or the maximum number of attempts is reached.

Link copied to clipboard

Gets the channels without running any side effects.

Link copied to clipboard
fun queryMembers(channelType: String, channelId: String, offset: Int, limit: Int, filter: FilterObject, sort: QuerySorter<Member>, members: List<Member> = emptyList()): Call<List<Member>>

Query members and apply side effects if there are any.

Link copied to clipboard

Query threads matching query request.

Link copied to clipboard

Query threads matching query request.

Link copied to clipboard

Query users matching query request.

Link copied to clipboard

Reconnects the socket. Works only if the user was previously set and the WS connections is closed.

Link copied to clipboard
fun rejectInvite(channelType: String, channelId: String): Call<Channel>
Link copied to clipboard
fun removeMembers(channelType: String, channelId: String, memberIds: List<String>, systemMessage: Message? = null, skipPush: Boolean? = null): Call<Channel>

Removes members from a given channel.

Link copied to clipboard
fun removePollVote(messageId: String, pollId: String, vote: Vote): Call<Vote>

Remove a vote for a poll in a message.

Link copied to clipboard
fun removeShadowBan(targetId: String, channelType: String, channelId: String): Call<Unit>
Link copied to clipboard
Link copied to clipboard

Resolves dependency T within the provided plugin DR. This method can't be called before user is connected because plugins are added only after user connection is completed.

Link copied to clipboard
fun searchMessages(channelFilter: FilterObject, messageFilter: FilterObject, offset: Int? = null, limit: Int? = null, next: String? = null, sort: QuerySorter<Message>? = null): Call<SearchMessagesResult>

Search messages across channels. There are two ways to paginate through search results:

Link copied to clipboard
Link copied to clipboard
fun sendEvent(eventType: String, channelType: String, channelId: String, extraData: Map<Any, Any> = emptyMap()): Call<ChatEvent>

Sends an event to all users watching the channel.

Link copied to clipboard
fun sendFile(channelType: String, channelId: String, file: File, callback: ProgressCallback? = null): Call<UploadedFile>

Uploads a file for the given channel. Progress can be accessed via callback.

Link copied to clipboard
fun sendGiphy(message: Message): Call<Message>

Sends selected giphy message to the channel specified by Message.cid. The call will be retried accordingly to retryPolicy.

Link copied to clipboard
fun sendImage(channelType: String, channelId: String, file: File, callback: ProgressCallback? = null): Call<UploadedFile>

Uploads an image for the given channel. Progress can be accessed via callback.

Link copied to clipboard
fun sendMessage(channelType: String, channelId: String, message: Message, isRetrying: Boolean = false): Call<Message>

Sends the message to the given channel. If isRetrying is set to true, the message may not be prepared again.

Link copied to clipboard
fun sendPoll(channelType: String, channelId: String, pollConfig: PollConfig): Call<Message>

Send a message with a poll to the given channel.

Link copied to clipboard
fun sendReaction(reaction: Reaction, enforceUnique: Boolean, cid: String? = null): Call<Reaction>

Sends the reaction. Use enforceUnique parameter to specify whether the reaction should replace other reactions added by the current user. cid parameter is being used in side effect functions executed by plugins. You can skip it if plugins are not being used.

Link copied to clipboard
Link copied to clipboard
fun shadowBanUser(targetId: String, channelType: String, channelId: String, reason: String?, timeout: Int?): Call<Unit>
Link copied to clipboard
fun showChannel(channelType: String, channelId: String): Call<Unit>
Link copied to clipboard

Performs Giphy shuffle operation in the channel specified by Message.cid. Returns new "ephemeral" message with new giphy url. The call will be retried accordingly to retryPolicy.

Link copied to clipboard
fun stopTyping(channelType: String, channelId: String, parentId: String? = null): Call<ChatEvent>

Sends a EventType.TYPING_STOP event to the backend.

Link copied to clipboard
fun stopWatching(channelType: String, channelId: String): Call<Unit>

Stops watching the channel which means you won't receive more events for the channel. The call requires active socket connection and will be automatically postponed and retried until the connection is established.

Link copied to clipboard
Link copied to clipboard
fun subscribeFor(vararg eventTypes: Class<out ChatEvent>, listener: ChatEventListener<ChatEvent>): Disposable
fun subscribeFor(vararg eventTypes: String, listener: ChatEventListener<ChatEvent>): Disposable

Subscribes to the specific eventTypes of the client.

fun subscribeFor(lifecycleOwner: LifecycleOwner, vararg eventTypes: Class<out ChatEvent>, listener: ChatEventListener<ChatEvent>): Disposable
fun subscribeFor(lifecycleOwner: LifecycleOwner, vararg eventTypes: String, listener: ChatEventListener<ChatEvent>): Disposable

Subscribes to the specific eventTypes of the client, in the lifecycle of lifecycleOwner.

Link copied to clipboard

Subscribes for the next event with the given eventType.

Link copied to clipboard
fun suggestPollOption(pollId: String, option: String): Call<Option>
Link copied to clipboard
fun switchUser(user: User, tokenProvider: TokenProvider, timeoutMilliseconds: Long? = null, onDisconnectionComplete: () -> Unit = {}): Call<ConnectionData>

Changes the user. Disconnects the current user and connects to a new one. The tokenProvider implementation is used for the initial token, and it's also invoked whenever the user's token has expired, to fetch a new token.

fun switchUser(user: User, token: String, timeoutMilliseconds: Long? = null, onDisconnectionComplete: () -> Unit = {}): Call<ConnectionData>

Changes the user. Disconnects the current user and connects to a new one. The tokenProvider implementation is used for the initial token, and it's also invoked whenever the user's token has expired, to fetch a new token.

Link copied to clipboard
fun translate(messageId: String, language: String): Call<Message>
Link copied to clipboard
fun truncateChannel(channelType: String, channelId: String, systemMessage: Message? = null): Call<Channel>

Removes all of the messages of the channel but doesn't affect the channel data or members.

Link copied to clipboard
fun unbanUser(targetId: String, channelType: String, channelId: String): Call<Unit>
Link copied to clipboard

Unblock a user by ID.

Link copied to clipboard
fun unflagMessage(messageId: String): Call<Flag>
Link copied to clipboard
fun unflagUser(userId: String): Call<Flag>
Link copied to clipboard
fun unmuteChannel(channelType: String, channelId: String): Call<Unit>

Unmutes a channel for the current user. Triggers notification.channel_mutes_updated event.

Link copied to clipboard
Link copied to clipboard
fun unmuteUser(userId: String): Call<Unit>

Unmutes a previously muted user. Triggers notification.mutes_updated event.

Link copied to clipboard

Unpins the message that was previously pinned

Link copied to clipboard
fun updateChannel(channelType: String, channelId: String, updateMessage: Message?, channelExtraData: Map<String, Any> = emptyMap()): Call<Channel>

Updates all of the channel data. Any data that is present on the channel and not included in a full update will be deleted.

Link copied to clipboard
fun updateChannelPartial(channelType: String, channelId: String, set: Map<String, Any> = emptyMap(), unset: List<String> = emptyList()): Call<Channel>

Updates specific fields of channel data retaining the custom data fields which were set previously.

Link copied to clipboard

Updates the message in the API and calls the plugins that handle this request. OfflinePlugin can be used here to store the updated message locally.

Link copied to clipboard
fun updateUser(user: User): Call<User>
Link copied to clipboard
fun updateUsers(users: List<User>): Call<List<User>>

Inherited functions

Link copied to clipboard
suspend fun ChatClient.filterWithOffset(filter: FilterObject, offset: Int, limit: Int): List<Channel>
Link copied to clipboard

Subscribes to client events of type T.

inline fun <T : ChatEvent> ChatClient.subscribeFor(lifecycleOwner: LifecycleOwner, listener: ChatEventListener<T>): Disposable

Subscribes to client events of type T, in the lifecycle of lifecycleOwner.

Subscribes to the specific eventTypes of the client.

fun ChatClient.subscribeFor(lifecycleOwner: LifecycleOwner, vararg eventTypes: KClass<out ChatEvent>, listener: ChatEventListener<ChatEvent>): Disposable

Subscribes to the specific eventTypes of the client, in the lifecycle of lifecycleOwner.

Link copied to clipboard

Subscribes for the next client event of type T.