GetStream / stream-chat-php

Stream Chat official PHP API Client
https://getstream.io/chat/
BSD 3-Clause "New" or "Revised" License
30 stars 9 forks source link

How to get all banned users per channel? #15

Closed alucic closed 3 years ago

alucic commented 4 years ago

I have a channel that's using livestream default channel type

  1. I have successfully banned a user from the channel X ✅
  2. Banned user can't send messages SendMessage failed with error: "Sorry, you do not have access to this feature. Your account is currently suspended from chat." ✅

After a live stream is done I'd like to revisit my bans and unban some users if needed. I've tried using queryChannels API endpoint but:

  1. queryChannels shows only current members, is there a way to get past members?
  2. queryChannel response doesn't reflect the current banned state for a member. Banned user who can't send messages is having banned => false inside channel's members key

What would be the best way to get all banned users for a channel?

Thanks!

Rajat117 commented 4 years ago

Same Concern Here

alucic commented 4 years ago

@pterk could you assist here? Thanks

pterk commented 4 years ago

Bans are global. You can user queryUsers to find all banned users:

$client->queryUsers(["banned" => true]);
alucic commented 4 years ago

Hi @pterk , I double checked the docs https://getstream.io/chat/docs_rest/#ban-user and it seems there are two types of bans, channel and app level bans.

POST /moderation/ban Bans a user from a channel or entirely.

In my case, I can successfully ban a user from a single channel, that user can still post to other channels. That is wanted behavior ✅

I'm still not able to get a list of banned users, for a channel or "entirely".

I've tried getting banned users using "user query" and "channel query" here are the examples:

Getting global bans Request

$client->queryUsers(["banned" => true]);

Response

[
  "users" => [] <<--- should this contain a banned user from the app and/or channels?
  "duration" => "12.76ms"
]

Getting channel data Request

$channel = $client->Channel('livestream', $id, new \stdClass());

$channel->query([]);

Response members key is empty, the only place where I see users in messages key

 "messages" => array:1 [
    0 => array:14 [
      "id" => "messageID"
      "text" => "a"
      "html" => "<p>a</p>\n"
      "type" => "regular"
      "user" => array:9 [
        "id" => "Banned User ID"
        "role" => "user"
        "created_at" => "2020-01-04T20:00:00.00000Z"
        "updated_at" => "2020-01-04T20:00:00.00000Z"
        "last_active" => "2020-01-04T20:00:00.00000Z"
        "banned" => false   << ------- This should be true, since this user can't post
        "online" => true
        "image" => "image"
        "name" => "User Name"
      ]

This is a live streaming use case I'm trying to solve:

  1. you start a live stream, and you get a brand new channel
  2. you ban X users
  3. you start a new live stream, and you get a brand new channel

In step 3, I'd like to ban all users that were banned in step 2 so they don't have access to my new channel.

A workaround would be to have a single channel, so there's no need to create a new channel, but in that case, and truncate it before a new stream starts. But, we would like to have access to old messages when the stream ends.

Thank you

alucic commented 4 years ago

Query by id and banned = true returns []

$banned = $client->queryUsers( 
[ 
  'id' => 'bob-1',
  'banned' => true,
]);              

Query just by id

$user = $client->queryUsers( 
[ 
  'id' => 'bob-1',
]);

Returns user info and mutes. "banned" => false which explains the first query returning []

pterk commented 4 years ago

@alucic AFAICT the banned filter works w/ the latest version.

I checked w/ the chat-team: """ its possible to ban in the scope of a channel. but currently there is no way to know/query if a certain user is banned from a channel its still possible to query for global bans using queryUsers """

I also heard on the grapevine that an upcoming feature will allow to filter at the channel level. I don't know an ETA though.

Rajat117 commented 4 years ago

Is there a way we could also get all the flag messages from the channel?

ferhatelmas commented 3 years ago

@alucic Query members is for channel level: $banned = $channel->queryMembers(['banned' => true]);

@Rajat117 not at the moment, please check with support for it later because it's related to API than SDK.