If a message sender wants to know who has or has not read the message, the sender needs to enable the message read receipt feature.
After this feature is enabled, the sender can set whether a message requires a read receipt when sending the message; if yes, the sender will receive a receipt after the message is read by the receiver.
// To use it, purchase the Pro edition 、Pro Plus edition or Enterprise edition and set `needReadReceipt` to `true` when creating a message.
needReadReceipt:true
});
// Send the message
let promise = chat.sendMessage(message);
promise.then(function(imResponse){
// Message sent successfully
console.log(imResponse);
}).catch(function(imError){
// Failed to send the message
console.warn('sendMessage error:', imError);
});
Sending a message read receipt (by the receiver)
After receiving the message, the receiver determines whether the message requires a read receipt based on the needReadReceipt field in Message. If yes, after the user reads the message, the receiver calls the sendMessageReadReceipt API to send a read receipt.
Note:
1. Messages in the messageList must be from the same one-to-one or group conversation.
2. After this API is called successfully, the unread count of the conversation will not change, and the sender will receive the TencentCloudChat.TYPES.MESSAGE_READ_RECEIPT_RECEIVED callback which contains the latest read information of the message.
3. Using this API requires you to purchase the Pro edition 、Pro Plus edition or Enterprise edition.
4. Community and AVChatRoom do not support this feature.
5. After successfully calling this API for C2C messages, the message.readReceiptInfo.isPeerRead property of the message sender will be updated to true. This property can be used for rendering the read receipt status of C2C messages. Calling this API will not update the isPeerRead property of the message.
API
chat.sendMessageReadReceipt(messageList);
Parameters
Name
Type
Description
messageList
Array
List of messages (up to 30) in the same conversation
// Read receipt for the one-to-one message sent successfully
}).catch(function(imError){
// Failed to send a read receipt for the one-to-one message
});
});
Listening for a message read receipt notification (by the sender)
After the receiver sends a message read receipt, the sender can listen for a receipt notification and update the UI based on the notification to display the message as, for example, "Read by two members".
Examples
letonMessageReadReceiptReceived=function(event){
// event.data - An array that stores message read receipt information
Pulling message read receipt information (by the sender)
After entering the message list, the sender pulls historical messages first, and then calls the getMessageReadReceipt API to pull the message read receipt information.
Note:
1. Messages in the messageList must be from the same one-to-one or group conversation.
2. Community and AVChatRoom do not support read receipts for group messages.
messageList = imResponse.data.messageList;// Message list
// After the message list is pulled successfully
// `Message.readReceiptInfo` will contain the message read receipt information.
// Message.readReceiptInfo.isPeerRead - Whether the receiver has sent a read receipt
}).catch(function(imError){
// Failed to pull the read receipt list
});
});
Pulling the list of members who have or have not read a group message (by the sender)
To view the list of members who have or have not read a group message, the sender can call the getGroupMessageReadMemberList API to pull the member list by page.
API
chat.getGroupMessageReadMemberList(options);
Parameters
The options parameter is of the Object type. It contains the following attribute values:
Name
Type
Description
message
Message
Message instance
cursor
String
Cursor for the paged pull. Pass in '' for the first pull.
filter
Number
Specifies to pull the list of members who have or have not read the message. Valid values:
0 - pull the list of members who have read the message
1 - pull the list of members who have not read the message
count
Number
Number of members to be pulled per page. Maximum value: 100.
Return value
Promise
Examples
// Pull the list of members who have read the group message
let promise = chat.getGroupMessageReadMemberList({