Class MessageComposerViewModel
-
- All Implemented Interfaces:
public final class MessageComposerViewModel extends ViewModel
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.
-
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<MessageComposerState>messageComposerStateprivate final MutableStateFlow<String>inputprivate final MutableStateFlow<Boolean>alsoSendToChannelprivate final MutableStateFlow<Integer>cooldownTimerprivate final MutableStateFlow<List<Attachment>>selectedAttachmentsprivate final MutableStateFlow<List<ValidationError>>validationErrorsprivate final MutableStateFlow<List<User>>mentionSuggestionsprivate final MutableStateFlow<List<Command>>commandSuggestionsprivate final MutableStateFlow<MessageMode>messageModeprivate final Flow<MessageAction>lastActiveActionprivate final StateFlow<Set<String>>ownCapabilities
-
Constructor Summary
Constructors Constructor Description MessageComposerViewModel(MessageComposerController messageComposerController)
-
Method Summary
Modifier and Type Method Description final StateFlow<MessageComposerState>getMessageComposerState()The full UI state that has all the required data. final MutableStateFlow<String>getInput()UI state of the current composer input. final MutableStateFlow<Boolean>getAlsoSendToChannel()If the message will be shown in the channel after it is sent. final MutableStateFlow<Integer>getCooldownTimer()Represents the remaining time until the user is allowed to send the next message. final MutableStateFlow<List<Attachment>>getSelectedAttachments()Represents the currently selected attachments, that are shown within the composer UI. final MutableStateFlow<List<ValidationError>>getValidationErrors()Represents the list of validation errors for the current text input and the currently selected attachments. final MutableStateFlow<List<User>>getMentionSuggestions()Represents the list of users that can be used to autocomplete the current mention input. final MutableStateFlow<List<Command>>getCommandSuggestions()Represents the list of commands to be displayed in the command suggestion list popup. final MutableStateFlow<MessageMode>getMessageMode()Current message mode, either MessageMode.Normal or MessageMode.MessageThread. final Flow<MessageAction>getLastActiveAction()Gets the active Edit or Reply action, whichever is last, to show on the UI. final StateFlow<Set<String>>getOwnCapabilities()Holds information about the abilities the current user is able to exercise in the given channel. final UnitsetMessageInput(String value)Called when the input changes and the internal state needs to be updated. final UnitsetAlsoSendToChannel(Boolean alsoSendToChannel)Called when the "Also send as a direct message" checkbox is checked or unchecked. final UnitsetMessageMode(MessageMode messageMode)Called when the message mode changes and the internal state needs to be updated. final UnitperformMessageAction(MessageAction messageAction)Handles the selected messageAction. final UnitdismissMessageActions()Dismisses all message actions from the UI and clears the input based on the internal state. final UnitaddSelectedAttachments(List<Attachment> attachments)Stores the selected attachments from the attachment picker. final UnitremoveSelectedAttachment(Attachment attachment)Removes a selected attachment from the list, when the user taps on the cancel/delete button. final UnitsendMessage(Message message, Call.Callback<Message> callback)Sends a given message using our Stream API. final UnitsendMessage(Message message)Sends a given message using our Stream API. final UnitsendMessage()Sends a given message using our Stream API. final MessagebuildNewMessage(String message, List<Attachment> attachments)Builds a new Message to send to our API. final MessagebuildNewMessage(String message)Builds a new Message to send to our API. final MessagebuildNewMessage()Builds a new Message to send to our API. final UnitleaveThread()Updates the UI state when leaving the thread, to switch back to the MessageMode.Normal message mode, by calling setMessageMode. final UnitselectMention(User user)Autocompletes the current text input with the mention from the selected user. final UnitselectCommand(Command command)Switches the message composer to the command input mode. final UnittoggleCommandsVisibility()Toggles the visibility of the command suggestion list popup. final UnitclearData()Clears the input and the current state of the composer. final UnitdismissSuggestionsPopup()Dismisses the suggestions popup above the message composer. final UnitstartRecording()final UnitlockRecording()final UnitcancelRecording()final UnitstopRecording()final UnittoggleRecordingPlayback()final UnitcompleteRecording()final UnitpauseRecording()final UnitseekRecordingTo(Float progress)final UnitsendRecording()-
-
Method Detail
-
getMessageComposerState
final StateFlow<MessageComposerState> getMessageComposerState()
The full UI state that has all the required data.
-
getAlsoSendToChannel
final MutableStateFlow<Boolean> getAlsoSendToChannel()
If the message will be shown in the channel after it is sent.
-
getCooldownTimer
final MutableStateFlow<Integer> getCooldownTimer()
Represents the remaining time until the user is allowed to send the next message.
-
getSelectedAttachments
final MutableStateFlow<List<Attachment>> getSelectedAttachments()
Represents the currently selected attachments, that are shown within the composer UI.
-
getValidationErrors
final MutableStateFlow<List<ValidationError>> getValidationErrors()
Represents the list of validation errors for the current text input and the currently selected attachments.
-
getMentionSuggestions
final MutableStateFlow<List<User>> getMentionSuggestions()
Represents the list of users that can be used to autocomplete the current mention input.
-
getCommandSuggestions
final MutableStateFlow<List<Command>> getCommandSuggestions()
Represents the list of commands to be displayed in the command suggestion list popup.
-
getMessageMode
final MutableStateFlow<MessageMode> getMessageMode()
Current message mode, either MessageMode.Normal or MessageMode.MessageThread. Used to determine if we're sending a thread reply or a regular message.
-
getLastActiveAction
final Flow<MessageAction> getLastActiveAction()
Gets the active Edit or Reply action, whichever is last, to show on the UI.
-
getOwnCapabilities
final StateFlow<Set<String>> getOwnCapabilities()
Holds information about the abilities the current user is able to exercise in the given channel.
e.g. send messages, delete messages, etc... For a full list @see ChannelCapabilities.
-
setMessageInput
final Unit setMessageInput(String value)
Called when the input changes and the internal state needs to be updated.
- Parameters:
value- Current state value.
-
setAlsoSendToChannel
final Unit setAlsoSendToChannel(Boolean alsoSendToChannel)
Called when the "Also send as a direct message" checkbox is checked or unchecked.
- Parameters:
alsoSendToChannel- If the message will be shown in the channel after it is sent.
-
setMessageMode
final Unit setMessageMode(MessageMode messageMode)
Called when the message mode changes and the internal state needs to be updated.
This affects the business logic.
- Parameters:
messageMode- The current message mode.
-
performMessageAction
final Unit performMessageAction(MessageAction messageAction)
Handles the selected messageAction.
- Parameters:
messageAction- The newly selected action.
-
dismissMessageActions
final Unit dismissMessageActions()
Dismisses all message actions from the UI and clears the input based on the internal state.
-
addSelectedAttachments
final Unit addSelectedAttachments(List<Attachment> attachments)
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.
- Parameters:
attachments- The attachments to store and show in the composer.
-
removeSelectedAttachment
final Unit removeSelectedAttachment(Attachment attachment)
Removes a selected attachment from the list, when the user taps on the cancel/delete button.
This will update the UI to remove it from the composer component.
- Parameters:
attachment- The attachment to remove.
-
sendMessage
@JvmOverloads() final Unit sendMessage(Message message, Call.Callback<Message> callback)
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.
It also dismisses any current message actions.
- Parameters:
message- The message to send.
-
sendMessage
@JvmOverloads() final Unit sendMessage(Message message)
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.
It also dismisses any current message actions.
- Parameters:
message- The message to send.
-
sendMessage
@JvmOverloads() final Unit sendMessage()
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.
It also dismisses any current message actions.
-
buildNewMessage
@JvmOverloads() final Message buildNewMessage(String message, List<Attachment> attachments)
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.
If we're not editing a message, we'll fill in the required data for the message.
- Parameters:
message- Message text.attachments- Message attachments.- Returns:
Message object, with all the data required to send it to the API.
-
buildNewMessage
@JvmOverloads() final Message buildNewMessage(String 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.
If we're not editing a message, we'll fill in the required data for the message.
- Parameters:
message- Message text.- Returns:
Message object, with all the data required to send it to the API.
-
buildNewMessage
@JvmOverloads() final Message buildNewMessage()
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.
If we're not editing a message, we'll fill in the required data for the message.
- Returns:
Message object, with all the data required to send it to the API.
-
leaveThread
final Unit leaveThread()
Updates the UI state when leaving the thread, to switch back to the MessageMode.Normal message mode, by calling setMessageMode.
It also dismisses any currently active message actions, such as Edit and Reply, as the user left the relevant thread.
-
selectMention
final Unit selectMention(User user)
Autocompletes the current text input with the mention from the selected user.
- Parameters:
user- The user that is used to autocomplete the mention.
-
selectCommand
final Unit selectCommand(Command command)
Switches the message composer to the command input mode.
- Parameters:
command- The command that was selected in the command suggestion list popup.
-
toggleCommandsVisibility
final Unit toggleCommandsVisibility()
Toggles the visibility of the command suggestion list popup.
-
dismissSuggestionsPopup
final Unit dismissSuggestionsPopup()
Dismisses the suggestions popup above the message composer.
-
startRecording
final Unit startRecording()
-
lockRecording
final Unit lockRecording()
-
cancelRecording
final Unit cancelRecording()
-
stopRecording
final Unit stopRecording()
-
toggleRecordingPlayback
final Unit toggleRecordingPlayback()
-
completeRecording
final Unit completeRecording()
-
pauseRecording
final Unit pauseRecording()
-
seekRecordingTo
final Unit seekRecordingTo(Float progress)
-
sendRecording
final Unit sendRecording()
-
-
-
-