Package 

Class MessageListViewModel


  • 
    public final class MessageListViewModel
    extends ViewModel
                        

    ViewModel responsible for handling all the business logic & state for the list of messages.

    • Constructor Detail

      • MessageListViewModel

        MessageListViewModel(MessageListController messageListController)
        Parameters:
        messageListController - Controller used to relay the logic and fetch the state.
    • Method Detail

      • getCurrentMessagesState

         final State<MessageListState> getCurrentMessagesState()

        State handler for the UI, which holds all the information the UI needs to render messages.

        It chooses between threadListState and messageListState based on if we're in a thread or not.

      • getMessageMode

         final MessageMode getMessageMode()

        Holds the current MessageMode that's used for the messages list. MessageMode.Normal by default.

      • getPollState

         final PollState getPollState()

        Holds the current PollState that's used for the messages list.

      • getChannel

         final Channel getChannel()

        The information for the current Channel.

      • getChannelState

         final StateFlow<ChannelState> getChannelState()

        Holds information about the current channel and is actively updated.

      • getMessageActions

         final Set<MessageAction> getMessageActions()

        Set of currently active MessageActions. Used to show things like edit, reply, delete and similar actions.

      • getConnectionState

         final StateFlow<ConnectionState> getConnectionState()

        Gives us information about the online state of the device.

      • getIsOnline

         final Flow<Boolean> getIsOnline()

        Gives us information about the online state of the device.

      • getUser

         final StateFlow<User> getUser()

        Gives us information about the logged in user state.

      • getEvents

         final SharedFlow<MessageListController.Event> getEvents()

        Flow of one-shot events such as action successes and errors.

      • updateLastSeenMessage

         final Unit updateLastSeenMessage(Message message)

        Attempts to update the last seen message in the channel or thread. We only update the last seen message the first time the data loads and whenever we see a message that's newer than the current last seen message.

        Parameters:
        message - The message that is currently seen by the user.
      • loadNewerMessages

         final Unit loadNewerMessages(String messageId, Integer messageLimit)

        Loads newer messages of a channel following the currently newest loaded message. In case of threads this will do nothing.

        Parameters:
        messageId - The id of the newest Message inside the messages list.
        messageLimit - The limit of messages to be loaded in the page.
      • loadOlderMessages

         final Unit loadOlderMessages(Integer messageLimit)

        Loads older messages of a channel following the currently oldest loaded message. Also will load older messages of a thread.

        Parameters:
        messageLimit - The limit of messages to be loaded in the page.
      • selectMessage

         final Unit selectMessage(Message message)

        Triggered when the user long taps on and selects a message.

        Parameters:
        message - The selected message.
      • displayPollMoreOptions

         final Unit displayPollMoreOptions(SelectedPoll selectedPoll)

        Triggered when the user taps the show more options button on the poll message.

        Parameters:
        selectedPoll - The poll that holds the details to be drawn on the more options screen.
      • updatePollState

         final Unit updatePollState(Poll poll, Message message, PollSelectionType pollSelectionType)

        Triggered when the poll information has been changed and need to sync on the poll states.

        Parameters:
        poll - The poll that holds the details to be drawn on the more options screen.
        message - The message that contains the poll information.
      • 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.
      • openMessageThread

         final Unit openMessageThread(Message message)

        Changes the current messageMode to be Thread with ThreadState and Loads thread data using ChatClient directly. The data is observed by using ThreadState.

        Parameters:
        message - The selected message with a thread.
      • 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.
      • 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.
      • deleteMessage

        @JvmOverloads() final Unit deleteMessage(Message message)

        Removes the delete actions from our messageActions, as well as the overlay, before deleting the selected message.

        Parameters:
        message - Message to delete.
      • flagMessage

         final Unit flagMessage(Message message, String reason, Map<String, String> customData)

        Removes the flag actions from our messageActions, as well as the overlay, before flagging the selected message.

        Parameters:
        message - Message to delete.
      • 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(String userId)

        Unmutes the given user inside this channel.

        Parameters:
        userId - The ID of the user to be unmuted.
      • 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.
      • flagUser

         final Unit flagUser(String userId, String reason, Map<String, String> customData)

        Flags a user identified by the provided ID.

        Parameters:
        userId - The ID of the user to flag.
        reason - The reason for flagging the user.
        customData - Additional key-value data submitted with the request.
      • unflagUser

        @Deprecated(message = The backend no longer supports un-flagging. This call does nothing and will be removed in the next major version., level = DeprecationLevel.WARNING) final Unit unflagUser(String userId)

        Un-flags a user identified by the provided ID.

        Parameters:
        userId - The ID of the user to un-flag.
      • leaveThread

         final Unit leaveThread()

        Leaves the thread we're in and resets the state of the messageMode and both of the MessageListStates.

      • removeOverlay

         final Unit removeOverlay()

        Resets the MessageListStates, to remove the message overlay, by setting 'selectedMessage' to null.

      • clearNewMessageState

         final Unit clearNewMessageState()

        Clears the NewMessageState from our UI state, after the user taps on the "Scroll to bottom" or "New Message" actions in the list or simply scrolls to the bottom.

      • performGiphyAction

         final Unit performGiphyAction(GiphyAction action)

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

        Parameters:
        action - The action to be executed.
      • castVote

         final Unit castVote(Message message, Poll poll, Option option)

        Cast a vote for a poll in a message.

        Parameters:
        message - The message where the poll is.
        poll - The poll that want to be casted a vote.
        option - The option to vote for.
      • castAnswer

         final Unit castAnswer(Message message, Poll poll, String answer)

        Cast an answer for a poll in a message.

        Parameters:
        message - The message where the poll is.
        poll - The poll that want to be casted an answer.
        answer - The answer that should be casted.
      • removeVote

         final Unit removeVote(Message message, Poll poll, Vote vote)

        Remove a vote for a poll in a message.

        Parameters:
        message - The message where the poll is.
        poll - The poll that want to be casted a vote.
        vote - The vote that should be removed.
      • closePoll

         final Unit closePoll(String pollId)

        Close a poll in a message.

        Parameters:
        pollId - The poll id.
      • scrollToMessage

         final Unit scrollToMessage(String messageId, String parentMessageId)

        Scrolls to message if in list otherwise get the message from backend. Does not work for threads.

        Parameters:
        messageId - The Message id we wish to scroll to.
        parentMessageId - The ID of the parent Message if the message we want to scroll to is in a thread.
      • scrollToBottom

         final Unit scrollToBottom(Integer messageLimit, Function0<Unit> scrollToBottom)

        Requests that the list scrolls to the bottom to the newest messages. If the newest messages are loaded will set scroll the list to the bottom. If they are not loaded will request the newest data and once loaded will scroll to the bottom of the list.

        Parameters:
        messageLimit - The message count we wish to load from the API when loading new messages.
        scrollToBottom - Notifies the ui to scroll to the bottom if the newest messages are in the list or have been loaded from the API.
      • 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.

      • disableUnreadLabelButton

         final Unit disableUnreadLabelButton()

        Hides the floating unread-label button without scrolling. The inline unread separator remains visible. Use this for explicit dismiss affordances (e.g. a close icon on the scroll-to-first-unread pill).

      • hideUnreadSeparator

         final Unit hideUnreadSeparator()

        Hides the unread label in the messages list (if already visible).

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

         final Unit setSystemMessageVisibility(Boolean areSystemMessagesVisible)

        Sets whether the system messages should be visible.

        Parameters:
        areSystemMessagesVisible - Whether system messages should be visible or not.
      • addPollOption

         final Unit addPollOption(Poll poll, String option)

        Adds a new poll option to the given poll.

        Parameters:
        poll - The poll to add the option to.
        option - The option to add.
      • toggleOriginalText

         final Unit toggleOriginalText(String messageId)

        Toggles between the translated and the original text of the message (if the message was auto-translated).

        Parameters:
        messageId - The ID of the message for which to toggle the original text.