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 thesubscribeToThread 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.
- Java
- Kotlin
Unsubscribe from a Thread
To unsubscribe from a thread, use theunsubscribeFromThread method. This too is idempotent — unsubscribing from a thread the user is not subscribed to succeeds silently.
- Java
- Kotlin
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.
- Java
- Kotlin
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.Fetch the Threads a User Participates In
To build a thread inbox — one row per thread the user is part of — create aThreadsRequest 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.
- Java
- Kotlin
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 aMessageThread:
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 aThreadListener to keep your UI in sync as subscription state changes and replies arrive.
- Java
- Kotlin
CometChat.removeThreadListener(listenerID).
onThreadSubscriptionChangedfires 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.onThreadReplyReceivedfires 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.