MessageComposerController
Controller responsible for handling the composing and sending of messages.
It acts as a central place for both the core business logic and state required to create and send messages, handle attachments, message actions and more.
If you require more state and business logic, compose this Controller with your code and apply the necessary changes.
Parameters
The CID of the channel we're chatting in.
The client used to communicate to the API.
The current state of the channel.
The media recorder used to record audio messages.
The handler used to lookup users for mentions.
The function used to convert a file to a URI.
The configuration for the message composer.
A flow emitting the current GlobalState.
Handle used to persist and restore picker selections and edit-mode state across process death (e.g. caused by opening the system file picker while editing a message).
Constructors
Types
Properties
Emits each time the message input field should request focus (e.g. after a command is selected).
Set of currently active message actions. These are used to display different UI in the composer, as well as help us decorate the message with information, such as the quoted message id.
UI state of the current composer input.
Full message composer state holding all the required information.
Buffers typing updates.
Functions
Adds attachments to the staged list, preserving insertion order.
Builds a new Message to send to our API. If isInEditMode is true, we use the current action's message and apply the given changes.
Dismisses the current link preview and marks enrichment as skipped. When a message is sent after dismissal, the backend will not enrich its URLs unless the detected URL in the input changes (e.g. the user replaces the link).
Cancels audio recording and moves MessageComposerState.recording state to RecordingState.Idle.
Dismisses the active command, clearing MessageComposerState.activeCommand and resetting the text input.
Removes all staged attachments and updates the composer state. Clears picker selections, edit-mode base attachments, and any completed recording attachment.
Clears all the data from the input — text, attachments, validation errors, actions, and active command. In thread mode, MessageComposerState.alsoSendToChannel is preserved until the user toggles it; otherwise it is reset.
Completes audio recording and updates the MessageComposerState.attachments list.
Creates a poll with the given createPollParams.
Dismisses all message actions from the UI and clears the input if isInEditMode is true.
Dismisses the suggestions popup above the message composer.
Sends coordinates of the touch event to the AudioRecordingController.
Updates the UI state when leaving the thread, to switch back to the MessageMode.Normal, by calling setMessageMode.
Moves MessageComposerState.recording state to RecordingState.Locked.
Pauses audio recording and sets RecordingState.Overview.isPlaying to false.
Handles selected messageAction. We only have three actions we can react to in the composer:
Removes attachment from the staged list.
Removes all staged attachments whose URI string key is contained in uris.
Pauses audio recording and seeks to the given progress. Sets RecordingState.Overview.isPlaying to false. Sets RecordingState.Overview.playingProgress to the given progress.
Switches the message composer to the command input mode.
Autocompletes the current text input with the mention from the selected user.
Autocompletes the current text input with the mention from the selected mention.
Sends a given message using our Stream API. Based on isInEditMode, we either edit an existing message, or we send a new message, using ChatClient. In case the message is a moderated message the old one is deleted before the replacing one is sent.
Completes the active audio recording and sends the recorded audio as an attachment.
Called when the "Also send as a direct message" checkbox is checked or unchecked.
Called when the input changes and the internal state needs to be updated.
Called when the message mode changes and the internal state needs to be updated.
Starts audio recording and moves MessageComposerState.recording state from RecordingState.Idle to RecordingState.Hold.
Stops audio recording and moves MessageComposerState.recording state to RecordingState.Overview.
Toggles the visibility of the command suggestion list popup.
Toggles audio recording playback if MessageComposerState.recording is instance of RecordingState.Overview.