Leaving channels
I'm trying to implementing leaving a conversation, but I'm not able to do this. When I try using the removeMember and use the user's memberId (user isn't the createdByUser of the channel), I get the message UpdateChannel failed with error: "cannot add or remove members in a distinct channel, please create a new distinct channel with the desired members" (I think this is because the user isn't permitted to do this). Here's my code for trying to achieve this
val memberIds = mutableListOf(memberId) // current User's memberID
streamClient.removeMembers(channel, memberIds, object : ChannelCallback {
override fun onSuccess(response: ChannelResponse?) {
...
}
// throws error with message above here
override fun onError(errMsg: String?, errCode: Int) {
Log.e(...)
}
})
Another approach I tried was using the update method. This time, it tells me that it was successful, but then I still see that the member is still part of this channel as it is still fetched for the user in the channels list. Also I would like to post a system message to other users that a user left, how can I also get that to work?
val membersWithoutCurrentUser = channel.channelState.members.filterNot { it.userId == currentUserUniqueUserId }.map { it.userId }
val currentUser = channel.channelState.members.find { it.userId == currentUserUniqueUserId }
channel.extraData["members"] = membersWithoutCurrentUser
//TODO this got posted as the user that left, how do make this a system message?
val message = Message().apply { text = "Member ${currentUser?.user?.name} left" }
streamClient.updateChannel(channel, message, object : ChannelCallback {
override fun onSuccess(response: ChannelResponse?) {
...
}
override fun onError(errMsg: String?, errCode: Int) {
Log.e(...)
}
})
How can I achieve this functionality?
closing this one; please re-open if still relevant for you
This is still relevant for me @tbarbugli . I just left out the feature for now but it's something we want to add
I also have the same problem. I created a channel without specifying the name and the id. Getstream automatically assigned an id. Now, when I call removeMember, I get the same error (
"UpdateChannel failed with error: "cannot add or remove members in a distinct channel, please create a new distinct channel with the desired members"
How do I implement leaving channel functionality (similar to leaving a group conversation on iOS) if the channel id was automatically assigned by getsream SDK?
also interested in this!
@Chikrix did you manage to find the solution for leaving the chat/remove a member from the channel?
Any updates on this?
Hello @lexa0303 unfortunately there is no way right now to remove members from distinct channel. And there is no plans to change this behaviour in the foreseeable future.
The only solution to edit members list is to not use distinct channels, ie define channel ids.
Specifying channel id when creating new channel resolves this issue.
From the documentation: Channels are unique either by specifying a channel ID or list of members in the create request.