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

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>)

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
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
@JvmName(name = "bind")
fun MessageComposerViewModel.bindView(view: MessageComposerView, lifecycleOwner: LifecycleOwner, messageBuilder: () -> Message = { buildNewMessage() }, sendMessageButtonClickListener: (Message) -> Unit = this.sendMessageButtonClickListener, textInputChangeListener: (String) -> Unit = this.textInputChangeListener, attachmentSelectionListener: (List<Attachment>) -> Unit = this.attachmentSelectionListener, attachmentRemovalListener: (Attachment) -> Unit = this.attachmentRemovalListener, pollSubmissionListener: (CreatePollParams) -> Unit = this.pollSubmissionListener, mentionSelectionListener: (User) -> Unit = this.mentionSelectionListener, commandSelectionListener: (Command) -> Unit = this.commandSelectionListener, alsoSendToChannelSelectionListener: (Boolean) -> Unit = this.alsoSendToChannelSelectionListener, dismissActionClickListener: () -> Unit = this.dismissActionClickListener, commandsButtonClickListener: () -> Unit = this.commandsButtonClickListener, dismissSuggestionsListener: () -> Unit = this.dismissSuggestionsListener, audioRecordButtonHoldListener: () -> Unit = this.audioRecordButtonHoldListener, audioRecordButtonLockListener: () -> Unit = this.audioRecordButtonLockListener, audioRecordButtonCancelListener: () -> Unit = this.audioRecordButtonCancelListener, audioRecordButtonReleaseListener: () -> Unit = this.audioRecordButtonReleaseListener( view.composerStyle.audioRecordingSendOnComplete, ), audioDeleteButtonClickListener: () -> Unit = this.audioDeleteButtonClickListener, audioStopButtonClickListener: () -> Unit = this.audioStopButtonClickListener, audioPlaybackButtonClickListener: () -> Unit = this.audioPlaybackButtonClickListener, audioCompleteButtonClickListener: () -> Unit = this.audioCompleteButtonClickListener( view.composerStyle.audioRecordingSendOnComplete, ), audioSliderDragStartListener: (Float) -> Unit = this.audioSliderDragStartListener, audioSliderDragStopListener: (Float) -> Unit = this.audioSliderDragStopListener)

Function which connects MessageComposerView to MessageComposerViewModel. As a result the view renders the state delivered by the ViewModel, and the ViewModel intercepts the user's actions automatically.

Link copied to clipboard
@JvmName(name = "bindDefaults")
fun MessageComposerViewModel.bindViewDefaults(view: MessageComposerView, lifecycleOwner: LifecycleOwner, messageBuilder: () -> Message = { buildNewMessage() }, sendMessageButtonClickListener: (Message) -> Unit? = null, textInputChangeListener: (String) -> Unit? = null, attachmentSelectionListener: (List<Attachment>) -> Unit? = null, attachmentRemovalListener: (Attachment) -> Unit? = null, pollSubmissionListener: (CreatePollParams) -> Unit? = null, mentionSelectionListener: (User) -> Unit? = null, commandSelectionListener: (Command) -> Unit? = null, alsoSendToChannelSelectionListener: (Boolean) -> Unit? = null, dismissActionClickListener: () -> Unit? = null, commandsButtonClickListener: () -> Unit? = null, dismissSuggestionsListener: () -> Unit? = null, audioRecordButtonHoldListener: () -> Unit? = null, audioRecordButtonLockListener: () -> Unit? = null, audioRecordButtonCancelListener: () -> Unit? = null, audioRecordButtonReleaseListener: () -> Unit? = null, audioDeleteButtonClickListener: () -> Unit? = null, audioStopButtonClickListener: () -> Unit? = null, audioPlaybackButtonClickListener: () -> Unit? = null, audioCompleteButtonClickListener: () -> Unit? = null, audioSliderDragStartListener: (Float) -> Unit? = null, audioSliderDragStopListener: (Float) -> Unit? = null)

Function which connects MessageComposerView to MessageComposerViewModel. As a result the view renders the state delivered by the ViewModel, and the ViewModel intercepts the user's actions automatically. The main difference with bindView is that listeners in this function do not override the default behaviour.

Link copied to clipboard
fun buildNewMessage(message: String = messageInput.value.text, attachments: List<Attachment> = messageComposerState.value.attachments): 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

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)
Link copied to clipboard

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

Link copied to clipboard

Dismisses the suggestions popup above the message composer.

Link copied to clipboard
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 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 = buildNewMessage(), 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
Link copied to clipboard
Link copied to clipboard

Toggles the visibility of the command suggestion list popup.

Link copied to clipboard