Read receipts
Required setup
Read Receipts requires Unread Message Count. First, set the last read timetoken for each user on a channel.
Read receipts show if channel members have viewed a message.
The SDK provides two complementary methods for working with read receipts:
FetchReadReceipts()— one-time paginated fetch. Returns the last-read timetoken for each member. Use this for initial load or on-demand checks. Supports any number of channel members.StreamReadReceipts()— real-time subscription. Delivers updates via the channel'sOnReadReceiptReceiveddelegate as individual users update their read position. Each update contains a single user's last-read timetoken, not a full member list.
Asynchronous and synchronous method execution
Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.
-
Asynchronous methods (
Asyncsuffix) returnvoidand take an optional delegate parameter that fires when the operation completes.1Channel->StreamReadReceiptsAsync(OnStreamReadReceiptsResponseDelegate);You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the
Nativesuffix (for example,FOnPubnubChatOperationResponseNative). -
Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.
1FPubnubChatOperationResult Result = Channel->StreamReadReceipts();
Get read receipts
StreamReadReceipts() provides read status for messages on a channel. The method fetches member read status and listens for updates. Read receipt data is delivered via the channel's OnReadReceiptReceived multicast delegate—bind it before calling StreamReadReceipts().
Not available for public chats
Read receipts are disabled in public chats.
Method signature
1Channel->StreamReadReceipts();
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Contains Error and ErrorMessage; use to check if the operation succeeded. |
To stop receiving read receipt updates, call StopStreamingReadReceipts() on the channel.
Fetch read receipts
Retrieve a snapshot of the current read status for all channel members with FetchReadReceipts(). Unlike StreamReadReceipts(), this is a one-time fetch that does not subscribe to updates.
Method signature
- C++ / Input parameters
1Channel->FetchReadReceipts(
2 int Limit = 0,
3 FString Filter = "",
4 FPubnubMemberSort Sort = FPubnubMemberSort(),
5 FPubnubPage Page = FPubnubPage()
6);
| Parameter | Description |
|---|---|
LimitType: intDefault: 0 | Number of member read receipts to return. Pass 0 to use the server default. |
FilterType: FStringDefault: "" | Expression used to filter the results. The filter language is defined here. |
SortType: FPubnubMemberSortDefault: n/a | Struct defining the property to sort by and sort direction. |
PageType: FPubnubPageDefault: n/a | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination. |
→ PrevType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination. Ignored if Next is supplied. |
Output
| Parameter | Description |
|---|---|
FPubnubChatFetchReadReceiptsResultType: struct | Returned object containing Result, ReadReceipts, Page, and Total. |
→ ResultType: FPubnubChatOperationResult | Contains Error and ErrorMessage for operation status. |
→ ReadReceiptsType: TArray<FPubnubChatReadReceipt> | Array of read receipts for channel members. |
→ UserIDType: FString | Unique identifier of the user who generated this read receipt. |
→ LastReadTimetokenType: FString | Timetoken of the last message read by this user. Messages before this timetoken are considered read. |
→ PageType: FPubnubPage | Object used for pagination. |
→ TotalType: int | Total number of member read receipts. |
Sample code
Fetch the current read receipt status for all members of the support channel.
1FPubnubChatFetchReadReceiptsResult Result = Channel->FetchReadReceipts();
2if (!Result.Result.Error)
3{
4 for (const FPubnubChatReadReceipt& Receipt : Result.ReadReceipts)
5 {
6 UE_LOG(LogTemp, Log, TEXT("User %s last read: %s"), *Receipt.UserID, *Receipt.LastReadTimetoken);
7 }
8}
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Stream read receipt events on a channel.
Actor.h
1
Actor.cpp
1