Package 

Class MessageListController


  • 
    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, Boolean threadLoadOrderOlderToNewer, String messageId, String parentMessageId, Integer messageLimit, ChatClient chatClient, ClientState clientState, StateFlow<ChannelState> channelState, 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.
        threadLoadOrderOlderToNewer - Determines the order in which the thread messages are loaded.
        messageId - The message id to which we want to scroll to when opening the message list.
        parentMessageId - The ID of the parent message for which we want to initially load the 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.
        channelState - The state of the channel.
        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

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

      • hideUnreadSeparator

         final Unit hideUnreadSeparator()

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

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

         final Unit openRelatedThread(Message message)

        Open the thread for the given message. If the message is a thread start, it will open the thread. If the message is a reply, it will open the thread for the parent message.

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

        @JvmOverloads() final Unit pinMessage(Message message, Date expiresAt)

        Pins the message from the current channel.

        Parameters:
        message - The message to pin.
      • pinMessage

        @JvmOverloads() 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.
      • castVote

         final Unit castVote(String messageId, String pollId, Option option)

        Cast a vote for a poll in a message.

        Parameters:
        messageId - The message id where the poll is.
        pollId - The poll id.
        option - The option to vote for.
      • castAnswer

         final Unit castAnswer(String messageId, String pollId, String answer)

        Cast an answer for a poll in a message.

        Parameters:
        messageId - The message id where the poll is.
        pollId - The poll id.
        answer - The answer to cast.
      • removeVote

         final Unit removeVote(String messageId, String pollId, Vote vote)

        Remove a vote for a poll in a message.

        Parameters:
        messageId - The message id where the poll is.
        pollId - The poll id.
        vote - The vote that should be removed.
      • closePoll

         final Unit closePoll(String pollId)

        Close a poll in a message.

        Parameters:
        pollId - The poll id.
      • closePoll

         final Unit closePoll(Poll poll)

        Closes the given poll.

        Parameters:
        poll - The poll to close.
      • reactToMessage

         final Unit reactToMessage(Reaction reaction, Message message, Boolean skipPush)

        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.
        skipPush - If set to "true", skips sending push notification when reacting to a 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.
      • 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.
      • 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

         final Unit unflagUser(String userId)

        Un-flags a user identified by the provided ID.

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

         final Unit blockUser(String userId)

        Block a user. Unlike ban the block is not channel related but rather directly to the user.

        Parameters:
        userId - the id of the user that will be blocked.
      • unblockUser

         final Unit unblockUser(String userId)

        Unblock a user.

        Parameters:
        userId - the id of the user that will be unblocked.
      • 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.

      • updatePollOption

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

        Updates the poll option for the given message and poll.

        Parameters:
        message - The message containing the poll.
        poll - The poll to update.
        option - The option to update.
      • addPollOption

         final Unit addPollOption(Poll poll, String option)

        Creates a new poll option for the given poll.

        Parameters:
        poll - The poll to which the option will be added.
        option - The text of the new option to be added.
      • addPollOption

         final Unit addPollOption(String pollId, String option)

        Creates a new poll option for the poll identified by pollId.

        Parameters:
        pollId - The id of the poll to which the option will be added.
        option - The text of the new option to be added.