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

References a given user's participation in a conversation.

Used in all Data API operations affecting that participant, such as joining/leaving a conversation, or setting their access. Created via .

Method Overview

createIfNotExists

Adds the user as a participant, or does nothing if they are already a participant.

delete

Removes the user as a participant, or does nothing if they are already not a participant.

deleteFields

Deletes properties of this participant.

edit

Edits properties of a pre-existing participant. If the user is not already a participant in the conversation, the function will throw.

get

Fetches a snapshot of the participant.

set

Sets properties of this participant. If the user is not already a participant in the conversation, they will be added.

Properties

conversationId
: String

The ID of the conversation the user is participating in.

Immutable: if you want to reference the user in a different conversation, get a new ParticipantRef instead.

userId
: String

The ID of the user who is participating.

Immutable: if you want to reference a different participant, get a new ParticipantRef instead.

createIfNotExists

participantRef.createIfNotExists(data): Unit

Adds the user as a participant, or does nothing if they are already a participant.

If the participant already exists, this operation is still considered successful.

The function will throw if client-side conversation syncing is disabled and the user is not already a participant.

Parameters

data class 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 = READ_WRITE 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 MENTIONS_ONLY means that the user will only be notified when they are mentioned with an @.

Returns

Unit

delete

participantRef.delete(): Unit

Removes the user as a participant, or does nothing if they are already not a participant.

Deleting a nonexistent participant is treated as success.

This function will throw if client-side conversation syncing is disabled.

Returns

Unit

deleteFields

participantRef.deleteFields(vararg fields): Unit

Deletes properties of this participant.

Pass the name of each property to delete as a separate parameter to this function.

Parameters

vararg fields
: String

Returns

Unit

edit

participantRef.edit(data): Unit

Edits properties of a pre-existing participant. If the user is not already a participant in the conversation, the function will throw.

When client-side conversation syncing is disabled, you must already be a participant and you cannot set anything except the notify property. Everything else requires client-side conversation syncing to be enabled, and will cause the function to throw.

Parameters

data class SetParticipantParams

Parameters you can pass when updating a participant.

Properties that are null will not be changed. To clear / reset a property to the default, call ParticipantRef.deleteFields instead.

access (optional)
: ConversationAccess?

The level of access the participant should have in the conversation. Default = READ_WRITE 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 MENTIONS_ONLY means that the user will only be notified when they are mentioned with an @.

Returns

Unit

get

participantRef.get(): ParticipantSnapshot?

Fetches a snapshot of the participant.

This contains all of the participant's public information.

Returns

ParticipantSnapshot?

A snapshot of the participant's attributes, or null if the user is not a participant. The function will throw if you are not a participant and try to read information about someone else.

set

participantRef.set(data): Unit

Sets properties of this participant. If the user is not already a participant in the conversation, they will be added.

When client-side conversation syncing is disabled, you must already be a participant and you cannot set anything except the notify property. Everything else requires client-side conversation syncing to be enabled, and will cause the function to throw.

Parameters

data class SetParticipantParams

Parameters you can pass when updating a participant.

Properties that are null will not be changed. To clear / reset a property to the default, call ParticipantRef.deleteFields instead.

access (optional)
: ConversationAccess?

The level of access the participant should have in the conversation. Default = READ_WRITE 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 MENTIONS_ONLY means that the user will only be notified when they are mentioned with an @.

Returns

Unit

data class ParticipantSnapshot

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

Properties

access
: ConversationAccess

The level of access this participant has in the conversation.

joinedAt
: Long

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

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 MENTIONS_ONLY means that the user will only be notified when they are mentioned with an @.

user
: UserSnapshot

The user who this Participant Snapshot is referring to

data class ParticipantSubscription

A subscription to the participants in a specific conversation.

Get a ParticipantSubscription by calling

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 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.

Properties

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.

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.

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 "pending", the subclass type of this property is .

When type is "active", the subclass type of this property is ParticipantActiveState.

When type is "unsubscribed", the subclass type of this property is .

When type is "error", the subclass type of this property is .

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.

unsubscribe
: () -> Unit

Unsubscribe from this resource and stop receiving updates.

If the subscription is already in the or , this is a no-op.

data class ParticipantActiveState

The state of a participants subscription when it is actively listening for changes

Properties

latestSnapshot (optional)
: List<ParticipantSnapshot>?

The most recently received snapshot for the participants, or null if you are not a participant in that conversation.

loadedAll
: Boolean

True if latestSnapshot contains all participants in the conversation. Use ParticipantSubscription.loadMore to load more.

type
: String