MessageListViewModel

class MessageListViewModel(messageListController: MessageListController) : ViewModel

ViewModel responsible for handling all the business logic & state for the list of messages.

Parameters

messageListController

Controller used to relay the logic and fetch the state.

Constructors

Link copied to clipboard
constructor(messageListController: MessageListController)

Properties

Link copied to clipboard

The information for the current Channel.

Link copied to clipboard

Gives us information about the online state of the device.

Link copied to clipboard

State handler for the UI, which holds all the information the UI needs to render messages.

Link copied to clipboard

Regulates the visibility of deleted messages.

Link copied to clipboard

Gives us information if we're currently in the Thread message mode.

Link copied to clipboard
val isOnline: Flow<Boolean>

Gives us information about the online state of the device.

Link copied to clipboard

Gives us information if we have selected a message.

Link copied to clipboard

Set of currently active MessageActions. Used to show things like edit, reply, delete and similar actions.

Link copied to clipboard

Regulates the message footer visibility.

Link copied to clipboard

Holds the current MessageMode that's used for the messages list. MessageMode.Normal by default.

Link copied to clipboard

Determines whether we should show system messages or not.

Link copied to clipboard

The list of typing users.

Link copied to clipboard
val user: StateFlow<User?>

Gives us information about the logged in user state.

Functions

Link copied to clipboard
fun banUser(userId: String, reason: String? = null, timeout: Int? = null)

Bans the given user inside this channel.

Link copied to clipboard

Clears the NewMessageState from our UI state, after the user taps on the "Scroll to bottom" or "New Message" actions in the list or simply scrolls to the bottom.

Link copied to clipboard
fun deleteMessage(message: Message, hard: Boolean = false)

Removes the delete actions from our messageActions, as well as the overlay, before deleting the selected message.

Link copied to clipboard

Dismisses all message actions, when we cancel them in the rest of the UI.

Link copied to clipboard

Used to dismiss a specific message action, such as delete, reply, edit or something similar.

Link copied to clipboard
fun flagMessage(message: Message)

Removes the flag actions from our messageActions, as well as the overlay, before flagging the selected message.

Link copied to clipboard
fun getMessageById(messageId: String): Message?

Returns a message with the given ID from the currentMessagesState.

Link copied to clipboard

Leaves the thread we're in and resets the state of the messageMode and both of the MessageListStates.

Link copied to clipboard
fun loadNewerMessages(messageId: String, messageLimit: Int = messageListController.messageLimit)

Loads newer messages of a channel following the currently newest loaded message. In case of threads this will do nothing.

Link copied to clipboard
fun loadOlderMessages(messageLimit: Int = messageListController.messageLimit)

Loads older messages of a channel following the currently oldest loaded message. Also will load older messages of a thread.

Link copied to clipboard
fun muteUser(userId: String, timeout: Int? = null)

Mutes the given user inside this channel.

Link copied to clipboard

Changes the current messageMode to be Thread with ThreadState and Loads thread data using ChatClient directly. The data is observed by using ThreadState.

Link copied to clipboard

Executes one of the actions for the given ephemeral giphy message.

Link copied to clipboard

Triggered when the user selects a new message action, in the message overlay.

Link copied to clipboard

Resets the MessageListStates, to remove the message overlay, by setting 'selectedMessage' to null.

Link copied to clipboard

Removes the shadow ban for the given user inside this channel.

Link copied to clipboard
fun scrollToBottom(messageLimit: Int = messageListController.messageLimit, scrollToBottom: () -> Unit)

Requests that the list scrolls to the bottom to the newest messages. If the newest messages are loaded will set scroll the list to the bottom. If they are not loaded will request the newest data and once loaded will scroll to the bottom of the list.

Link copied to clipboard
fun scrollToMessage(messageId: String, parentMessageId: String?)

Scrolls to message if in list otherwise get the message from backend. Does not work for threads.

Link copied to clipboard

Triggered when the user taps the show more reactions button.

Link copied to clipboard
fun selectMessage(message: Message?)

Triggered when the user long taps on and selects a message.

Link copied to clipboard
fun selectReactions(message: Message?)

Triggered when the user taps on and selects message reactions.

Link copied to clipboard
fun setDateSeparatorHandler(dateSeparatorHandler: DateSeparatorHandler?)

Sets the date separator handler which determines when to add date separators. By default, a date separator will be added if the difference between two messages' dates is greater than 4h.

Link copied to clipboard

Sets the value used to filter deleted messages.

Link copied to clipboard

Sets the value used to determine if message footer content is shown.

Link copied to clipboard

Sets a handler which determines the position of a message inside a group.

Link copied to clipboard
fun setSystemMessageVisibility(areSystemMessagesVisible: Boolean)

Sets whether the system messages should be visible.

Link copied to clipboard
fun setThreadDateSeparatorHandler(threadDateSeparatorHandler: DateSeparatorHandler?)

Sets the thread date separator handler which determines when to add date separators inside the thread.

Link copied to clipboard
fun shadowBanUser(userId: String, reason: String? = null, timeout: Int? = null)

Shadow bans the given user inside this channel.

Link copied to clipboard
fun unbanUser(userId: String)

Unbans the given user inside this channel.

Link copied to clipboard
fun unmuteUser(userId: String)

Unmutes the given user inside this channel.

Link copied to clipboard

Attempts to update the last seen message in the channel or thread. We only update the last seen message the first time the data loads and whenever we see a message that's newer than the current last seen message.

Inherited functions

Link copied to clipboard