Skip to main content
Give users Slack-style control over thread noise. A user can subscribe to a message thread to be notified of future replies, or unsubscribe from it to mute it. Users are automatically subscribed to a thread when they start it, reply in it, or are @-mentioned in it — and they can explicitly subscribe to any parent message, even one that has no replies yet. The SDK also exposes the list of threads a user participates in, so you can build a thread inbox. Let’s see how to work with thread subscriptions in CometChat’s Android SDK.
Thread subscription builds on Threaded Messages. A thread is identified by the ID of its parent message — there is no separate thread ID.

Subscribe to a Thread

To subscribe to a thread, use the subscribeToThread method with the ID of the thread’s parent message. The call is idempotent — subscribing to a thread the user is already subscribed to succeeds silently. Subscribing to a message with zero replies is allowed; the user will be notified when the first reply arrives.

Unsubscribe from a Thread

To unsubscribe from a thread, use the unsubscribeFromThread method. This too is idempotent — unsubscribing from a thread the user is not subscribed to succeeds silently.
Unsubscribing is not sticky. If the user replies in the thread again, or is @-mentioned in it, they are automatically re-subscribed. Do not promise users “you won’t be notified about this thread again”.

Get the Subscription State

getThreadSubscriptionState returns the logged-in user’s subscription state for a thread synchronously — it never makes a network call, never throws, and is safe to call from your UI while rendering.
The state is a deliberate tri-state, not a boolean:
Render UNKNOWN as the unsubscribed state (an enabled “Subscribe” control) — never as a spinner or a disabled control. The state is kept in an in-memory, per-login-session cache; it is cleared on login and logout, and nothing is persisted to disk.
The cache is seeded only by message fetches that opt in with withThreadSubscribed(true) on the MessagesRequestBuilder — a plain fetch does not carry the subscription state, and getThreadSubscriptionState will keep returning UNKNOWN. Opt in on the requests that back your thread UI:
(The CometChat UI Kit sets this flag internally, so this only concerns you when calling the SDK directly.)

Fetch the Threads a User Participates In

To build a thread inbox — one row per thread the user is part of — create a ThreadsRequest using the ThreadsRequestBuilder. The list is the union of threads the user started, replied in, was mentioned in, or explicitly subscribed to. Every returned row is, by definition, a thread the user is subscribed to: participation is subscription, and unsubscribing removes the row.
Call fetchNext() repeatedly to page forward; hasMore() tells you whether more pages exist. A ThreadsRequest is single-use and forward-only — there is no fetchPrevious(). To refresh the list from the top, build a new request from the builder and replace your list with its results. Calling fetchNext() while a fetch is already in flight fails with a request-in-progress error.

The MessageThread Model

Each row is a MessageThread:
To order rows in your UI, sort on getLastReply().getSentAt(), falling back to getParentMessage().getSentAt() for zero-reply threads — not on getUpdatedAt().
The list starts empty for every user when the feature launches — it fills up as users reply, get mentioned, and subscribe to threads. There is no historical backfill.

Real-time Thread Events

Register a ThreadListener to keep your UI in sync as subscription state changes and replies arrive.
To stop listening, remove the listener with CometChat.removeThreadListener(listenerID).
  • onThreadSubscriptionChanged fires when the logged-in user’s subscription state for a thread changes on this device — after a successful subscribe/unsubscribe call, or after a threaded send auto-subscribes them.
  • onThreadReplyReceived fires for every incoming threaded message and for the user’s own successful threaded sends. Use it to bump reply counts and re-sort your thread list.
Registering a second listener with the same listenerID replaces the first one. Use distinct IDs for distinct screens. A subscribe or unsubscribe performed on the user’s other device does not currently produce a real-time event on this one — the state self-corrects on the next message fetch, so refresh your thread list when the app returns to the foreground.

Notification Preferences

The notification preference for replies gains a new value so users can be notified only for threads they are subscribed to: SUBSCRIBE_TO_SUBSCRIBED_THREADS in the RepliesOptions enum. See Notification Preferences for how to read and update a user’s preferences.

Error Handling