Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Mark Messages as Delivered

In other words, as a recipient, how do I inform the sender that I’ve received a message? You can mark the messages for a particular conversation as read using the markAsDelivered() method. This method takes the below parameters as input:
ParameterInformation
messageIdThe ID of the message above which all the messages for a particular conversation are to be marked as read.
receiverIdIn case of one to one conversation message’s sender UID will be the receipt’s receiver Id. In case of group conversation message’s receiver Id will be the receipt’s receiver Id.
receiverTypeType of the receiver. Could be either of the two values( user or group).
senderIdThe UID of the sender of the message.
Messages for both user & group conversations can be marked as read using this method. Ideally, you would like to mark all the messages as delivered for any conversation when the user opens the chat window for that conversation. This includes two scenarios:
  1. When the list of messages for the conversation is fetched: In this case you need to obtain the last message in the list of messages and pass the message ID of that message to the markAsDelivered() method.
  2. When the user is on the chat window and a real-time message is received: In this case you need to obtain the message ID of the message and pass it to the markAsDelivered() method.
// Mark as delivered/read (pass message object)
CometChat.markAsDelivered(message);
CometChat.markAsRead(message);

// Mark entire conversation
CometChat.markConversationAsRead("UID", "user");

// Listen for receipt events
CometChat.addMessageListener("LISTENER_ID", new CometChat.MessageListener({
onMessagesDelivered: (receipt) => { },
onMessagesRead: (receipt) => { },
onMessagesDeliveredToAll: (receipt) => { }, // Groups only
onMessagesReadByAll: (receipt) => { } // Groups only
}));

Delivery and read receipts track whether messages have been delivered to and read by recipients.

Mark as Delivered

Use markAsDelivered() to mark messages as delivered. You can pass either a message object or individual parameters.

Using Message Object

CometChat.markAsDelivered(message).then(
  () => {
    console.log("Marked as delivered successfully");
  },
  (error: CometChat.CometChatException) => {
    console.log("Error marking as delivered:", error);
  }
);

Using Parameters

ParameterDescription
messageIdID of the message to mark as delivered
receiverIdFor user chats: sender’s UID. For groups: group GUID
receiverType"user" or "group"
senderIdUID of the message sender
let messageId: string = "MESSAGE_ID";
let receiverId: string = "MESSAGE_SENDER_UID";
let receiverType: string = "user";
let senderId: string = "MESSAGE_SENDER_UID";

CometChat.markAsDelivered(messageId, receiverId, receiverType, senderId).then(
() => {
console.log("Marked as delivered successfully");
},
(error: CometChat.CometChatException) => {
console.log("Error marking as delivered:", error);
}
);

Mark Conversation as Delivered

Use markConversationAsDelivered() to mark all messages in a conversation as delivered. markConversationAsDelivered() resolves with a string on success.
let conversationWith: string = "USER_UID";
let conversationType: string = "user";

CometChat.markConversationAsDelivered(conversationWith, conversationType).then(
(response: string) => {
console.log("Conversation marked as delivered", response);
},
(error: CometChat.CometChatException) => {
console.log("Error:", error);
}
);

Mark as Read

Use markAsRead() to mark messages as read. You can pass either a message object or individual parameters.

Using Message Object

CometChat.markAsRead(message).then(
  () => {
    console.log("Marked as read successfully");
  },
  (error: CometChat.CometChatException) => {
    console.log("Error marking as read:", error);
  }
);

Using Parameters

let messageId: string = "MESSAGE_ID";
let receiverId: string = "MESSAGE_SENDER_UID";
let receiverType: string = "user";
let senderId: string = "MESSAGE_SENDER_UID";

CometChat.markAsRead(messageId, receiverId, receiverType, senderId).then(
() => {
console.log("Marked as read successfully");
},
(error: CometChat.CometChatException) => {
console.log("Error marking as read:", error);
}
);

Mark Conversation as Read

Use markConversationAsRead() to mark all messages in a conversation as read.
let conversationWith: string = "USER_UID";
let conversationType: string = "user";

CometChat.markConversationAsRead(conversationWith, conversationType).then(
(response: string) => {
console.log("Conversation marked as read", response);
},
(error: CometChat.CometChatException) => {
console.log("Error:", error);
}
);

Real-Time Receipt Events

