CometChat Pro Documentation

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Typing Indicators

Start Typing

You can use the startTyping() method to inform the receiver that the logged in user has started typing. The receiver will receive this information in the onTypingStarted() method of the CometChatMessageDelegate protocol conformance. In order to send the typing indicator, you need to use the TypingIndicator class.

let typingIndicator = TypingIndicator(receiverID: "receiverUID", receiverType: .user, metadata: nil)

CometChat.startTyping(indicator: typingIndicator)
TypingIndicator *typingIndicator = [[TypingIndicator alloc]initWithReceiverID:@"receiverID" receiverType: ReceiverTypeUser metadata:nil];

[CometChat startTypingWithIndicator:typingIndicator];

End Typing

You can use the endTyping() method to inform the receiver that the logged in user has stopped typing. The receiver will receive this information in the onTypingEnded() method of the CometChatMessageDelegate protocol conformance. In order to send the typing indicator, you need to use the TypingIndicator class.

let typingIndicator = TypingIndicator(receiverID: "receiverUID", receiverType: .user, metadata: nil)

CometChat.endTyping(indicator: typingIndicator)
TypingIndicator *typingIndicator = [[TypingIndicator alloc]initWithReceiverID:@"receiverID" receiverType: ReceiverTypeUser metadata:nil];

[CometChat endTypingWithIndicator:typingIndicator];

Custom Data

You can use the metaData field of the TypingIndicator class to pass additional data along with the typing indicators. The metaData field is a dictionary and this property can be set from TypingIndicator class. This data will be received at the receiver end and can be obtained using the metaData property.

Receiving Typing Indicators

In order to receive typing indicators, you must add protocol conformance CometChatMessageDelegate.

extension ViewController: CometChatMessageDelegate {

  func onTypingStarted(_ typingDetails : TypingIndicator) {

    print("Typing started received successfully")
  }

  func onTypingEnded(_ typingDetails : TypingIndicator) {

    print("Typing ended received successfully")
  }
}
@interface ViewController ()<CometChatMessageDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CometChat.messagedelegate = self ;
}

- (void)onTypingStarted:(TypingIndicator *)typingDetails {
    NSLog(@"Typing started received successfully");
}

- (void)onTypingEnded:(TypingIndicator *)typingDetails {
    NSLog(@"Typing ended received successfully");
}

@end

The TypingIndicator class consists of the below properties:

Properties
Information

sender

An object of the User class holding all the information. related to the sender of the typing indicator.

receiverId

Unique Id of the receiver. This can be the Id of the group or the user the typing indicator is sent to.

receiverType

This parameter indicates if the typing indicator is to be sent to a user or a group. The possible values are:

  1. CometChat.ReceiverType.user
  2. CometChat.ReceiverType.group

metaData

A Dictionary to provide additional data

Read Receipts

Mark a Message as Read

You can mark the message as read once the user has read it using the markMessageAsRead() method. This method takes an object of the message that needs to be marked as read. Messages for both User conversation and Groups can be marked as read using this method.

CometChat.markMessageAsRead(message : message)
[CometChat markMessageAsReadWithMessage: message];

Receiving events for Message Delivery and Read

You can get the real-time events for the messages being delivered and read by the receiver of the message using the onMessageDelivered() and the onMessageRead() methods of the CometChatMessageDelegate protocol conformance.

extension ViewController : CometChatMessageDelegate {
    
    func onMessageDelivered(receipt : MessageReceipt) {
       
        print("Message delivered receipt received.")
    }
    
    func onMessageRead(receipt : MessageReceipt) {
        
        print("Message read receipt received.")
    }
}
@interface ViewController () <CometChatMessageDelegate>

@end

@implementation ViewController

- (void)onMessageReadWithReceipt:(MessageReceipt *)receipt {
    NSLog(@"Message delivered receipt received.");
}

- (void)onMessageDeliveredWithReceipt:(MessageReceipt *)receipt {
    NSLog(@"Message read receipt received.");
}

@end

Note: The real-time events for a group message will only be sent to the sender of the message.

You will receive events in the form of MessageReceipt objects.

