/ UIKit / Android View
UIKit
Chat UIKit Android View v3
Chat UIKit Android View
Chat UIKit
Android View
Version 3

Filter message list

Copy link

You can statically filter messages when retrieving a message. Currently, dynamic filtering is not supported. To change the filtering criteria, you must recreate the channel.


Set MessageListParams directly when creating a ViewModel

Copy link

The ChannelViewModel is responsible for fetching and managing messages from a channel. You can filter these messages by changing the properties of MessageListParams within the ChannelViewModel. See this page if you need help with customizing a ViewModel.

You can inherit from ChannelViewModel and implement the createMessageListParams()method. When you call the super.createMessageListParams() method, you can then obtain the default params setting used by the UIKit.

class MessageFilteringSampleViewModel(channelUrl: String) : ChannelViewModel(channelUrl, null) {
    override fun createMessageListParams(): MessageListParams {
        val params = super.createMessageListParams()
        // To get UserMessage only 
        params.messageTypeFilter = MessageTypeFilter.USER

        // TODO: Uncomment this to filter message list.
        /*
        params.messagePayloadFilter =
        params.customTypes =
        */
        return params
    }
}

Set MessageListParams through fragment builder

Copy link

The fragment builder also provides an interface to customize the MessageListParams. In this case, however, the default setting used by the UIKit can't be retrieved.

val fragment = ChannelFragment.Builder(channelUrl)
    .setMessageListParams(MessageListParams().apply {
        val filter = MessagePayloadFilter().apply {
            this.includeReactions = false
            // TODO: Uncomment this to filter message list.
            /*
            this.includeMetaArray
            this.includeParentMessageInfo
            this.includeThreadInfo
            */
        }
        messagePayloadFilter = filter
        // TODO: Uncomment this to filter message list.
        /*
        messageTypeFilter =
        customTypes =
        */
    })
    .build()

For an in-depth practical demonstration, see our sample code.