-
public final class MessageListViewModel extends ViewModel
View model class for MessageListView. Responsible for updating the list of messages. Can be bound to the view using MessageListViewModel.bindView function.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classMessageListViewModel.StateThe current state of the message list.
public classMessageListViewModel.EventRepresents events coming from the View class.
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<ChannelState>channelStateprivate final LiveData<Channel>channelprivate final LiveData<Set<String>>ownCapabilitiesprivate final LiveData<Boolean>showSystemMessagesStateprivate final LiveData<MessageFooterVisibility>messageFooterVisibilityStateprivate final LiveData<MessageListViewModel.State>stateprivate final LiveData<MessageMode>modeprivate final LiveData<Boolean>loadMoreLiveDataprivate final LiveData<Message>targetMessageprivate final LiveData<Event<MessageListController.ErrorEvent>>errorEventsprivate final LiveData<User>userprivate final LiveData<Integer>unreadCountprivate final LiveData<Boolean>insideSearchprivate final LiveData<Boolean>shouldRequestMessagesAtBottomprivate final LiveData<MessageListController.UnreadLabel>unreadLabel
-
Constructor Summary
Constructors Constructor Description MessageListViewModel(MessageListController messageListController, ChatClient chatClient)
-
Method Summary
Modifier and Type Method Description final StateFlow<ChannelState>getChannelState()Holds information about the current channel and is actively updated. final LiveData<Channel>getChannel()The current channel used to load the message list data. final LiveData<Set<String>>getOwnCapabilities()Holds information about the abilities the current user is able to exercise in the given channel. final LiveData<Boolean>getShowSystemMessagesState()Determines whether we should show system messages or not. final LiveData<MessageFooterVisibility>getMessageFooterVisibilityState()Regulates the message footer visibility. final LiveData<MessageListViewModel.State>getState()Current message list state. final LiveData<MessageMode>getMode()Whether the user is viewing a thread. final LiveData<Boolean>getLoadMoreLiveData()Emits true if we should are loading more older messages. final LiveData<Message>getTargetMessage()The target message that the list should scroll to. final LiveData<Event<MessageListController.ErrorEvent>>getErrorEvents()Emits error events. final LiveData<User>getUser()The currently logged in user. final LiveData<Integer>getUnreadCount()Unread count of the channel or thread depending on MessageMode. final LiveData<Boolean>getInsideSearch()Emits the status of searching situation. final LiveData<Boolean>getShouldRequestMessagesAtBottom()final LiveData<MessageListController.UnreadLabel>getUnreadLabel()Emits the current unread label state. final UnitonEvent(MessageListViewModel.Event event)Handles an Event coming from the View layer. final MessagegetMessageById(String messageId)Returns a message with the given ID from the messages list. 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 UnitscrollToFirstUnreadMessage()Scrolls to the first unread message in the list. final UnithideUnreadSeparator()Hides the unread label in the messages list (if already visible). final UnitsetDateSeparatorHandler(DateSeparatorHandler dateSeparatorHandler)Sets the date separator handler which determines when to add date separators. final UnitsetThreadDateSeparatorHandler(DateSeparatorHandler threadDateSeparatorHandler)Sets thread date separator handler which determines when to add date separators inside the thread. final UnitsetMessagePositionHandler(MessagePositionHandler messagePositionHandler)Sets a handler which determines the position of a message inside a group. final UnitsetMessageFooterVisibility(MessageFooterVisibility messageFooterVisibility)Sets the value used to determine if message footer content is shown. final UnitsetAreSystemMessagesVisible(Boolean showSystemMessages)Sets whether the system messages should be visible. final UnitpauseAudioRecordingAttachments()Pauses all running audio recording attachments. -
-
Method Detail
-
getChannelState
final StateFlow<ChannelState> getChannelState()
Holds information about the current channel and is actively updated.
-
getChannel
final LiveData<Channel> getChannel()
The current channel used to load the message list data.
-
getOwnCapabilities
final LiveData<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.
-
getShowSystemMessagesState
final LiveData<Boolean> getShowSystemMessagesState()
Determines whether we should show system messages or not.
-
getMessageFooterVisibilityState
final LiveData<MessageFooterVisibility> getMessageFooterVisibilityState()
Regulates the message footer visibility.
-
getState
final LiveData<MessageListViewModel.State> getState()
Current message list state.
-
getLoadMoreLiveData
final LiveData<Boolean> getLoadMoreLiveData()
Emits true if we should are loading more older messages.
-
getTargetMessage
final LiveData<Message> getTargetMessage()
The target message that the list should scroll to. Used when scrolling to a pinned message, a message opened from a push notification or similar.
-
getErrorEvents
final LiveData<Event<MessageListController.ErrorEvent>> getErrorEvents()
Emits error events.
-
getUnreadCount
final LiveData<Integer> getUnreadCount()
Unread count of the channel or thread depending on MessageMode.
-
getInsideSearch
final LiveData<Boolean> getInsideSearch()
Emits the status of searching situation. True when inside a search and false otherwise.
-
getShouldRequestMessagesAtBottom
final LiveData<Boolean> getShouldRequestMessagesAtBottom()
-
getUnreadLabel
final LiveData<MessageListController.UnreadLabel> getUnreadLabel()
Emits the current unread label state.
-
onEvent
final Unit onEvent(MessageListViewModel.Event event)
Handles an Event coming from the View layer.
-
getMessageById
final Message getMessageById(String messageId)
Returns a message with the given ID from the messages list.
- Parameters:
messageId- The ID of the selected message.
-
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 limit of messages to load when loading newest messages.scrollToBottom- The handler that notifies when the data has been loaded to scroll to the bottom.
-
scrollToFirstUnreadMessage
final Unit scrollToFirstUnreadMessage()
Scrolls to the first unread message in the list. If there are no unread messages, this method does nothing.
Important: It is possible that the first unread message is not loaded in the list yet. In this case, the method will first try to load that message, and then scroll to it.
-
hideUnreadSeparator
final Unit hideUnreadSeparator()
Hides the unread label in the messages list (if already visible).
-
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 thread date separator handler which determines when to add date separators inside the thread.
- Parameters:
threadDateSeparatorHandler- The handler to use.
-
setMessagePositionHandler
final Unit setMessagePositionHandler(MessagePositionHandler messagePositionHandler)
Sets a handler which determines the position of a message inside a group.
- Parameters:
messagePositionHandler- The handler to use.
-
setMessageFooterVisibility
final Unit setMessageFooterVisibility(MessageFooterVisibility messageFooterVisibility)
Sets the value used to determine if message footer content is shown.
- Parameters:
messageFooterVisibility- Determines the visibility of message footers.
-
setAreSystemMessagesVisible
final Unit setAreSystemMessagesVisible(Boolean showSystemMessages)
Sets whether the system messages should be visible.
- Parameters:
showSystemMessages- Whether system messages should be visible or not.
-
pauseAudioRecordingAttachments
final Unit pauseAudioRecordingAttachments()
Pauses all running audio recording attachments.
-
-
-
-