While fetching messages in bulk, if the message is a part of a user conversation, the message object will have two fields viz. deliveredAt and readAt which hold the timestamp for the time the message was delivered and read respectively. using these two variables, the delivery and read status for a user message can be obtained.

However, for a group message, the deliveredAt and readAt fields are never set and hence to get the status of the message you can use the below-described method.

Get Message Receipts

In order to fetch the message receipts, you can use the getMessageReceipts() method.

let messageId = 10101;

CometChat.getMessageReceipts(messageId, onSuccess: { (receipts) in
         
   print("Fetched message receipts successfully.")
   
}, onError:  { (error) in
            
   print("Error in while fetching message receipts: \(error?.errorDescription)")
   
})
NSInteger messageId = 10101;
[CometChat getMessageReceiptsWithMessageId:messageId onSuccess: ^(MessageReceipts  *)receipts {

  NSLog(@"Fetched message receipts successfully.");
  
}, onError: ^(CometChatException *)error {

  NSLog(@"Error in while fetching message receipts: %@", error.errorDescription);
  
}];

You will receive a list of MessageReceipt objects in the onSuccess() method.

Unread Message Count

Unread Message count for a user.

In order to get the unread message count for a particular user, you can use the getUnreadMessageCountForUser(). This method has the below two variants:

