Skip to contentSkip to navigationSkip to topbar
On this page

Read Horizon and Read Status Overview


The Read Horizon feature helps to indicate how far along a particular Chat (SDK) Participant is in the Conversation.


Set a Chat Participant's Read Horizon

set-a-chat-participants-read-horizon page anchor
(information)

Info

The Read Horizon feature is not automatically set. You'll need to set it within your application.

You can mark all of a Conversation's Messages as read by calling the specific method on the Conversation object. For most implementations, marking all messages as read when a user views a particular Conversation in your application is sufficient.

You can also call a different method to set all messages in the Conversation to unread.

To set a Chat Participant's Read Horizon to a specific message, you'll need to retrieve the index property of the Message you want to set the horizon to and then call the appropriate method.

(information)

Info

Message indices are sequential (later messages will have a greater index than previous messages), but are not necessarily consecutive (indices between two messages may increment by more than 1).

You can also use an alternate method to advance the index of the last read message in a conversation to a specific index. This method only changes the Read Horizon if the index you provided is greater than the index that the Read Horizon is currently set to.

This action doesn't change the order of messages in the conversation. It only influences which messages are considered as having been viewed by a participant and which messages are still considered "unread."

Set Read HorizonLink to code sample: Set Read Horizon
1
/*
2
Setting Read Horizon (all forms, like setAllRead, setNoneRead, advanceIndex, etc)
3
*/
4
5
// get a message from conversation
6
const message = await conversation.getMessages().items[5];
7
8
// advance the conversation's last read message index to the current read horizon - won't allow you to move the marker backwards
9
await conversation.advanceLastReadMessageIndex(message.index);
10
11
// set last read message index of the conversation to a specific message
12
await conversation.updateLastReadMessageIndex(message.index);
13
14
// Mark all messages read
15
await conversation.setAllMessagesRead();
16
17
// Mark all messages unread
18
await conversation.setAllMessagesUnread();

Display a Participant's Read Horizon

display-a-participants-read-horizon page anchor

The Conversation SDK will report the Participant's read status and share it with other Participants in the Conversation.

To display how far a specific Participant has read in a Conversation, you will need to get the "last read message" value for that Participant within a Conversation. Once you have this value, you can render this however you want in your UI. For 1:1 messages, some type of checkmark or other visual indicator works well. For group conversations, you'll need to decide how to represent different read positions in the Conversation for each Participant.

From a Conversations list, you can get a specific content (Message) that another Participant has read, by referencing their last read message index.

You can count the number of unread Messages in a Conversation for a specific Participant. This is useful for displaying unread message counters in a list of Conversations.

1
/*
2
Retrieving/checking Read Horizon for rendering
3
*/
4
5
// get last read message index of your participant in the conversation
6
conversation.lastReadMessageIndex();
7
8
// get last read message index of another participant in the conversation
9
participant.lastReadMessageIndex();
10
11
// check the index of a message
12
message.index;
13
14
// get unread messages count for the user, that is, count of all the messages after message
15
await conversation.getUnreadMessagesCount();

You have finished reading the Read Horizon Overview guide. Let's continue learning more about Conversations:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.