Read receipts
Read receipts indicate if other channel members have received and viewed a message.
Required setup
Read Receipts feature is tightly coupled with the Unread Message Count feature. To receive message read receipts, you must know which message was last read by which user on a given channel. That's why, to implement the Read Receipts feature, you must first set the timetoken of the last message a user read on a given channel. Based on that, Chat SDK will map a user's last read message to a given message timetoken and let you show this mapping result in your chat app as read or unread.
Get read receipts
streamReadReceipts()
lets you get a read confirmation status for messages you published on a channel.
When called, the method fetches the read status of the members, listens for new messages, and updates the read status accordingly. The read status is then passed as an event of the receipt
type to a callback function for further processing or display.
Not available for public chats
Read receipts are disabled in public chats. If you try implementing this feature in a public channel type, you'll get the Read receipts are not supported in Public chats
error.
Method signature
channel.streamReadReceipts(callback: (receipts: Map<Long, List<String>>) -> Unit): AutoCloseable
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
callback | n/a | Yes | n/a | Callback function passed as a parameter. It defines the custom behavior to be executed when receiving a read confirmation status on the joined channel. |
→ receipts | Map<Long, List<String>> | Yes | n/a | The received object that maps message timetokens (as Long ) to users who last read these messages, like {147289397461273: ["user1", "user2"], 147289399472194: ["user3"]} . |
Output
Type | Description |
---|---|
AutoCloseable | Interface you can call to stop listening for message read receipts and clean up resources when they are no longer needed by invoking the close() method. |
Basic Usage
Receive updates for read receipts on the support
channel.
chat.getChannel("support").async { result ->
result.onSuccess { channel ->
// stream read receipts on the 'support' channel
val receiptStream = channel.streamReadReceipts { receipts ->
println("Read Receipts Received:")
receipts.forEach { (messageTimetoken, users) ->
println("Message Timetoken: $messageTimetoken was read by users: $users")
}
}
// when you need to stop receiving read receipts
// receiptStream.close()
}.onFailure { error ->
// handle failure
println("Failed to get channel: $error")
}
show all 16 lines