Class MessageListController

  • All Implemented Interfaces:

    
    public final class MessageListController
    
                        

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

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

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

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

         final Unit onCleared()

        Cancels any pending work when the parent ViewModel is about to be destroyed.