Register a MessageListener to receive delivery and read receipt events.
CallbackDescription
onMessagesDeliveredMessage delivered to a user
onMessagesReadMessage read by a user
onMessagesDeliveredToAllGroup message delivered to all members
onMessagesReadByAllGroup message read by all members
let listenerID: string = "UNIQUE_LISTENER_ID";

CometChat.addMessageListener(
listenerID,
new CometChat.MessageListener({
onMessagesDelivered: (messageReceipt: CometChat.MessageReceipt) => {
console.log("Message delivered:", messageReceipt);
},
onMessagesRead: (messageReceipt: CometChat.MessageReceipt) => {
console.log("Message read:", messageReceipt);
},
onMessagesDeliveredToAll: (messageReceipt: CometChat.MessageReceipt) => {
console.log("Message delivered to all group members:", messageReceipt);
},
onMessagesReadByAll: (messageReceipt: CometChat.MessageReceipt) => {
console.log("Message read by all group members:", messageReceipt);
}
})
);

You will receive events in the form of MessageReceipt objects. The message receipt contains the below parameters:
ParameterInformation
messageIdThe Id of the message prior to which all the messages for that particular conversation have been marked as read.
senderUser object containing the details of the user who has marked the message as read. System User for deliveredToAll & readByAll events.
receiverIdId of the receiver whose conversation has been marked as read.
receiverTypetype of the receiver (user/group)
receiptTypeType of the receipt (read/delivered)
deliveredAtThe timestamp of the time when the message was delivered. This will only be present if the receiptType is delivered.
readAtThe timestamp of the time when the message was read. This will only be present when the receiptType is read.
The markAsDelivered() and markAsRead() methods are fire-and-forget — they do not return a MessageReceipt object. Use the listener callbacks above to receive delivery and read confirmations. You will receive a list of MessageReceipt objects.
The following features will be available only if the Enhanced Messaging Status feature is enabled for your app.
  • onMessagesDeliveredToAll event,
  • onMessagesReadByAll event,
  • deliveredAt field in a group message,
  • readAt field in a group message.
  • markMessageAsUnread method.
Always remove listeners when no longer needed to prevent memory leaks.
CometChat.removeMessageListener("UNIQUE_LISTENER_ID");

MessageReceipt Object

The listener callbacks receive a MessageReceipt object:
FieldGetterReturn TypeDescription
messageIdgetMessageId()stringID of the message
sendergetSender()UserUser who triggered the receipt
receiverIdgetReceiverId()stringID of the receiver
receiverTypegetReceiverType()string"user" or "group"
receiptTypegetReceiptType()string"delivery" or "read"
deliveredAtgetDeliveredAt()numberTimestamp when delivered
readAtgetReadAt()numberTimestamp when read

Get Receipt History

Use getMessageReceipts() to fetch delivery and read receipts for a specific message. Useful for group messages to see which members have received/read the message.
let messageId: number = 123;

CometChat.getMessageReceipts(messageId).then(
(receipts: CometChat.MessageReceipt[]) => {
console.log("Message receipts:", receipts);
},
(error: CometChat.CometChatException) => {
console.log("Error fetching receipts:", error);
}
);

Returns an array of MessageReceipt objects.

Missed Receipts

When fetching messages, each message object includes deliveredAt and readAt timestamps indicating when the message was delivered and read.
let deliveredAt = message.getDeliveredAt();
let readAt = message.getReadAt();
The following features require Enhanced Messaging Status to be enabled for your app: - onMessagesDeliveredToAll event - onMessagesReadByAll event - deliveredAt field in group messages - readAt field in group messages - markMessageAsUnread() method

Mark as Unread

Use markAsUnread() to mark a message as unread. This is useful for “mark as unread” functionality in conversation lists. Pass a message object (TextMessage, MediaMessage, or CustomMessage).
CometChat.markAsUnread(message).then(
  (response: string) => {
    console.log("Message marked as unread:", response);
  },
  (error: CometChat.CometChatException) => {
    console.log("Error marking as unread:", error);
  }
);
ParameterTypeDescription
messageBaseMessageThe message object to mark as unread

Next Steps

Typing Indicators

Show real-time typing status in conversations

Receive Messages

Listen for incoming messages in real time

Retrieve Conversations

Fetch conversation list with unread counts

All Real-Time Listeners

Complete reference for all SDK event listeners