Skip to main content

Read receipts

Read receipts track per-message read status. Supported in direct and group channels.

Send a message with read receipt

Set needReceipt in message send params before sending:

swift
import NexconnChatSDK
let params = SendMessageParams(content: content)
params.needReceipt = true
guard let channel = GroupChannel(channelId: "groupId") else { return }
channel.sendMessage(params: params, attachedHandler: nil, completionHandler: nil)
PropertyTypeDescription
needReceipt (on NCSendMessageParams)BOOLWhether the recipient should send a read receipt
needReceipt (on NCMessage)BOOLRead-only property indicating whether a receipt is required for this message
sentReceipt (on NCMessage)BOOLWhether the read receipt has been sent

Send a read receipt

After the recipient reads a message, send a read receipt by calling sendReadReceiptResponse on the channel instance:

swift
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else { return }
channel.sendReadReceiptResponse(messageIds: [message.messageId]) { error in
if error == nil {
// Receipt sent
}
}

Listen for read receipts

Register an NCMessageHandler and implement onMessageReceiptResponse::

swift
import NexconnChatSDK
final class MyMessageHandler: NSObject, MessageHandler {
func onMessageReceiptResponse(_ event: MessageReceiptResponseEvent) {
for response in event.responses {
// response.messageId: server message ID
// response.channelIdentifier: channel where the receipt was sent
// response.readCount: number of users who have read the message
// response.unreadCount: number of users who have not read it yet
// response.totalCount: total recipient count
// response.users: list of MessageReadReceiptUser (userId, timestamp, isMentioned)
print("Message \(response.messageId) read by \(response.readCount) users")
}
}
}

let handler = MyMessageHandler()
NCEngine.addMessageHandler(identifier: "MyHandler", handler: handler)