App Context API for PubNub Kotlin SDK
This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.
App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to easily store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.
PubNub also triggers events when object data is set or removed from the database. Clients can receive these events in real time and update their front-end application accordingly.
Calling Kotlin methods
Most PubNub Kotlin SDK method invocations return an Endpoint
object, which allows you to decide whether to perform the operation synchronously or asynchronously. You must choose one of these or the operation will not be performed at all.
For example, the following code is valid and will compile, but the publish won't be performed:
pubnub.publish(
message = "this sdk rules!",
channel = "my_channel"
)
To successfully publish a message, you must follow the actual method invocation with whether to perform it synchronously or asynchronously, for example:
pubnub.publish(
message = "this sdk rules!",
channel = "my_channel"
).async { result, status ->
if (status.error) {
// handle error
} else {
// handle successful method result
}
}
User
Get Metadata for All Users
Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.
Method(s)
To Get All UUID Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.getAllUUIDMetadata(
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
Basic Usage
pubnub.getAllUUIDMetadata()
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNUUIDMetadataArrayResult(
val status: Int,
val data: Collection<PNUUIDMetadata>,
val totalCount: Int?,
val next: PNPage?,
val prev: PNPage?
)
data class PNUUIDMetadata(
val id: String,
val name: String? = null,
val externalId: String?,
val profileUrl: String?,
val email: String?,
val custom: Any?,
show all 18 linesGet User Metadata
Returns metadata for the specified UUID, optionally including the custom data object for each.
Method(s)
To Get UUID Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.getUUIDMetadata(
uuid: String? = null,
includeCustom: Boolean = false
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
includeCustom | Boolean | Optional | false | Whether to include the custom field in the fetch response. |
Basic Usage
pubnub.getUUIDMetadata()
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNUUIDMetadataResult(
val status: Int,
val data: PNUUIDMetadata?
)
data class PNUUIDMetadata(
val id: String,
val name: String? = null,
val externalId: String?,
val profileUrl: String?,
val email: String?,
val custom: Any?,
val updated: Instant?,
val eTag: String?
)
Set User Metadata
Set metadata for a UUID in the database, optionally including the custom data object for each.
Method(s)
To Set UUID Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.setUUIDMetadata(
uuid: String? = null,
includeCustom: Boolean = false,
name: String? = null,
externalId: String? = null,
profileUrl: String? = null,
email: String? = null,
custom: Any? = null,
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
includeCustom | Boolean | Optional | false | Whether to include the custom field in the fetch response. |
name | String? | Optional | null | Display name for the user. Maximum 200 characters. |
externalId | String? | Optional | null | User's identifier in an external system |
profileUrl | String? | Optional | null | The URL of the user's profile picture |
email | String? | Optional | null | The user's email address. Maximum 80 characters |
custom | Any? | Optional | null | Any object of key-value pairs with supported data types. App Context filtering language doesn’t support filtering by custom properties. |
Basic Usage
pubnub.setUUIDMetadata()
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNUUIDMetadataResult(
val status: Int,
val data: PNUUIDMetadata?
)
data class PNUUIDMetadata(
val id: String,
val name: String? = null,
val externalId: String?,
val profileUrl: String?,
val email: String?,
val custom: Any?,
val updated: Instant?,
val eTag: String?
)
Remove User Metadata
Removes the metadata from a specified UUID.
Method(s)
To Remove UUID Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.removeUUIDMetadata(
uuid: String? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
Basic Usage
pubnub.removeUUIDMetadata()
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNRemoveMetadataResult(private val status: Int)
Channel
Get Metadata for All Channels
Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.
Method(s)
To Get All Channel Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.getAllChannelMetadata(
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false,
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
Basic Usage
pubnub.getAllChannelMetadata()
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNChannelMetadataArrayResult(
val status: Int,
val data: Collection<PNChannelMetadata>,
val totalCount: Int?,
val next: PNPage?,
val prev: PNPage?
)
data class PNChannelMetadata(
val id: String,
val name: String?,
val description: String?,
val custom: Any?,
val updated: Instant?,
val eTag: String?
show all 16 linesGet Channel Metadata
Returns metadata for the specified Channel, optionally including the custom data object for each.
Method(s)
To Get Channel Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.getChannelMetadata(
channel: String,
includeCustom: Boolean = false
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | yes | Channel name. | |
includeCustom | Boolean | Optional | false | Whether to include the custom field in the fetch response. |
Basic Usage
pubnub.getChannelMetadata(channel = "myChannel")
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNChannelMetadataResult(
val status: Int,
val data: PNChannelMetadata?
)
data class PNChannelMetadata(
val id: String,
val name: String?,
val description: String?,
val custom: Any?,
val updated: Instant?,
val eTag: String?
)
Set Channel Metadata
Set metadata for a Channel in the database, optionally including the custom data object for each.
Method(s)
To Set Channel Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.setChannelMetadata(
channel: String,
includeCustom: Boolean = false,
name: String? = null,
description: String? = null,
custom: Any? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | yes | Channel name. | |
includeCustom | Boolean | Optional | false | Whether to include the custom field in the fetch response. |
name | String? | Optional | null | Name for the channel. |
description | String? | Optional | null | Description of a channel. |
custom | Any? | Optional | null | Any object of key-value pairs with supported data types. App Context filtering language doesn’t support filtering by custom properties. |
Basic Usage
pubnub.setChannelMetadata(channel = "myChannel")
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNChannelMetadataResult(
val status: Int,
val data: PNChannelMetadata?
)
data class PNChannelMetadata(
val id: String,
val name: String?,
val description: String?,
val custom: Any?,
val updated: Instant?,
val eTag: String?
)
Remove Channel Metadata
Removes the metadata from a specified channel.
Method(s)
To Remove Channel Metadata
you can use the following method(s) in the Kotlin SDK:
pubnub.removeChannelMetadata(
channel: String
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | yes | Channel name. |
Basic Usage
pubnub.removeChannelMetadata(channel = "myChannel")
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNRemoveMetadataResult(private val status: Int)
Channel Memberships
Get Channel Memberships
The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.
Method(s)
To Get Channel Memberships
you can use the following method(s) in the Kotlin SDK:
pubnub.getMemberships(
uuid: String? = null,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false,
includeChannelDetails: PNChannelDetailsLevel? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeChannelDetails | PNChannelDetailsLevel? | Optional | null | The level of channel details to return in the membership. Possible values are: PNChannelDetailsLevel.CHANNEL which include basic channel information and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which includes additionally custom field |
Basic Usage
pubnub.getMemberships()
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNChannelMembershipArrayResult(
val status: Int,
val data: Collection<PNChannelMembership>,
val totalCount: Int?,
val next: PNPage?,
val prev: PNPage?
)
data class PNChannelMembership(
val channel: PNChannelMetadata?,
val custom: Any?,
val updated: Instant,
val eTag: String
)
Set Channel Memberships
Set channel memberships for a UUID.
Method(s)
To Set Channel Memberships
you can use the following method(s) in the Kotlin SDK:
pubnub.setMemberships(
channels: List<PNChannelWithCustom>,
uuid: String? = null,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCount: Boolean = false,
includeCustom: Boolean = false,
includeChannelDetails: PNChannelDetailsLevel? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channels | List<PNChannelWithCustom> | yes | List of PNChannelWithCustom to add to membership with optional custom metadata. | |
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeChannelDetails | PNChannelDetailsLevel? | Optional | null | The level of channel details to return in the membership. Possible values are: PNChannelDetailsLevel.CHANNEL which include basic channel information and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which includes additionally custom field |
Basic Usage
pubnub.setMemberships(listOf(PNChannelWithCustom(channel = "myChannel")))
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNChannelMembershipArrayResult(
val status: Int,
val data: Collection<PNChannelMembership>,
val totalCount: Int?,
val next: PNPage?,
val prev: PNPage?
)
data class PNChannelMembership(
val channel: PNChannelMetadata?,
val custom: Any?,
val updated: Instant,
val eTag: String
)
Remove Channel Memberships
Remove channel memberships for a UUID.
Method(s)
To Remove Channel Memberships
you can use the following method(s) in the Kotlin SDK:
pubnub.removeMemberships(
channels: List<String>,
uuid: String? = null,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCount: Boolean = false,
includeCustom: Boolean = false,
includeChannelDetails: PNChannelDetailsLevel? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channels | List<String> | yes | List of channels to remove from membership. | |
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeChannelDetails | PNChannelDetailsLevel? | Optional | null | The level of channel details to return in the membership. Possible values are: PNChannelDetailsLevel.CHANNEL which include basic channel information and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which includes additionally custom field |
Basic Usage
pubnub.removeMemberships(listOf("myChannel"))
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNChannelMembershipArrayResult(
val status: Int,
val data: Collection<PNChannelMembership>,
val totalCount: Int?,
val next: PNPage?,
val prev: PNPage?
)
data class PNChannelMembership(
val channel: PNChannelMetadata?,
val custom: Any?,
val updated: Instant,
val eTag: String
)
Manage Channel Memberships
Manage a user's channel memberships.
Method(s)
To Manage Memberships
you can use the following method(s) in the Kotlin SDK:
pubnub.manageMemberships(
channelsToSet: List<PNChannelWithCustom>,
channelsToRemove: List<String>,
uuid: String? = null,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false,
includeChannelDetails: PNChannelDetailsLevel? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channelsToSet | List<PNChannelWithCustom> | yes | List of PNChannelWithCustom to add to membership. | |
channelsToRemove | List<String> | yes | List of channels to remove from membership. | |
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeChannelDetails | PNChannelDetailsLevel? | Optional | null | The level of channel details to return in the membership. Possible values are: PNChannelDetailsLevel.CHANNEL which include basic channel information and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which includes additionally custom field. |
Basic Usage
pubnub.manageMemberships(
channelsToSet = listOf(PNChannelWithCustom(channel = "myChannelToSet")),
channelsToRemove = listOf("myChannelToRemove")
).async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNChannelMembershipArrayResult(
val status: Int,
val data: Collection<PNChannelMembership>,
val totalCount: Int?,
val next: PNPage?,
val prev: PNPage?
)
data class PNChannelMembership(
val channel: PNChannelMetadata?,
val custom: Any?,
val updated: Instant,
val eTag: String
)
Channel Members
Get Channel Members
The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.
Method(s)
To Get Channel Members
you can use the following method(s) in the Kotlin SDK:
pubnub.getChannelMembers(
channel: String,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false,
includeUUIDDetails: PNUUIDDetailsLevel? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | yes | Channel name. | |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeUUIDDetails | PNUUIDDetailsLevel? | Optional | null | The level of UUID details to return. Possible values are: PNUUIDDetailsLevel.UUID which include basic UUID information and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which includes additionally custom field. |
Basic Usage
pubnub.getChannelMembers()
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNMemberArrayResult(
val status: Int,
val data: Collection<PNMember>,
val totalCount: Int?,
val next: PNPage.PNNext?,
val prev: PNPage.PNPrev?
)
data class PNMember(
val uuid: PNUUIDMetadata?,
val custom: Any? = null,
val updated: Instant,
val eTag: String
)
Set Channel Members
This method sets members in a channel.
Method(s)
To Set Channel Members
you can use the following method(s) in the Kotlin SDK:
pubnub.setChannelMembers(
uuids: List<PNUUIDWithCustom>,
channel: String,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false,
includeUUIDDetails: PNUUIDDetailsLevel? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuids | List<PNUUIDWithCustom> | yes | List of members PNUUIDWithCustom to add to channel. | |
channel | String | yes | Channel name. | |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeUUIDDetails | PNUUIDDetailsLevel? | Optional | null | The level of UUID details to return. Possible values are: PNUUIDDetailsLevel.UUID which include basic UUID information and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which includes additionally custom field |
Basic Usage
pubnub.setChannelMembers(channel = "myChannel", uuids = listOf(PNUUIDWithCustom(uuid = "myUuid")))
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNMemberArrayResult(
val status: Int,
val data: Collection<PNMember>,
val totalCount: Int?,
val next: PNPage.PNNext?,
val prev: PNPage.PNPrev?
)
data class PNMember(
val uuid: PNUUIDMetadata?,
val custom: Any? = null,
val updated: Instant,
val eTag: String
)
Remove Channel Members
Remove members from a Channel.
Method(s)
To Remove Channel Members
you can use the following method(s) in the Kotlin SDK:
pubnub.removeChannelMembers(
uuids: List<String>,
channel: String,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false,
includeUUIDDetails: PNUUIDDetailsLevel? = null
).async { result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuids | List<String> | yes | List of members UUIDs to remove from channel. | |
channel | String | yes | Channel name. | |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeUUIDDetails | PNUUIDDetailsLevel? | Optional | null | The level of UUID details to return. Possible values are: PNUUIDDetailsLevel.UUID which include basic UUID information and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which includes additionally custom field. |
Basic Usage
pubnub.removeChannelMembers(channel = "myChannel", uuids = listOf("myUuid"))
.async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNMemberArrayResult(
val status: Int,
val data: Collection<PNMember>,
val totalCount: Int?,
val next: PNPage.PNNext?,
val prev: PNPage.PNPrev?
)
data class PNMember(
val uuid: PNUUIDMetadata?,
val custom: Any? = null,
val updated: Instant,
val eTag: String
)
Manage Channel Members
Set and Remove channel memberships for a user.
Method(s)
To Manage Channel Members
you can use the following method(s) in the Kotlin SDK:
pubnub.manageChannelMembers(
uuidsToSet: List<PNUUIDWithCustom>,
uuidsToRemove: List<String>,
channel: String,
filter: String? = null,
sort: Collection<PNSortKey> = listOf(),
page: PNPage? = null,
limit: Int? = null,
includeCustom: Boolean = false,
includeCount: Boolean = false,
includeUUIDDetails: PNUUIDDetailsLevel? = null
).async {result, status -> }
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuidsToSet | List<PNUUIDWithCustom> | yes | List of members PNUUIDWithCustom to add to channel with optional custom metadata. | |
uuidsToRemove | List<String> | yes | List of members UUIDs to remove from channel. | |
channel | String | yes | Channel name. | |
filter | String? | Optional | null | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | List<PNSortKey> | Optional | listOf() | List of properties to sort by. Available options are id , name , and updated . Use asc or desc to specify sort direction. For example: {name: 'asc'} |
page | PNPage? | Optional | null | The paging object used for pagination. |
limit | Int | Optional | 100 | The number of objects to retrieve at a time. |
includeCustom | Boolean | Optional | false | Whether to include the Custom field in the fetch response. |
includeCount | Boolean | Optional | false | Request IncludeCount to be included in paginated response. By default, IncludeCount is omitted. |
includeUUIDDetails | PNUUIDDetailsLevel? | Optional | null | The level of UUID details to return. Possible values are: PNUUIDDetailsLevel.UUID which include basic UUID information and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which includes additionally custom field |
Basic Usage
pubnub.setChannelMembers(
channel = "myChannel",
uuidsToSet = listOf(PNUUIDWithCustom(uuid = "myUuidToSet"),
uuidsToRemove = listOf("myUuidToRemove"),
)).async { result, status ->
if (status.error) {
//handle error
} else if (result != null) {
//handle result
}
}
Response
data class PNMemberArrayResult(
val status: Int,
val data: Collection<PNMember>,
val totalCount: Int?,
val next: PNPage.PNNext?,
val prev: PNPage.PNPrev?
)
data class PNMember(
val uuid: PNUUIDMetadata?,
val custom: Any? = null,
val updated: Instant,
val eTag: String
)
App Context Filtering Language Definition
The filtering language for App Context is similar to the stream filtering language.
Note the following:
Date/time properties, such as
updated
, must be compared to valid date/time strings formatted according to ISO 8601.The LIKE operator supports wildcards denoted by the
*
character. A wildcard matches any sequence of arbitrary Unicode characters, including the empty sequence. The literal asterisk is matched when escaped using the backslash (\
) character.Values used with LIKE must be properly encoded just like any other string value. Thus, in order to escape an asterisk, the raw value must contain
\\*
.The entire expression must be properly URL-encoded when used in the query string.
Custom property filtering
You can't filter by custom properties.
<expression> ::= <and_expression> ( "||" <and_expression> )*
<and_expression> ::= <binary_condition> ( "&&" <binary_condition> )*
<binary_condition> ::= "!" <binary_condition> | "(" <expression> ")" | <relational_condition>
<relational_condition> ::= <property_path> <relational_operator> <value>
<property_path> ::= <property_name> ( "." <property_name> )*
<property_name> ::= <identifier> | "[" <string> "]"
<value> ::= <string> | <number> | "true" | "false" | "null"
Tokens
<identifier> ::= <letter> | "$" | "_" ( <letter> | "$" | "_" | <digit> )*
<relational_operator> ::= "==" | "!=" | "<=" | ">=" | "<" | ">" | "LIKE"
<string> ::= <double_quote> ( "\" <double_quote> | "\" <special_char>
| "\" "u" <hex_digit> <hex_digit> <hex_digit> <hex_digit>
| <unicode_char> - <double_quote> - "\" )* <double_quote>
show all 26 linesSample object filtering operations
The following date/time comparison returns results that were modified on or after August 31st, 2019 (UTC):
updated >= "2019-08-31T00:00:00Z"
The following wildcard expression returns results whose name starts with the letter X:
name LIKE 'X*'
The following escaped wildcard expression returns results whose name contains an asterisk:
name LIKE '*\\**'