CometChatMessageDelegate
as Shown Below :
viewDidLoad()
as CometChat.messagedelegate = self
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 him as he was 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 he/she was offline.
Below code, snippet demonstrates how this can be achieved.
fetchNext()
method on the same object repeatedly allows you to fetch all the offline messages for the logged-in user.
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.
setUID()
and setGUID()
methods respectively.
BaseMessage
class. A BaseMessage can either be a TextMessage
or a MediaMessage
. You can use the instanceOf
operator to check the type of object.MessagesRequest
class discussed above, you can fetch all the messages for a logged-in user which involves his messages for all the User and Group conversations. Applying the filters using the MessagesRequestBuilder
class, you can fetch messages either before or after a particular messageId or timestamp.
The below code snippet shows how to fetch the latest 50 messages for the logged-in user which includes messages to and from the logged-in user as a part of any User or Group conversations.
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 search the message for any particular user. For this use case, it is mandatory to set the UID parameter using the set(UID:)
method of the builder and the searchKeyword. This UID is the unique id of the user for which the conversation needs to be fetched and searchKeyword contains the string of the message to be searched.
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 set(UID:)
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 the entire conversation between the logged in user and the specified user. This can be implemented with upward scrolling to display the entire conversation.
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 set(GUID:)
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 for the group. This can be implemented with upward scrolling to display the entire conversation.
getUnreadMessageCountForUser()
.
This method has the below two variants:
onSuccess()
callback, you will receive a dictionary that will contain the UID of the user as the key and the unread message count as the value.
getUnreadMessageCountForGroup()
. This method has the below two variants:
onSuccess()
callback, you will receive a dictionary that 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:
onSuccess()
callback, you will receive a dictionary having two keys:
getUnreadMessageCountForAllUsers()
method.
This method just like others has two variants:
onSuccess()
callback, you will receive a dictionary that will contain the UIDs of the users as the key and the unread message counts as the values.
getUnreadMessageCountForAllGroups()
method. This method just like others has two variants:
onSuccess()
callback, you will receive a dictionary that will contain the GUIDs of the groups as the key and the unread message counts as the values.