MessageListController

class MessageListController(cid: String, clipboardHandler: ClipboardHandler, messageId: String? = null, parentMessageId: String? = null, val messageLimit: Int = DEFAULT_MESSAGES_LIMIT, chatClient: ChatClient = ChatClient.instance(), clientState: ClientState = chatClient.clientState, deletedMessageVisibility: DeletedMessageVisibility = DeletedMessageVisibility.ALWAYS_VISIBLE, showSystemMessages: Boolean = true, messageFooterVisibility: MessageFooterVisibility = MessageFooterVisibility.WithTimeDifference(), enforceUniqueReactions: Boolean = true, dateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultDateSeparatorHandler(), threadDateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultThreadDateSeparatorHandler(), messagePositionHandler: MessagePositionHandler = MessagePositionHandler.defaultHandler(), showDateSeparatorInEmptyThread: Boolean = false, showThreadSeparatorInEmptyThread: Boolean = false)

Controller responsible for handling message list state. It acts as a central place for core business logic and state required to show the message list, message thread and handling message actions.

Parameters

cid

The channel id in the format messaging:123.

clipboardHandler

ClipboardHandler used to copy messages.

messageId

The message id to which we want to scroll to when opening the message list.

parentMessageId

The ID of the parent Message if the message we want to scroll to is in a thread. If the message we want to scroll to is not in a thread, you can pass in a null value.

messageLimit

The limit of messages being fetched with each page od data.

chatClient

The client used to communicate with the API.

clientState

The current state of the SDK.

deletedMessageVisibility

The DeletedMessageVisibility to be applied to the list.

showSystemMessages

Determines if the system messages should be shown or not.

messageFooterVisibility

Determines if and when the message footer is visible or not.

enforceUniqueReactions

Determines whether the user can send only a single or multiple reactions to a message. If it is true the new reaction will override the old reaction.

dateSeparatorHandler

Determines the visibility of date separators inside the message list.

threadDateSeparatorHandler

Determines the visibility of date separators inside the thread.

messagePositionHandler

Determines the position of the message inside a group.

showDateSeparatorInEmptyThread

Configures if we show a date separator when threads are empty. Adds the separator item when the value is true.

showThreadSeparatorInEmptyThread

Configures if we show a thread separator when threads are empty or not. Adds the separator item when the value is true.

Constructors

Link copied to clipboard
constructor(cid: String, clipboardHandler: ClipboardHandler, messageId: String? = null, parentMessageId: String? = null, messageLimit: Int = DEFAULT_MESSAGES_LIMIT, chatClient: ChatClient = ChatClient.instance(), clientState: ClientState = chatClient.clientState, deletedMessageVisibility: DeletedMessageVisibility = DeletedMessageVisibility.ALWAYS_VISIBLE, showSystemMessages: Boolean = true, messageFooterVisibility: MessageFooterVisibility = MessageFooterVisibility.WithTimeDifference(), enforceUniqueReactions: Boolean = true, dateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultDateSeparatorHandler(), threadDateSeparatorHandler: DateSeparatorHandler = DateSeparatorHandler.getDefaultThreadDateSeparatorHandler(), messagePositionHandler: MessagePositionHandler = MessagePositionHandler.defaultHandler(), showDateSeparatorInEmptyThread: Boolean = false, showThreadSeparatorInEmptyThread: Boolean = false)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed class ErrorEvent

A class designed for error event propagation.

Properties

Link copied to clipboard
val channel: StateFlow<Channel>

The information for the current Channel.

Link copied to clipboard
val channelState: StateFlow<ChannelState?>

Holds information about the current channel and is actively updated.

Link copied to clipboard

Gives us information about the online state of the device.

Link copied to clipboard
Link copied to clipboard
val isInsideSearch: StateFlow<Boolean>

Whether the user is inside search or not.

Link copied to clipboard

Gives us information if we're currently in the MessageMode.MessageThread mode.

Link copied to clipboard
val listState: StateFlow<MessageListState>

Current state of the message list depending on the MessageMode the list is in.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val mode: StateFlow<MessageMode>
Link copied to clipboard
val ownCapabilities: StateFlow<Set<String>>

Holds information about the abilities the current user is able to exercise in the given channel.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val typingUsers: StateFlow<List<User>>

The list of typing users.

Link copied to clipboard
val unreadCount: StateFlow<Int>
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 new messages state and drops the unread count to 0 after the user scrolls to the newest message.

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

Deletes the given 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

Leaves the thread we're in and switches to MessageMode.Normal.

Link copied to clipboard
suspend fun enterThreadMode(parentMessage: Message, messageLimit: Int = this.messageLimit)

Changes the current _mode to be MessageMode.MessageThread and uses ChatClient to get the ThreadState for the current thread.

Link copied to clipboard
fun flagMessage(message: Message, onResult: (Result<Flag>) -> Unit = {})

Flags the selected message.

Link copied to clipboard

Gets the message if it is inside the list.

Link copied to clipboard
fun loadMessageById(messageId: String, onResult: (Result<Message>) -> Unit = {})

Loads a given Message with a single page around it.

Link copied to clipboard
fun loadNewerMessages(baseMessageId: String, messageLimit: Int = this.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 = this.messageLimit)

Loads more messages if we have reached the oldest message currently loaded.

Link copied to clipboard

Marks that the last message in the list as read. This also sets the unread count to 0.

Link copied to clipboard
fun markUnread(message: Message, onResult: (Result<Unit>) -> Unit = {})

Marks the selected message as unread.

Link copied to clipboard
fun muteUser(user: User)

Mutes the given user.

fun muteUser(userId: String, timeout: Int? = null)

Mutes the given user inside this channel.

Link copied to clipboard
fun onCleared()

Cancels any pending work when the parent ViewModel is about to be destroyed.

Link copied to clipboard

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

Link copied to clipboard
suspend fun performMessageAction(messageAction: MessageAction)

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

Link copied to clipboard
fun pinMessage(message: Message)

Pins the message from the current channel.

Link copied to clipboard
fun reactToMessage(reaction: Reaction, message: Message)

Triggered when the user selects a reaction for the currently selected message. If the message already has that reaction, from the current user, we remove it. Otherwise we add a new reaction.

Link copied to clipboard
fun removeAttachment(messageId: String, attachmentToBeDeleted: Attachment)

Removes a single Attachment from a Message.

Link copied to clipboard

Resets the MessagesStates, to remove the message overlay, by setting 'selectedMessageState' to null.

Link copied to clipboard

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

Link copied to clipboard
fun resendMessage(message: Message)

Resends a failed message.

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

When the user clicks the scroll to bottom button we need to take the user to the bottom of the newest messages. If the messages are not loaded we need to load them first and then scroll to the bottom of the list.

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

Scrolls to the selected message. If the message is not currently in the list it will first load a page with the message in the middle of it, add it to the list and then notify to scroll to the message.

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 the MessagePositionHandler that determines the message position 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(user: User)

Unmutes the given user.

fun unmuteUser(userId: String)

Unmutes the given user inside this channel.

Link copied to clipboard
fun unpinMessage(message: Message)

Unpins the message from the current channel.

Link copied to clipboard

Updates the last seen message so we can determine the unread count and mark messages as read.

Link copied to clipboard

Pins or unpins the message from the current channel based on its state.

Link copied to clipboard
fun updateUserMute(user: User)

Mutes or unmutes a user for the current user based on the users mute state.