CometChat.getUnreadMessageCountForUser(UID, callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUnreadMessageCountForUser(UID, hideMessagesFromBlockedUsers:true, callbacks)
let UID = "Superhero1"
  
CometChat.getUnreadMessageCountForUser(UID, onSuccess: { (response) in
                
    print("Unread count for users: \(response)")
                
}) { (error) in
                
    print("Error in unread count for users: \(error)")
}

in the onSuccess() callback, you will receive a dictionary which will contain the UID of the user as the key and the unread message count as the value.

Unread Message count for a group.

In order to get the unread message count for a particular group, you can use the getUnreadMessageCountForGroup(). This method has the below two variants:

CometChat.getUnreadMessageCountForGroup(GUID, callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUnreadMessageCountForGroup(GUID, hideMessagesFromBlockedUsers:true, callbacks)
let GUID = "Supergroup"
  
CometChat.getUnreadMessageCountForGroup(GUID, onSuccess: { (response) in
                
    print("Unread count for groups: \(response)")
                
}) { (error) in
                
    print("Error in unread count for group: \(error.errorDescription)")
}

in the onSuccess() callback, you will receive a dictionary which will contain the GUID of the group as the key and the unread message count as the value.

Get all unread message count

In order to get all the unread message count combined i.e unread message counts for all the users and groups, you can use the getUnreadMessageCount() method. This method has two variants:

CometChat.getUnreadMessageCount(callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUnreadMessageCount(hideMessagesFromBlockedUsers:true, callbacks)
CometChat.getUnreadMessageCount(onSuccess: { (response) in
            
    print("Unread message count: \(response)")
            
}) { (error) in
            
    print("Error in fetching unread count: \(error)")
}

in the onSuccess() callback, you will receive a dictionary having two keys:

  1. user - The value for this key holds another dictionary that holds the UIDs of the users and their corresponding unread message counts
  2. group - The value for this key holds another dictionary that holds the GUIDs of the groups and their corresponding unread message counts

Get unread message count for all the users:

In order to fetch the unread message counts for just the users, you can use the getUnreadMessageCountForAllUsers() method. This method just like others has two variants:

CometChat.getUnreadMessageCountForAllUsers(callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUnreadMessageCountForAllUsers(hideMessagesFromBlockedUsers:true, callbacks)
CometChat.getUnreadMessageCountForAllUsers(onSuccess: { response in
            
    print("Unread count for all users: \(response)")
            
}) { (error) in
            
    print("Error in fetching unread count for all users: \(error?.errorDescription)")
}

in the onSuccess() callback, you will receive a dictionary which will contain the UIDs of the users as the key and the unread message counts as the values.

Get unread message count for all groups:

In order to fetch the unread message counts for just the groups, you can use the getUnreadMessageCountForAllGroups() method. This method just like others has two variants:

CometChat.getUnreadMessageCountForAllGroups(callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUnreadMessageCountForAllGroups(hideMessagesFromBlockedUsers:true, callbacks)
CometChat.getUnreadMessageCountForAllGroups(onSuccess: { response in
            
    print("Unread count for all groups: \(response)")
            
}) { (error) in
            
    print("Error in fetching unread count for all groups: \(error.errorDescription)")
}

in the onSuccess() callback, you will receive a dictionary which will contain the GUIDs of the groups as the key and the unread message counts as the values.

Undelivered Message Count

Undelivered message count for a user

In order to get the undelivered message count for a particular user, you can use the getUndeliveredMessageCountForUser(). This method has the below two variants:

CometChat.getUndeliveredMessageCountForUser(UID, callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUndeliveredMessageCountForUser(UID, hideMessagesFromBlockedUsers:true, callbacks)
let UID = "Superhero"
CometChat.getUndeliveredMessageCountForUser(UID, onSuccess: { (response) in
                
    print("Undelivered count for user: \(response)")
                
}) { (error) in
                
    print("Error in undelivered count for user: \(error)")
}

in the onSuccess() callback, you will receive a dictionary which will contain the UID of the user as the key and the undelivered message count as the value.

Undelivered Message Count for a Group

In order to get the undelivered message count for a particular group, you can use the getUndeliveredMessageCountForGroup(). This method has the below two variants:

CometChat.getUndeliveredMessageCountForGroup(GUID, callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUndeliveredMessageCountForGroup(GUID, hideMessagesFromBlockedUsers:true, callbacks)
let GUID = "Supergroup"
CometChat.getUndeliveredMessageCountForGroup(GUID, onSuccess: { (response) in
                
    print("Undelivered count for group: \(response)")
                
}) { (error) in
                
    print("Error in undelivered count for group: \(error)")
}

in the onSuccess() callback, you will receive a dictionary which will contain the GUID of the group as the key and the undelivered message count as the value.

Get all undelivered message count

In order to get all the undelivered message count combined i.e undelivered message counts for all the users and groups, you can use the getUndeliveredMessageCount() method. This method has two variants:

CometChat.getUndeliveredMessageCount(callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUndeliveredMessageCount(hideMessagesFromBlockedUsers:true, callbacks)
CometChat.getUndeliveredMessageCount(hideMessagesFromBlockedUsers:true, onSuccess: { (response) in
                
    print("Undelivered count: \(response)")
                
}) { (error) in
                
    print("Error in undelivered count: \(error)")
}

in the onSuccess() callback, you will receive a hashmap having two keys:

  1. user - The value for this key holds another dictionary that holds the UIDs of the users and their corresponding undelivered message counts
  2. group - The value for this key holds another dictionary that holds the GUIDs of the groups and their corresponding undelivered message counts

Get undelivered message count for all users:

In order to fetch the undelivered message counts for just the users, you can use the getUndeliveredMessageCountForAllUsers() method. This method just like others has two variants:

CometChat.getUnrdeliveredMessageCountForAllUsers(callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUnrdeliveredMessageCountForAllUsers(hideMessagesFromBlockedUsers:true, callbacks)
CometChat.getUnrdeliveredMessageCountForAllUsers(hideMessagesFromBlockedUsers:true, onSuccess: { response in
            
    print("Undelivered count for all users: \(response)")
            
}) { (error) in
            
    print("Error in fetching undelivered count for all users: \(error.errorDescription)")
}

in the onSuccess() callback, you will receive a hashmap which will contain the UIDs of the users as the key and the undelivered message counts as the values.

Get undelivered message count for all groups:

In order to fetch the undelivered message counts for just the groups, you can use the getUndeliveredMessageCountForAllGroups() method. This method just like others has two variants:

CometChat.getUndeliveredMessageCountForAllGroups(callbacks)

if you wish to ignore the messages from blocked users you can use the below syntax setting the boolean parameter to true:

CometChat.getUndeliveredMessageCountForAllGroups(callbacks)
CometChat.getUndeliveredMessageCountForAllGroups(onSuccess: { response in
            
    print("Undelivered count for all groups: \(response)")
            
}) { (error) in
            
    print("Error in fetching undelivered count for all groups: \(error.errorDescription)")
}

in the onSuccess() callback, you will receive a dictionary which will contain the GUIDs of the groups as the key and the undelivered message counts as the values.

Advanced


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.