watchChannelAsState

fun ChatClient.watchChannelAsState(cid: String, messageLimit: Int, coroutineScope: CoroutineScope = CoroutineScope(DispatcherProvider.IO)): StateFlow<ChannelState?>

Performs ChatClient.queryChannel with watch = true under the hood and returns ChannelState associated with the query. The ChannelState cannot be created before connecting the user therefore, the method returns a StateFlow that emits a null when the user has not been connected yet and the new value every time the user changes.

Return

A StateFlow object that emits a null when the user has not been connected yet and the new ChannelState when the user changes.

Parameters

cid

The full channel id, i.e. "messaging:123"

messageLimit

The number of messages that will be initially loaded.

coroutineScope

The CoroutineScope used for executing the request.


fun ChatClient.watchChannelAsState(cid: String, messageLimit: Int, aroundMessageId: String?, coroutineScope: CoroutineScope = CoroutineScope(DispatcherProvider.IO)): StateFlow<ChannelState?>

Same as watchChannelAsState but loads messages around the given aroundMessageId in the initial request. Use this when opening a channel with focus on a specific message (e.g. deep-link) to avoid a race between the initial watch and a separate loadAround call.

Parameters

aroundMessageId

When non-null, the initial watch uses AROUND_ID pagination to load messages around this ID. Only use for channel-level focus (not when opening a thread).