Participants

A participant represents a user in a conversation. To add a user to a conversation you can create a participant, and you can delete a participant to kick them. You can track the participants of a conversation in real-time using ConversationRef.subscribeParticipants.

class ParticipantRef

Method Overview

Properties

userId
: String
conversationId
: String

get

participantRef.get(): ParticipantSnapshot?

Returns

ParticipantSnapshot?

set

participantRef.set(data): Unit

Parameters

interface SetParticipantParams

Parameters you can pass when updating a participant.

Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.

access (optional)
: ConversationAccess?

The level of access the participant should have in the conversation. Default = "ReadWrite" access.

notify (optional)
: NotificationSettings?

When the participant should be notified about new messages in this conversation. Default = ReadWrite access.

false means no notifications, true means notifications for all messages, and "MentionsOnly" means that the user will only be notified when they are mentioned with an @.

Returns

Unit

deleteFields

participantRef.deleteFields(fields): Unit

Parameters

fields
: String

Returns

Unit

edit

participantRef.edit(data): Unit

Parameters

interface SetParticipantParams

Parameters you can pass when updating a participant.

Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.

access (optional)
: ConversationAccess?

The level of access the participant should have in the conversation. Default = "ReadWrite" access.

notify (optional)
: NotificationSettings?

When the participant should be notified about new messages in this conversation. Default = ReadWrite access.

false means no notifications, true means notifications for all messages, and "MentionsOnly" means that the user will only be notified when they are mentioned with an @.

Returns

Unit

createIfNotExists

participantRef.createIfNotExists(data): Unit

Parameters

interface CreateParticipantParams

Parameters you can pass when creating a participant (adding a user to a conversation).

access (optional)
: ConversationAccess?

The level of access the participant should have in the conversation. Default = "ReadWrite" access.

notify (optional)
: NotificationSettings?

When the participant should be notified about new messages in this conversation. Default = true

false means no notifications, true means notifications for all messages, and "MentionsOnly" means that the user will only be notified when they are mentioned with an @.

Returns

Unit

delete

participantRef.delete(): Unit

Returns

Unit

constructor

new ParticipantRef.constructor(userId, conversationId, _realtimeClient)

Parameters

userId
: String
conversationId
: String
_realtimeClient
: RealtimeClient

data class ParticipantSnapshot

A snapshot of a participant's attributes at a given moment in time.

Method Overview

Properties

The user who this Participant Snapshot is referring to

access
: ConversationAccess

The level of access this participant has in the conversation.

notify
: NotificationSettings

When the participant will be notified about new messages in this conversation.

false means no notifications, true means notifications for all messages, and "MentionsOnly" means that the user will only be notified when they are mentioned with an @.

joinedAt
: Long

The date that this user joined the conversation, as a unix timestamp in milliseconds.

constructor

new ParticipantSnapshot.constructor(user, access, notify, joinedAt)

Parameters

access
: ConversationAccess
notify
: NotificationSettings
joinedAt
: Long

data class ParticipantSubscription

A subscription to the participants in a specific conversation.

Get a ParticipantSubscription by calling {@link ConversationRef.subscribeParticipants}

The subscription is 'windowed'. It includes everyone who joined since a certain point in time. By default, you subscribe to the 10 most recent participants, and any participants who joined after you subscribe.

You can expand this window by calling {@link ParticipantSubscription.loadMore}, which extends the window further into the past. Do not call .loadMore in a loop until you have loaded all participants, unless you know that the maximum number of participants is small (under 100).

Remember to .unsubscribe the subscription once you are done with it.

Method Overview

Properties

state
: SubscriptionState

The current state of the subscription

An object with the following fields:

type is one of "pending", "active", "unsubscribed", or "error".

When type is "active", includes latestSnapshot and loadedAll.

latestSnapshot: ParticipantSnapshot[] | null the current state of the participants in the window, or null if you're not a participant in the conversation

loadedAll: boolean true when latestSnapshot contains all the participants in the conversation

When type is "error", includes the error field. It is a JS Error object explaining what caused the subscription to be terminated.

connected
: Deferred<SubscriptionState>

Resolves when the subscription starts receiving updates from the server.

Wait for this promise if you want to perform some action as soon as the subscription is active.

The promise rejects if the subscription is terminated before it connects.

terminated
: Deferred<SubscriptionState>

Resolves when the subscription permanently stops receiving updates from the server.

This is either because you unsubscribed or because the subscription encountered an unrecoverable error.

loadMore
: suspend (Int?) -> Unit

Expand the window to include older participants

Calling loadMore multiple times in parallel will still only load one page of participants.

Avoid calling .loadMore in a loop until you have loaded all participants. If you do need to call loadMore in a loop, make sure you set a small upper bound (e.g. 100) on the number of participants, where the loop will exit.

unsubscribe
: () -> Unit

Unsubscribe from this resource and stop receiving updates.

If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.

error (optional)
: Exception?

constructor

new ParticipantSubscription.constructor(state, connected, terminated, loadMore, unsubscribe)

Parameters

state
: SubscriptionState
connected
: Deferred<SubscriptionState>
terminated
: Deferred<SubscriptionState>
loadMore
: suspend (Int?) -> Unit
unsubscribe
: () -> Unit