Read receipts
Read receipts show if channel members have viewed a message.
Required setup
Read Receipts requires Unread Message Count. First, set the last read timetoken for each user on a channel.
Get read receipts
streamReadReceipts() provides read status for messages on a channel. The method fetches member read status, listens for updates, and passes receipt events to your callback.
Not available for public chats
Read receipts are disabled in public chats.
Method signature
1channel.streamReadReceipts(callback: (receipts: Map<Long, List<String>>) -> Unit): AutoCloseable
Input
* required
| Parameter | Description |
|---|---|
callback *Type: n/a Default: 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 *Type: Map<Long, List<String>>Default: 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. |
Sample code
Receive updates for read receipts on the support channel.
1chat.getChannel("support").async { result ->
2 result.onSuccess { channel ->
3 // stream read receipts on the 'support' channel
4 val receiptStream = channel.streamReadReceipts { receipts ->
5 println("Read Receipts Received:")
6 receipts.forEach { (messageTimetoken, users) ->
7 println("Message Timetoken: $messageTimetoken was read by users: $users")
8 }
9 }
10 // when you need to stop receiving read receipts
11 // receiptStream.close()
12 }.onFailure { error ->
13 // handle failure
14 println("Failed to get channel: $error")
15 }
show all 16 lines