NotAChannelMemberError thrown when trying to leave a channel

Sample Code
/** Testing create/delete */
function createAndDelete() {
	// ChatManager.createDirectMessage(...) just returns the result from kitty.createChannel(...)
	const channel = await ChatManager.createDirectMessage([friendUsername]);
	if (!channel) {
		return;
	}

	// ...

	const user = await ChatManager.getCurrentUser();
	const statusResult = await kitty.getUserIsChannelMember({
		channel,
		user,
	});
	if (isSuccess<GetUserIsChannelMemberSucceededResult>(statusResult)) {
		console.log('Is Member: ', statusResult.isMember); // Outputs: Is Member: true
	}

	const result = await kitty.leaveChannel({
		channel,
	});
	if (isSuccess<LeftChannelResult>(result)) {
		console.log('Left channel!'); // No output
	} else if (isFailure(result)) {
		console.error('Could not leave channel', result.error); // No output
	}

	// ... This is unreachable
}

Leaving a channel seems to result in NotAChannelMemberError being thrown. Looking at the error message, I can clearly see my user in the list of members. Calling kitty.getUserIsChannelMember(...) also confirms this.

The message also shows that the _actions property lacks the leave property. Looking at the source code, this might be part of why the error is thrown, though I’m not sure why leave is missing.

EDIT: Running “Delete Channel Membership” from the REST API returns with an InternalServerError.

Hey @MrGVSV, are you trying to leave a direct channel?

Yes, it’s a direct channel

I see. A user can’t leave a direct channel since it’s directly tied to all members of its members. If a user is no longer interested in the conversation of a direct channel, the user can hide the channel using kitty.hideChannel({ channel }).

However, NotAChannelMemberError is the wrong error to been thrown in this case. I’ll update the error and error message to be more accurate and descriptive.

1 Like