On this page

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.

Stream read receipts

onReadReceiptReceived() provides read status for messages on a channel via a closure. The method listens for updates and passes ReadReceipt events to the callback. You can also use channel.stream.readReceipts() for an AsyncStream-based approach.

Not available for public chats

Read receipts are disabled in public chats by default. You can control this behavior per channel type with the emitReadReceiptEvents configuration parameter.

Deprecation

streamReadReceipts() is deprecated. Use onReadReceiptReceived() (closure-based) or channel.stream.readReceipts() (AsyncStream-based) instead.

ReadReceipt type

Read receipts now use a typed ReadReceipt struct instead of a raw dictionary:

1public struct ReadReceipt {
2 public let userId: String
3 public let lastReadTimetoken: Timetoken
4}

Method signature

1channel.onReadReceiptReceived(
2 callback: @escaping (ReadReceipt) -> Void
3) -> AutoCloseable

Input

* required
ParameterDescription
callback *
Type: (ReadReceipt) -> Void
Default:
n/a
Closure called with a ReadReceipt whenever someone marks a message as read.

Output

ParameterDescription
AutoCloseable
An object you must retain. When released or closed, the listener stops.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Receive updates for read receipts on the support channel.

1

Fetch read receipts

fetchReadReceipts() retrieves historical read receipts for a channel with pagination support.

Method signature

1channel.fetchReadReceipts(
2 limit: Int? = nil,
3 page: PubNubHashedPage? = nil,
4 filter: String? = nil,
5 sort: [PubNub.MembershipSortField] = []
6) async throws -> (receipts: [ReadReceipt], page: PubNubHashedPage?)

Input

* required
ParameterDescription
limit
Type: Int
Default:
nil
Number of read receipts to return per call.
page
Type: PubNubHashedPage
Default:
nil
Pagination object for fetching additional pages.
filter
Type: String
Default:
nil
Expression to filter results. The filter language is defined here.
sort
Type: [PubNub.MembershipSortField]
Default:
[]
Sort order for results.

Output

ParameterDescription
(receipts: [ReadReceipt], page: PubNubHashedPage?)
A tuple containing an array of ReadReceipt objects and pagination information.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Fetch all read receipts for the support channel.

1