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

Filtering channels does not work #2594

Open
AGSTRANGER opened this issue Dec 27, 2024 · 0 comments
Open

Filtering channels does not work #2594

AGSTRANGER opened this issue Dec 27, 2024 · 0 comments
Labels
bug Something isn't working status: unconfirmed

Comments

@AGSTRANGER
Copy link

AGSTRANGER commented Dec 27, 2024

Describe the bug

Filtering channels does not work. The user is able to send a message to all users by typing their names in the channels filter.

To Reproduce
<ChannelList filters={{ type: "messaging", members: { $in: [connectedUserData._id] }, }} showChannelSearch options={{ state: true, presence: true, limit: 8 }} sort={{ last_message_at: -1 }} additionalChannelSearchProps={{ searchForChannels: true, searchQueryParams: { channelFilters: { filters: { members: { $in: [connectedUserData._id] } }, }, }, }} Preview={ChannelPreviewCustom} />

Steps to reproduce the behavior:

  1. Type a letter in the channels filter
  2. You will see all users that have the letter in their names

Expected behavior

Only see channels the user is already a part of. In other words, only existing conversations that the user have.

Screenshots

image

I don't have a conversation with Ali. I shouldn't be able to see him when I type his name in the channels filter.

image

Additional context
In my app, a user has connections. So when he tries to send a message, he can only send a message to his connection. I have implemented this successfully like this:

`
useEffect(() => {
const fetchUsers = async () => {
if (!connectedUserData) {
setFetchError("Connected user data is not available");
return;
}

  setIsFetching(true);
  setFetchError(null);

  try {
    const response = await client.queryUsers(
      {
        $and: [
          { id: { $ne: connectedUserData._id } }, 
          { id: { $in: connectedUserData.connections.map(user => user) } }, 
        ],
        role: { $ne: "admin" },
        ...(searchInputDebounced
          ? {
              $or: [
                { name: { $autocomplete: searchInputDebounced } },
                { username: { $autocomplete: searchInputDebounced } },
              ],
            }
          : {}),
      },
      { name: 1, username: 1 },
      { limit: 15 }
    );
    setUsers(response.users);
  } catch (error) {
    console.error("Error fetching users", error);
    setFetchError("An error occurred while loading users.");
  } finally {
    setIsFetching(false);
  }
};

if (searchInputDebounced) {
  fetchUsers();
} else {
  setUsers([]); // Clear users when search input is empty
}

}, [searchInputDebounced, connectedUserData, client]);
`

I tried the same thing with filtering channels but it didn't work.
<ChannelList filters={{ type: "messaging", members:{ $and: [ { members: { $in: connectedUserData.connections.map(user => user)} }, // Existing condition:connectedUserData._idis inmembers{ id: { $ne: connectedUserData._id } }, // New condition:idis not equal toconnectedUserData._id], }, }} showChannelSearch options={{ state: true, presence: true, limit: 8 }} sort={{ last_message_at: -1 }} additionalChannelSearchProps={{ searchForChannels: true, searchQueryParams: { channelFilters: { filters: { $and: [ { members: { $in: connectedUserData.connections.map(user => user)} }, // Existing condition:connectedUserData._idis inmembers{ id: { $ne: connectedUserData._id } }, // New condition:idis not equal toconnectedUserData._id ], }, }, }, }} Preview={ChannelPreviewCustom} />

So I also I tried a simpler filter like the initial example I provided where I only filter by the connected user id but it did not work.
(While writing this, I realized it's redudant to filter channels by both connected user id and his connection requests. Since the user channels can be filtered by either of them. So one is enough.)

Package version

  • stream-chat-react: ^11.23.0
  • stream-chat ^8.37.0:
@AGSTRANGER AGSTRANGER added bug Something isn't working status: unconfirmed labels Dec 27, 2024
@AGSTRANGER AGSTRANGER changed the title bug: Filtering channels does not work Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status: unconfirmed
Projects
None yet
Development

No branches or pull requests

1 participant