Updating Channel Members

Adding & Removing Channel Members

Using the addMembers() method adds the given users as members, while removeMembers() removes them.

val channelClient = client.channel("messaging", "general")  // Add members with ids "thierry" and "josh" channelClient.addMembers(listOf("thierry", "josh")).enqueue { result ->  if (result is Result.Success) {  val channel: Channel = result.value  } else {  // Handle Result.Failure  } }  // Add member "thierry" with custom data with key: "code_name" and value "007" val params = AddMembersParams(  members = listOf(  MemberData(userId = "thierry", extraData = mapOf("code_name" to "007")),  ), ) channelClient.addMembers(params).enqueue { result ->  if (result is Result.Success) {  val channel: Channel = result.value  } else {  // Handle Result.Failure  } }  // Remove member with id "tommaso" channelClient.removeMembers(listOf("tommaso")).enqueue { result ->  if (result is Result.Success) {  val channel: Channel = result.value  } else {  // Handle Result.Failure  } }

Note: You can only add/remove up to 100 members at once.

Members can also be added while creating the channel.

val channelClient = client.channel("messaging", "general")  // Add members with ids "james_bond", "alec_trevelyan" and "bill_fairbanks" // during channel creation channelClient.create(  memberIds = listOf("james_bond", "alec_trevelyan", "bill_fairbanks"),  extraData = emptyMap(), ).enqueue()  // Add members with custom extra data during channel creation val params = CreateChannelParams(  members = listOf(  MemberData(userId = "james_bond", extraData = mapOf("code_name" to "007")),  MemberData(userId = "alec_trevelyan", extraData = mapOf("code_name" to "006")),  MemberData(userId = "bill_fairbanks", extraData = mapOf("code_name" to "007")),  ),  extraData = emptyMap(), ) channelClient.create(params).enqueue()

Message parameter

You can optionally include a message object that client-side SDKs will use to populate a system message. This works for both add and remove members

val channelClient = client.channel("messaging", "general")  // Add members with ids "thierry" and "josh" channelClient.addMembers(  listOf("thierry", "josh"),  Message(text = "Thierry and Josh joined this channel."), ).enqueue()  // Add members with custom extra data and a system message val params = AddMembersParams(  members = listOf(  MemberData(userId = "thierry", extraData = mapOf("new_member" to true)),  MemberData(userId = "josh", extraData = mapOf("new_member" to true)),  ),  systemMessage = Message(text = "Thierry and Josh joined this channel."), ) channelClient.addMembers(params).enqueue()  // Remove member with id "tommaso" channelClient.removeMembers(  listOf("tommaso"),  Message(text = "Tommaso was removed from this channel."), ).enqueue()

Hide history

When members join a channel you can specify if they have access to the history or not. The history will be shown by default, set true to hide_history parameter to hide it for new members.

// Add members by their IDs with hideHistory=true channelClient.addMembers(  memberIds = listOf("thierry"),  hideHistory = true, ).enqueue()  // Add members by their IDs with hideHistory=true and custom extra data val params = AddMembersParams(  members = listOf(  MemberData(userId = "thierry", extraData = mapOf("new_member" to true)),  ),  hideHistory = true, ) channelClient.addMembers(params).enqueue()

Leaving a channel

It is possible for user to leave the channel without moderator-level permissions. Make sure channel members have Leave Own Channel permission.

channelClient.removeMembers(listOf("my_user_id")).enqueue()

You can familiarize yourself with all permissions in Permissions section

Adding & Removing Moderators to a Channel

Using the addModerators() method adds the given users as moderators (or updates their role to moderator if already members), while demoteModerators() removes the moderator status.

await channel.addModerators(["thierry", "josh"]); await channel.demoteModerators(["tommaso"]);

These operations can only be performed server-side and up to 100 moderators can be added or removed at once.

© Getstream.io, Inc. All Rights Reserved.