MessageListener
using the addMessageListener()
method.
We suggest adding the listener in the onResume()
method of the activity or the fragment where you wish to receive these events in.
Parameter | Description |
---|---|
listenerID | An ID that uniquely identifies that listener. We recommend using the activity or fragment name |
onPause()
method.
MessagesRequest
class and the filters provided by the MessagesRequestBuilder
class, you can fetch the message that we sent to the logged-in user but were not delivered to them as they were offline. For this, you will require the ID of the last message received. You can either maintain it at your end or use the getLastDeliveredMessageId()
method provided by the CometChat class. This ID needs to be passed to the setMessageId()
method of the builder class.
Now using the fetchNext()
method, you can fetch all the messages that were sent to the user when they were offline.
Calling the fetchNext()
method on the same object repeatedly allows you to fetch all the offline messages for the logged in user in a paginated manner
MessagesRequest
class described above, you can fetch the unread messages for the logged-in user. In order to achieve this, you need to set the unread
variable in the builder to true
using the setUnread()
method so that only the unread messages are fetched.
BaseMessage
class. A BaseMessage
can either be an object of the TextMessage
, MediaMessage
, CustomMessage
, Action
or Call
class. You can use the instanceOf
operator to check the type of object.MessagesRequest
class and the filters for the MessagesRequestBuilder
class as shown in the below code snippet, you can fetch the entire conversation between the logged in user and any particular user. For this use case, it is mandatory to set the UID parameter using the setUID()
method of the builder. This UID is the unique id of the user for which the conversation needs to be fetched.
fetchPrevious()
method on the same object repeatedly allows you to fetch all the previous messages in a paginated way.
MessagesRequest
class and the filters for the MessagesRequestBuilder
class as shown in the below code snippet, you can fetch the entire conversation for any group provided you have joined the group. For this use case, it is mandatory to set the GUID parameter using the setGUID()
method of the builder. This GUID is the unique identifier of the Group for which the messages are to be fetched.
fetchPrevious()
method on the same object repeatedly allows you to fetch the entire conversation between the logged in user and the specified user. This can be implemented with upward scrolling to display the entire conversation.
setSearchKeyword()
method. This method accepts string as input. When set, the SDK will fetch messages which match the searchKeyword
.
Conversation & Advanced Search
, the searchKey will be searched in message text, file name, mentions & mime type of the file.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)Feature | Basic Search | Advance Search |
---|---|---|
Text search | ✅ | ✅ |
File name search | ❌ | ✅ |
Mentions search | ❌ | ✅ |
Mime type search | ❌ | ✅ |
getUnreadMessageCountForUser()
.
This method has the two variants:
true
:
onSuccess()
callback, you will receive a Hashmap which will contain the UID
of the user as the key and the unread message count as the value.
getUnreadMessageCountForGroup()
.
This method has two variants:
true
:
onSuccess()
callback, you will receive a Hashmap which will contain the GUID
of the group as the key and the unread message count as the value.
getUnreadMessageCount()
method. This method has two variants:
true
:
onSuccess()
callback, you will receive a hashmap having two keys:
user
- The value for this key holds another hashmap that holds the UIDs
of users and their corresponding unread message counts.group
- The value for this key holds another hashmap that holds the GUIDs
of groups and their corresponding unread message counts.getUnreadMessageCountForAllUsers()
method.
This method, just like others, has two variants:
true
:
onSuccess()
callback, you will receive a Hashmap that will contain the UIDs
of users as the key and the unread message counts as the values.
getUnreadMessageCountForAllGroups()
method.
This method has two variants:
true
:
onSuccess()
callback, you will receive a hashmap which will contain the GUIDs
of the groups as the key and the unread message counts as the values.