Class MessageListViewModel
-
- All Implemented Interfaces:
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<DeletedMessageVisibility>deletedMessageVisibilityprivate 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<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<DeletedMessageVisibility>getDeletedMessageVisibility()Regulates the visibility of deleted messages. 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<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 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 UnitsetDeletedMessageVisibility(DeletedMessageVisibility deletedMessageVisibility)Sets the value used to filter deleted messages. 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. -
-
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.
-
getDeletedMessageVisibility
final LiveData<DeletedMessageVisibility> getDeletedMessageVisibility()
Regulates the visibility of deleted messages.
-
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.
-
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.- Returns:
The Message with the ID, if it exists.
-
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.
-
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.
-
setDeletedMessageVisibility
final Unit setDeletedMessageVisibility(DeletedMessageVisibility deletedMessageVisibility)
Sets the value used to filter deleted messages.
- Parameters:
deletedMessageVisibility- Determines the visibility of deleted messages.
-
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.
-
-
-
-