MessageComposerViewModel

ViewModel responsible for handling the composing and sending of messages.

It relays all its core actions to a shared data source, as a central place for all the Composer logic. Additionally, all the core data that can be reused across our SDKs is available through shared data sources, while implementation-specific data is stored in respective in the ViewModel.

Parameters

messageComposerController

The controller used to relay all the actions and fetch all the state.

Constructors

Link copied to clipboard
constructor(messageComposerController: MessageComposerController)

Properties

Link copied to clipboard
val alsoSendToChannel: MutableStateFlow<Boolean>

If the message will be shown in the channel after it is sent.

Link copied to clipboard
val commandSuggestions: MutableStateFlow<List<Command>>

Represents the list of commands to be displayed in the command suggestion list popup.

Link copied to clipboard
val cooldownTimer: MutableStateFlow<Int>

Represents the remaining time until the user is allowed to send the next message.

Link copied to clipboard
val input: MutableStateFlow<String>

UI state of the current composer input.

Link copied to clipboard

Gets the active Edit or Reply action, whichever is last, to show on the UI.

Link copied to clipboard
val linkPreviews: MutableStateFlow<List<LinkPreview>>

Represents the list of links that can be previewed.

Link copied to clipboard
val mentionSuggestions: MutableStateFlow<List<User>>

Represents the list of users that can be used to autocomplete the current mention input.

Link copied to clipboard

The full UI state that has all the required data.

Link copied to clipboard
val messageMode: MutableStateFlow<MessageMode>

Current message mode, either MessageMode.Normal or MessageMode.MessageThread. Used to determine if we're sending a thread reply or a regular message.

Link copied to clipboard
val ownCapabilities: StateFlow<Set<String>>

Holds information about the abilities the current user is able to exercise in the given channel.

Link copied to clipboard
val selectedAttachments: MutableStateFlow<List<Attachment>>

Represents the currently selected attachments, that are shown within the composer UI.

Link copied to clipboard
val validationErrors: MutableStateFlow<List<ValidationError>>

Represents the list of validation errors for the current text input and the currently selected attachments.

Functions

Link copied to clipboard

Stores the selected attachments from the attachment picker. These will be shown in the UI, within the composer component. We upload and send these attachments once the user taps on the send button.

Link copied to clipboard
fun buildNewMessage(message: String = input.value, attachments: List<Attachment> = emptyList()): Message

Builds a new Message to send to our API. Based on the internal state, we use the current action's message and apply the given changes.

Link copied to clipboard
Link copied to clipboard
fun clearData()

Clears the input and the current state of the composer.

Link copied to clipboard
Link copied to clipboard
fun createPoll(pollConfig: PollConfig)

Creates a poll with the given pollConfig.

Link copied to clipboard

Dismisses all message actions from the UI and clears the input based on the internal state.

Link copied to clipboard
fun holdRecording(offset: Pair<Float, Float>)
Link copied to clipboard

Updates the UI state when leaving the thread, to switch back to the MessageMode.Normal message mode, by calling setMessageMode.

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

Handles the selected messageAction.

Link copied to clipboard

Removes a selected attachment from the list, when the user taps on the cancel/delete button.

Link copied to clipboard
fun seekRecordingTo(progress: Float)
Link copied to clipboard
fun selectCommand(command: Command)

Switches the message composer to the command input mode.

Link copied to clipboard
fun selectMention(user: User)

Autocompletes the current text input with the mention from the selected user.

Link copied to clipboard
fun sendMessage(message: Message, callback: Call.Callback<Message> = Call.Callback { /* no-op */ })

Sends a given message using our Stream API. Based on the internal state, we either edit an existing message, or we send a new message, using our API.

Link copied to clipboard
Link copied to clipboard
fun setAlsoSendToChannel(alsoSendToChannel: Boolean)

Called when the "Also send as a direct message" checkbox is checked or unchecked.

Link copied to clipboard

Called when the input changes and the internal state needs to be updated.

Link copied to clipboard
fun setMessageMode(messageMode: MessageMode)

Called when the message mode changes and the internal state needs to be updated.

Link copied to clipboard

Sets the typing updates buffer.

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

Toggles the visibility of the command suggestion list popup.

Link copied to clipboard

Inherited functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard