Class MessageListController
-
- All Implemented Interfaces:
public final class MessageListControllerController 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classMessageListController.ErrorEventA class designed for error event propagation.
public final classMessageListController.UnreadLabel
-
Field Summary
Fields Modifier and Type Field Description public final static IntegerDEFAULT_MESSAGES_LIMITprivate final StateFlow<ChannelState>channelStateprivate final StateFlow<ConnectionState>connectionStateprivate final StateFlow<User>userprivate final MutableStateFlow<MessageListController.UnreadLabel>unreadLabelStateprivate final StateFlow<Set<String>>ownCapabilitiesprivate final StateFlow<Channel>channelprivate final StateFlow<MessageMode>modeprivate final BooleanisInThreadprivate final StateFlow<MessageListController.ErrorEvent>errorEventsprivate final StateFlow<Integer>unreadCountprivate final StateFlow<List<User>>typingUsersprivate final StateFlow<MessageListState>messageListStateprivate final StateFlow<MessageListState>threadListStateprivate final StateFlow<MessageListState>listStateprivate final StateFlow<Set<MessageAction>>messageActionsprivate final StateFlow<Boolean>showSystemMessagesStateprivate final StateFlow<MessageFooterVisibility>messageFooterVisibilityStateprivate final StateFlow<DeletedMessageVisibility>deletedMessageVisibilityStateprivate final StateFlow<Boolean>isInsideSearchprivate final IntegermessageLimit
-
Constructor Summary
Constructors Constructor Description MessageListController(String cid, ClipboardHandler clipboardHandler, String messageId, String parentMessageId, Integer messageLimit, ChatClient chatClient, ClientState clientState, DeletedMessageVisibility deletedMessageVisibility, Boolean showSystemMessages, MessageFooterVisibility messageFooterVisibility, Boolean enforceUniqueReactions, DateSeparatorHandler dateSeparatorHandler, DateSeparatorHandler threadDateSeparatorHandler, MessagePositionHandler messagePositionHandler, Boolean showDateSeparatorInEmptyThread, Boolean showThreadSeparatorInEmptyThread)
-
Method Summary
Modifier and Type Method Description final StateFlow<ChannelState>getChannelState()Holds information about the current channel and is actively updated. final StateFlow<ConnectionState>getConnectionState()Gives us information about the online state of the device. final StateFlow<User>getUser()Gives us information about the logged in user state. final MutableStateFlow<MessageListController.UnreadLabel>getUnreadLabelState()Holds information about the unread label state. final StateFlow<Set<String>>getOwnCapabilities()Holds information about the abilities the current user is able to exercise in the given channel. final StateFlow<Channel>getChannel()The information for the current Channel. final StateFlow<MessageMode>getMode()final BooleanisInThread()final StateFlow<MessageListController.ErrorEvent>getErrorEvents()final StateFlow<Integer>getUnreadCount()final StateFlow<List<User>>getTypingUsers()The list of typing users. final StateFlow<MessageListState>getMessageListState()final StateFlow<MessageListState>getThreadListState()final StateFlow<MessageListState>getListState()Current state of the message list depending on the MessageMode the list is in. final StateFlow<Set<MessageAction>>getMessageActions()final StateFlow<Boolean>getShowSystemMessagesState()final StateFlow<MessageFooterVisibility>getMessageFooterVisibilityState()final StateFlow<DeletedMessageVisibility>getDeletedMessageVisibilityState()final StateFlow<Boolean>isInsideSearch()Whether the user is inside search or not. final IntegergetMessageLimit()final UnitdisableUnreadLabelButton()Disable the unread label button. final UnitscrollToFirstUnreadMessage()Scrolls to the first unread message in the channel. final UnitscrollToBottom(Integer messageLimit, Function0<Unit> scrollToBottom)When the user clicks the scroll to bottom button we need to take the user to the bottom of the newest messages. final UnitloadNewerMessages(String baseMessageId, Integer messageLimit)Loads newer messages of a channel following the currently newest loaded message. final UnitloadOlderMessages(Integer messageLimit)Loads more messages if we have reached the oldest message currently loaded. final UnitenterThreadMode(Message parentMessage, Integer messageLimit)Changes the current _mode to be MessageMode.MessageThread and uses ChatClient to get the ThreadState for the current thread. final UnitenterNormalMode()Leaves the thread we're in and switches to MessageMode.Normal. final UnitloadMessageById(String messageId, Function1<Result<Message>, Unit> onResult)Loads a given Message with a single page around it. final UnitscrollToMessage(String messageId, String parentMessageId)Scrolls to the selected message. final UnitselectMessage(Message message)Triggered when the user long taps on and selects a message. final UnitselectReactions(Message message)Triggered when the user taps on and selects message reactions. final UnitselectExtendedReactions(Message message)Triggered when the user taps the show more reactions button. final UnitperformMessageAction(MessageAction messageAction)Triggered when the user selects a new message action, in the message overlay. final UnitdismissMessageAction(MessageAction messageAction)Used to dismiss a specific message action, such as delete, reply, edit or something similar. final UnitdismissAllMessageActions()Dismisses all message actions, when we cancel them in the rest of the UI. final UnitremoveOverlay()Resets the MessagesStates, to remove the message overlay, by setting 'selectedMessageState' to null. final UnitdeleteMessage(Message message, Boolean hard)Deletes the given message. final UnitupdateLastSeenMessage(Message message)Updates the last seen message so we can determine the unread count and mark messages as read. final UnitmarkLastMessageRead()Marks that the last message in the list as read. final UnitflagMessage(Message message, String reason, Map<String, String> customData, Function1<Result<Flag>, Unit> onResult)Flags the selected message. final UnitmarkUnread(Message message, Function1<Result<Unit>, Unit> onResult)Marks the selected message as unread. final UnitupdateMessagePin(Message message)Pins or unpins the message from the current channel based on its state. final UnitpinMessage(Message message)Pins the message from the current channel. final UnitunpinMessage(Message message)Unpins the message from the current channel. final UnitresendMessage(Message message)Resends a failed message. final UnitupdateUserMute(User user)Mutes or unmutes a user for the current user based on the users mute state. final UnitmuteUser(User user)Mutes the given user. final UnitmuteUser(String userId, Integer timeout)Mutes the given user inside this channel. final UnitunmuteUser(User user)Unmutes the given user. final UnitunmuteUser(String userId)Unmutes the given user inside this channel. final UnitreactToMessage(Reaction reaction, Message message)Triggered when the user selects a reaction for the currently selected message. final MessagegetMessageFromListStateById(String messageId)Gets the message if it is inside the list. final UnitclearNewMessageState()Clears the new messages state and drops the unread count to 0 after the user scrolls to the newest message. final UnitbanUser(String userId, String reason, Integer timeout)Bans the given user inside this channel. final UnitunbanUser(String userId)Unbans the given user inside this channel. final UnitshadowBanUser(String userId, String reason, Integer timeout)Shadow bans the given user inside this channel. final UnitremoveShadowBanFromUser(String userId)Removes the shadow ban for the given user inside this channel. final UnitperformGiphyAction(GiphyAction action)Executes one of the actions for the given ephemeral giphy message. final UnitremoveAttachment(String messageId, Attachment attachmentToBeDeleted)Removes a single Attachment from a Message. final UnitsetMessagePositionHandler(MessagePositionHandler messagePositionHandler)Sets the MessagePositionHandler that determines the message position inside a group. final UnitsetDateSeparatorHandler(DateSeparatorHandler dateSeparatorHandler)Sets the date separator handler which determines when to add date separators. final UnitsetThreadDateSeparatorHandler(DateSeparatorHandler threadDateSeparatorHandler)Sets the thread date separator handler which determines when to add date separators inside the thread. final UnitsetMessageFooterVisibility(MessageFooterVisibility messageFooterVisibility)Sets the value used to determine if message footer content is shown. final UnitsetDeletedMessageVisibility(DeletedMessageVisibility deletedMessageVisibility)Sets the value used to filter deleted messages. final UnitsetSystemMessageVisibility(Boolean areSystemMessagesVisible)Sets whether the system messages should be visible. final UnitonCleared()Cancels any pending work when the parent ViewModel is about to be destroyed. -
-
Constructor Detail
-
MessageListController
MessageListController(String cid, ClipboardHandler clipboardHandler, String messageId, String parentMessageId, Integer messageLimit, ChatClient chatClient, ClientState clientState, DeletedMessageVisibility deletedMessageVisibility, Boolean showSystemMessages, MessageFooterVisibility messageFooterVisibility, Boolean enforceUniqueReactions, DateSeparatorHandler dateSeparatorHandler, DateSeparatorHandler threadDateSeparatorHandler, MessagePositionHandler messagePositionHandler, Boolean showDateSeparatorInEmptyThread, Boolean showThreadSeparatorInEmptyThread)
- 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.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.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.showThreadSeparatorInEmptyThread- Configures if we show a thread separator when threads are empty or not.
-
-
Method Detail
-
getChannelState
final StateFlow<ChannelState> getChannelState()
Holds information about the current channel and is actively updated.
-
getConnectionState
final StateFlow<ConnectionState> getConnectionState()
Gives us information about the online state of the device.
-
getUser
final StateFlow<User> getUser()
Gives us information about the logged in user state.
-
getUnreadLabelState
final MutableStateFlow<MessageListController.UnreadLabel> getUnreadLabelState()
Holds information about the unread label state.
-
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.
-
getChannel
final StateFlow<Channel> getChannel()
The information for the current Channel.
-
getMode
final StateFlow<MessageMode> getMode()
-
isInThread
final Boolean isInThread()
-
getErrorEvents
final StateFlow<MessageListController.ErrorEvent> getErrorEvents()
-
getUnreadCount
final StateFlow<Integer> getUnreadCount()
-
getTypingUsers
final StateFlow<List<User>> getTypingUsers()
The list of typing users.
-
getMessageListState
final StateFlow<MessageListState> getMessageListState()
-
getThreadListState
final StateFlow<MessageListState> getThreadListState()
-
getListState
final StateFlow<MessageListState> getListState()
Current state of the message list depending on the MessageMode the list is in.
-
getMessageActions
final StateFlow<Set<MessageAction>> getMessageActions()
-
getShowSystemMessagesState
final StateFlow<Boolean> getShowSystemMessagesState()
-
getMessageFooterVisibilityState
final StateFlow<MessageFooterVisibility> getMessageFooterVisibilityState()
-
getDeletedMessageVisibilityState
final StateFlow<DeletedMessageVisibility> getDeletedMessageVisibilityState()
-
isInsideSearch
final StateFlow<Boolean> isInsideSearch()
Whether the user is inside search or not.
-
getMessageLimit
final Integer getMessageLimit()
-
disableUnreadLabelButton
final Unit disableUnreadLabelButton()
Disable the unread label button.
-
scrollToFirstUnreadMessage
final Unit scrollToFirstUnreadMessage()
Scrolls to the first unread message in the channel.
-
scrollToBottom
final Unit scrollToBottom(Integer messageLimit, Function0<Unit> scrollToBottom)
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.
- Parameters:
messageLimit- The size of the message list page to load.scrollToBottom- Handler that notifies when the message has been loaded.
-
loadNewerMessages
final Unit loadNewerMessages(String baseMessageId, Integer messageLimit)
Loads newer messages of a channel following the currently newest loaded message. In case of threads this will do nothing.
- Parameters:
baseMessageId- The id of the most new Message inside the messages list.messageLimit- The size of the message list page to load.
-
loadOlderMessages
final Unit loadOlderMessages(Integer messageLimit)
Loads more messages if we have reached the oldest message currently loaded.
- Parameters:
messageLimit- The size of the message list page to load.
-
enterThreadMode
final Unit enterThreadMode(Message parentMessage, Integer messageLimit)
Changes the current _mode to be MessageMode.MessageThread and uses ChatClient to get the ThreadState for the current thread.
- Parameters:
parentMessage- The root Message which contains the thread we want to show.messageLimit- The size of the message list page to load.
-
enterNormalMode
final Unit enterNormalMode()
Leaves the thread we're in and switches to MessageMode.Normal.
-
loadMessageById
final Unit loadMessageById(String messageId, Function1<Result<Message>, Unit> onResult)
Loads a given Message with a single page around it.
- Parameters:
messageId- The id of the Message we wish to load.onResult- Handler that notifies the result of the load action.
-
scrollToMessage
final Unit scrollToMessage(String messageId, String parentMessageId)
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.
- Parameters:
messageId- The ID of the Message we wish to scroll to.parentMessageId- The ID of the parent Message if the message we want to scroll to is in a thread.
-
selectMessage
final Unit selectMessage(Message message)
Triggered when the user long taps on and selects a message.
- Parameters:
message- The selected message.
-
selectReactions
final Unit selectReactions(Message message)
Triggered when the user taps on and selects message reactions.
- Parameters:
message- The message that contains the reactions.
-
selectExtendedReactions
final Unit selectExtendedReactions(Message message)
Triggered when the user taps the show more reactions button.
- Parameters:
message- The selected message.
-
performMessageAction
final Unit performMessageAction(MessageAction messageAction)
Triggered when the user selects a new message action, in the message overlay.
We first remove the overlay, after which we consume the event and based on the type of the event, we do different things, such as starting a thread & loading thread data, showing delete or flag events and dialogs, copying the message, muting users and more.
- Parameters:
messageAction- The action the user chose.
-
dismissMessageAction
final Unit dismissMessageAction(MessageAction messageAction)
Used to dismiss a specific message action, such as delete, reply, edit or something similar.
- Parameters:
messageAction- The action to dismiss.
-
dismissAllMessageActions
final Unit dismissAllMessageActions()
Dismisses all message actions, when we cancel them in the rest of the UI.
-
removeOverlay
final Unit removeOverlay()
Resets the MessagesStates, to remove the message overlay, by setting 'selectedMessageState' to null.
-
deleteMessage
final Unit deleteMessage(Message message, Boolean hard)
Deletes the given message.
- Parameters:
message- Message to delete.hard- Whether we do a hard delete or not.
-
updateLastSeenMessage
final Unit updateLastSeenMessage(Message message)
Updates the last seen message so we can determine the unread count and mark messages as read.
- Parameters:
message- The last seen Message.
-
markLastMessageRead
final Unit markLastMessageRead()
Marks that the last message in the list as read. This also sets the unread count to 0.
-
flagMessage
final Unit flagMessage(Message message, String reason, Map<String, String> customData, Function1<Result<Flag>, Unit> onResult)
Flags the selected message.
- Parameters:
message- Message to be flagged.reason- The reason for flagging the message.customData- Additional data to send with the flag.onResult- Handler that notifies the result of the flag action.
-
markUnread
final Unit markUnread(Message message, Function1<Result<Unit>, Unit> onResult)
Marks the selected message as unread.
- Parameters:
message- Message to mark as unread.onResult- Handler that notifies the result of the mark as unread action.
-
updateMessagePin
final Unit updateMessagePin(Message message)
Pins or unpins the message from the current channel based on its state.
- Parameters:
message- The message to update the pin state of.
-
pinMessage
final Unit pinMessage(Message message)
Pins the message from the current channel.
- Parameters:
message- The message to pin.
-
unpinMessage
final Unit unpinMessage(Message message)
Unpins the message from the current channel.
- Parameters:
message- The message to unpin.
-
resendMessage
final Unit resendMessage(Message message)
Resends a failed message.
- Parameters:
message- The Message to be resent.
-
updateUserMute
final Unit updateUserMute(User user)
Mutes or unmutes a user for the current user based on the users mute state.
- Parameters:
user- The User for which to toggle the mute state.
-
muteUser
final Unit muteUser(User user)
Mutes the given user.
- Parameters:
user- The User we wish to mute.
-
muteUser
final Unit muteUser(String userId, Integer timeout)
Mutes the given user inside this channel.
- Parameters:
userId- The ID of the user to be muted.timeout- The period of time for which the user will be muted, expressed in minutes.
-
unmuteUser
final Unit unmuteUser(User user)
Unmutes the given user.
- Parameters:
user- The User we wish to unmute.
-
unmuteUser
final Unit unmuteUser(String userId)
Unmutes the given user inside this channel.
- Parameters:
userId- The ID of the user to be unmuted.
-
reactToMessage
final Unit 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.
- Parameters:
reaction- The reaction to add or remove.message- The currently selected message.
-
getMessageFromListStateById
final Message getMessageFromListStateById(String messageId)
Gets the message if it is inside the list.
- Parameters:
messageId- The Message id we are looking for.- Returns:
The Message with the given id or null if the message is not in the list.
-
clearNewMessageState
final Unit clearNewMessageState()
Clears the new messages state and drops the unread count to 0 after the user scrolls to the newest message.
-
banUser
final Unit banUser(String userId, String reason, Integer timeout)
Bans the given user inside this channel.
- Parameters:
userId- The ID of the user to be banned.reason- The reason for banning the user.timeout- The period of time for which the user will be banned, expressed in minutes.
-
unbanUser
final Unit unbanUser(String userId)
Unbans the given user inside this channel.
- Parameters:
userId- The ID of the user to be unbanned.
-
shadowBanUser
final Unit shadowBanUser(String userId, String reason, Integer timeout)
Shadow bans the given user inside this channel.
- Parameters:
userId- The ID of the user to be shadow banned.reason- The reason for shadow banning the user.timeout- The period of time for which the user will be shadow banned, expressed in minutes.
-
removeShadowBanFromUser
final Unit removeShadowBanFromUser(String userId)
Removes the shadow ban for the given user inside this channel.
- Parameters:
userId- The ID of the user for which the shadow ban is removed.
-
performGiphyAction
final Unit performGiphyAction(GiphyAction action)
Executes one of the actions for the given ephemeral giphy message.
- Parameters:
action- The action to be executed.
-
removeAttachment
final Unit removeAttachment(String messageId, Attachment attachmentToBeDeleted)
Removes a single Attachment from a Message.
- Parameters:
messageId- The Message id that contains the attachment.attachmentToBeDeleted- The Attachment to be deleted from the message.
-
setMessagePositionHandler
final Unit setMessagePositionHandler(MessagePositionHandler messagePositionHandler)
Sets the MessagePositionHandler that determines the message position inside a group.
- Parameters:
messagePositionHandler- The MessagePositionHandler to be used when grouping the list.
-
setDateSeparatorHandler
final Unit 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.
- Parameters:
dateSeparatorHandler- The handler to use.
-
setThreadDateSeparatorHandler
final Unit setThreadDateSeparatorHandler(DateSeparatorHandler threadDateSeparatorHandler)
Sets the thread date separator handler which determines when to add date separators inside the thread.
- Parameters:
threadDateSeparatorHandler- The handler to use.
-
setMessageFooterVisibility
final Unit setMessageFooterVisibility(MessageFooterVisibility messageFooterVisibility)
Sets the value used to determine if message footer content is shown.
- Parameters:
messageFooterVisibility- Changes the visibility of message footers.
-
setDeletedMessageVisibility
final Unit setDeletedMessageVisibility(DeletedMessageVisibility deletedMessageVisibility)
Sets the value used to filter deleted messages.
- Parameters:
deletedMessageVisibility- Changes the visibility of deleted messages.
-
setSystemMessageVisibility
final Unit setSystemMessageVisibility(Boolean areSystemMessagesVisible)
Sets whether the system messages should be visible.
- Parameters:
areSystemMessagesVisible- Whether system messages should be visible or not.
-
-
-
-