MessagesRequest
class as you must be familiar with helps you to fetch messages based on the various parameters provided to it. This document will help you understand better the various options that are available using the MessagesRequest
class.
The MessagesRequest
class is designed using the Builder design pattern
. In order to obtain an object of the MessagesRequest
class, you will have to make use of the MessagesRequestBuilder
class in the MessagesRequest
class.
The MessagesRequestBuilder
class allows you to set various parameters to the MessagesRequest
class based on which the messages are fetched.
Steps to generate an object of the MessagesRequest class:
MessagesRequestBuilder
class.build()
method of the MessagesRequestBuilder
class to get an object of the MessagesRequest
class.MessagesRequest
class, you can call either the fetchNext()
method or the fetchPrevious()
method using the object.
maximum of 100
messages can be pulled in a single iteration. Calling the fetchPrevious()
/fetchNext()
method on the same MessagesRequest
object will get you the next set of messages.
Now that you are clear how to use the MessagesRequest
class, below are the various options available:
setLimit()
method. This method takes an integer value as the input and informs the SDK to fetch the specified number of messages in one iteration. The maximum number of messages that can be fetched in one go is 100
.
setUID()
method. This method takes the UID of the user with whom the conversation is to be fetched. When a valid UID is passed, the SDK will return all the messages that are a part of the conversation between the logged-in user and the UID that has been specified.
setGUID()
method. This method takes the GUID of a group for which the conversations are to be fetched. Passing a valid GUID to this method will return all the messages that are a part of the group conversation. Please note that the logged-in user must be a member of the group to fetch the messages for that group.
MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder() .setGUID(“cometchat-guid-1”) .setLimit(50) .build();
setMessageId()
method. This method takes the message-id as input and provides messages only after/before the message-id based on if the fetchNext() or fetchPrevious() method is triggered.
setUID()
or setGUID()
methods to fetch messages after/before any specific message-id for a particular user/group conversation.
setTimestamp()
method. This method takes the Unix timestamp as input and provides messages only after/before the timestamp based on if fetchNext() or fetchPrevious() method is triggered.
setUID()
or setGUID()
methods to fetch messages after/before any specific date or time for a particular user/group conversation.
setUnread()
method. This method takes a boolean value as input. If the value is set to true, the SDK will return just the unread messages.
setGUID()
or setUID()
can be used to fetch unread messages for a particular group or user conversation respectively.
hideMessagesFromBlockedUsers()
method. This method accepts a boolean value which determines if the messages from users blocked by the logged-in user need to be a part if the fetched messages. If the value is set to true, the messages will be hidden and won’t be a part of the messages fetched. The default value is false i.e if this method is not used, the messages from blocked users will be included in the fetched messages.
setUpdatedAfter()
method to get jus the updated messages and not the messages sent/received after the specified time. This method cannot be used independently and always needs to be used with the setUpdatedAfter()
method.
setCategories()
method. This method accepts a list of categories. This tells the SDK to fetch messages only belonging to these categories.
message
and custom
category. This can also be used to disable certain categories of messages like call
and action
. This along with setGUID()
and setUID()
can help display only the messages you wish to display avoiding the other category of messages.
setTypes()
method. This method accepts a list of types. This tells the SDK to fetch messages only belonging to these types.
setParentMessageId()
method. This method needs to be used when you have implemented threaded conversations in your app. This method will return the messages only belonging to the thread with the specified parent Id.
hideReplies()
method. This method is also related to threaded conversations. This method takes boolean as input. This boolean when set to true will make sure that the messages that belong to threads are not fetched. If set to false, which is also the default value, the messages belong to the threads will also be fetched along with other messages.
setTags()
method. This method accepts a list of tags. This tells the SDK to fetch messages only belonging to these tags.
withTags()
method. This method accepts boolean as input. When set to true
, the SDK will fetch messages along with the tags information. When set to false
, the SDK will not fetch tags information associated with messages. The default value for this parameter is false
.
hasLinks()
method. This method accepts boolean as input. When set to true
, the SDK will fetch messages which have links in the text. The default value for this parameter is false
.
Conversation & Advanced Search
. The Conversation & Advanced Search
is only available in Advanced
& Custom
plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search
from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)hasAttachments()
method. This method accepts boolean as input. When set to true
, the SDK will fetch messages which have attachments (image, audio, video or file). The default value for this parameter is false
.
Conversation & Advanced Search
. The Conversation & Advanced Search
is only available in Advanced
& Custom
plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search
from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)hasReactions()
method. This method accepts boolean as input. When set to true
, the SDK will fetch messages which have reactions. The default value for this parameter is false
.
Conversation & Advanced Search
. The Conversation & Advanced Search
is only available in Advanced
& Custom
plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search
from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)hasMentions()
method. This method accepts boolean as input. When set to true
, the SDK will fetch messages which have mentions. The default value for this parameter is false
.
Conversation & Advanced Search
. The Conversation & Advanced Search
is only available in Advanced
& Custom
plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search
from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)setMentionedUIDs()
method. This method accepts an array of UIDs as input. When set, the SDK will fetch messages which have the mentions of the UIDs passed.
Conversation & Advanced Search
. The Conversation & Advanced Search
is only available in Advanced
& Custom
plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search
from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)setAttachmentTypes()
method. This method accepts an array of CometChat.AttachmentType
ENUM values as input. When provided, the SDK will fetch only those messages that include attachments of the specified types (such as image, audio, video, or file).
Conversation & Advanced Search
. The Conversation & Advanced Search
is only available in Advanced
& Custom
plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search
from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)