MessageComposerViewModel

class MessageComposerViewModel(messageComposerController: MessageComposerController, storageHelper: AttachmentStorageHelper) : ViewModel

ViewModel responsible for handling the composing and sending of messages.

Delegates all state management and business logic to MessageComposerController, including persistence of picker selections and edit-mode state across process death.

Parameters

messageComposerController

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

storageHelper

Resolves deferred attachment files before sending.

Constructors

Link copied to clipboard
constructor(messageComposerController: MessageComposerController, storageHelper: AttachmentStorageHelper)

Properties

Link copied to clipboard
val inputFocusEvents: SharedFlow<Unit>

Emits each time the message input field should request focus (e.g. after a command is selected).

Link copied to clipboard

The full UI state that has all the required data.

Link copied to clipboard
val messageInput: StateFlow<MessageInput>

UI state of the current composer input.

Functions

Link copied to clipboard
fun addAttachments(attachments: List<Attachment>)

Adds attachments to the staged attachment list.

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
fun buildNewMessage(message: String = messageInput.value.text, 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
Link copied to clipboard
Link copied to clipboard

Removes all staged attachments.

Link copied to clipboard
fun clearData()

Clears the input and the current state of the composer.

Link copied to clipboard
fun completeRecording(onComplete: (Result<Attachment>) -> Unit? = null)
Link copied to clipboard
fun createPoll(createPollParams: CreatePollParams)

Creates a poll with the given createPollParams.

Link copied to clipboard

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

Link copied to clipboard
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
fun removeAttachment(attachment: Attachment)

Removes attachment from the staged attachment list.

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.

fun selectMention(mention: Mention)

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

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