stream-chat-android icon indicating copy to clipboard operation
stream-chat-android copied to clipboard

Leaving channels

Open Chikrix opened this issue 7 years ago • 8 comments

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?

Chikrix avatar Oct 23 '19 12:10 Chikrix

closing this one; please re-open if still relevant for you

tbarbugli avatar Dec 11 '19 14:12 tbarbugli

This is still relevant for me @tbarbugli . I just left out the feature for now but it's something we want to add

Chikrix avatar Dec 27 '19 14:12 Chikrix

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?

familywiser1 avatar Jan 23 '20 19:01 familywiser1

also interested in this!

josephto avatar Mar 06 '20 20:03 josephto

@Chikrix did you manage to find the solution for leaving the chat/remove a member from the channel?

adeelnoor avatar Mar 09 '20 10:03 adeelnoor

Any updates on this?

lexa0303 avatar Jun 02 '20 13:06 lexa0303

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.

elevenetc avatar Jun 02 '20 13:06 elevenetc

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.

BohdanSamusko avatar Apr 05 '22 16:04 BohdanSamusko