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.

    • Constructor Detail

      • MessageListViewModel

        MessageListViewModel(MessageListController messageListController, ChatClient chatClient)
        Parameters:
        messageListController - Controller used to relay the logic and fetch the state.
    • 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.

      • getMode

         final LiveData<MessageMode> getMode()

        Whether the user is viewing a thread.

      • 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.

      • getUnreadLabel

         final LiveData<MessageListController.UnreadLabel> getUnreadLabel()

        Emits the current unread label state.

      • 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.