Join channels
Requires App Context
Enable App Context on your keyset in the Admin Portal to manage memberships.
Use join() to create a user's membership on a channel. To also receive messages, call onMessageReceived() separately.
Method signature
join() creates a new Membership object that represents the user-channel relationship. Unlike previous versions, join() only sets membership. Use onMessageReceived() to subscribe to incoming messages and Membership.setLastReadMessageTimetoken() to track read status.
This method takes the following parameters:
1channel.join(
2 status: String? = null,
3 type: String? = null,
4 custom: CustomObject? = null,
5): PNFuture<Membership>
Input
* required
| Parameter | Description |
|---|---|
statusType: StringDefault: null | Optional membership status value. |
typeType: StringDefault: null | Optional membership type value. |
customType: CustomObjectDefault: null | Any custom properties or metadata associated with the channel-user membership in the form of a Map. Values must be scalar only; arrays or objects are not supported. |
Output
| Type | Description |
|---|---|
PNFuture<Membership> | Returned object containing the created membership data. |
Sample code
1val channel: Channel
2// ...
3
4// join the channel and add metadata to the newly created membership
5channel.join(custom = mapOf("support_plan" to "premium")).async {
6 it.onSuccess { membership ->
7 // handle success
8 println("Joined channel: ${membership.channel.id}")
9 }.onFailure {
10 // handle failure
11 }
12}
13
14// to also receive messages, call onMessageReceived() separately
15channel.onMessageReceived { message ->
show all 17 lines