Unable to `shadowBan` or `Ban` user from a specific channel
I'm using getStream.io to integrate chat in my flutter app. The app have one-on-one chatting feature, so I want users to be able to block other users.
To do that I have written a node.js cloud function backend in typescript. The users can pass the user Id of the person they want to block from their personal one-on-one chatting channel.
That users will be "shadow banned" from the channel, so the user that requested blocking will not receive messages and the blocked user won't know that they are blocked.
The backend code is as follows:
import * as functions from "firebase-functions";
import { StreamChat } from "stream-chat";
export const blockUser = functions.https.onCall(
async (data: {
fromUserId: string;
toBlockUserId: string;
shouldBlock: boolean;
}) => {
// Get data from request
const { fromUserId, toBlockUserId, shouldBlock } = data;
// Get admin Stream Chat client
const serverClient = StreamChat.getInstance(
process.env.API_KEY_VAR as string,
process.env.SECRET_KEY_VAR
);
// Get channel for the caller and the user to be blocked
const channel = serverClient.channel("messaging", {
members: [fromUserId, toBlockUserId],
});
if (shouldBlock) {
await channel.shadowBan(toBlockUserId, {
banned_by_id: fromUserId,
reason: "You have blocked this user.",
});
} else {
await channel.removeShadowBan(toBlockUserId);
}
}
);
However, doing so, the user is completely being shadow banned from all the channels and not from the only single intended channel.
The stream chat node js package I'm using is "stream-chat": "^8.6.0"
I can confirm it happening on a similar scenario:
I have a channel with two users. When I receive a message from another user and hold it to press "block user" on the actions menu, it triggers a ban user method instead (and not a block user which should only affect my own user), which fails because I, as a user/channel_member role, don't have permission to ban the user. 🤔
@vanGalilea any updates? This is blocking deployment of my app.
@OutdatedGuy have you tried using it without passing the banned_by_id or the reason prop?
I ask this because I'm using the same shadowBan here, client-side:
To shadowban: await channel?.shadowBan(userId, {})
To remove shadowban: await channel?.unbanUser(userId)
And in my case it only blocks the user from that particular 1on1 channel. If this user is blocked from a 1on1 channel with another user, it can still send messages to other chats with other users.
Yo @carolinaknoll, on the server side method, passing banned_by_id is mandatory, reason is optional and removing it doesn't change anything.
I'm using Flutter on the client side and it is not allowed to shadow ban users from client side.