stream-chat-js
stream-chat-js copied to clipboard
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"