Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to shadowBan or Ban user from a specific channel #1121

Open
OutdatedGuy opened this issue May 8, 2023 · 4 comments
Open

Unable to shadowBan or Ban user from a specific channel #1121

OutdatedGuy opened this issue May 8, 2023 · 4 comments
Labels
Backend Team The backend team is in charge of this issue

Comments

@OutdatedGuy
Copy link

OutdatedGuy commented May 8, 2023

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"

@vanGalilea vanGalilea added the Backend Team The backend team is in charge of this issue label May 11, 2023
@carolinaknoll
Copy link

carolinaknoll commented May 22, 2023

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. 🤔

@OutdatedGuy
Copy link
Author

@vanGalilea any updates? This is blocking deployment of my app.

@carolinaknoll
Copy link

carolinaknoll commented May 30, 2023

@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.

@OutdatedGuy
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Team The backend team is in charge of this issue
Projects
None yet
Development

No branches or pull requests

3 participants