stream-chat-react icon indicating copy to clipboard operation
stream-chat-react copied to clipboard

Setting the custom searchFunction to get only channels for Channel List

Open shakogele opened this issue 5 years ago • 7 comments

Hello

Setting the custom searchFunction to get only channels for Channel List is not showing up as expected. This is my ChannelList component

<ChannelList
  filters={filters}
  sort={sort}
  showChannelSearch
  additionalChannelSearchProps={{
    searchForChannels: true,
    searchFunction: async (ChannelSearchFunctionParams, event) => {
      ChannelSearchFunctionParams.setQuery(event.target.value);
      const channels = await chatClient.queryChannels(filters, sort);
      ChannelSearchFunctionParams.setResults(channels);
    },
  }}
  List={ChannelListMessenger}
  customActiveChannel={memberChannelId}
/>

and his is what I get after dispatching all channels

Screenshot 2021-08-19 at 17 01 27

I have no idea why it shows up like this?

shakogele avatar Aug 19 '21 15:08 shakogele

Hello! Thanks for writing in. Excellent use of writing your own search function for the input.

By default, a search result in the dropdown list for channels displays the channel name, which is optional. Do your channels have names? That could be the issue. I'd suggest creating your own SearchResultItem component that will handle the display of your channel results (maybe the id or members if no name?) and pass it in into your additionalChannelSearchProps. See the Channel Search guide in our documentation that outlines several customization options including how to use a custom result item component. I believe that should help so I'm going to close this issue, but if you find that's not the issue then please reach back out. Thanks!

ambaldwin avatar Aug 19 '21 16:08 ambaldwin

@ambaldwin if I stick with the default channel search functionality that getStream provides out of the box, then it displays the channel names as expected (by using the showChannelSearch with no custom searchFunction), but the problem occurs when I use chatClient.queryChannels - the strange thing is that I've implemented the customDropdown component but no names are visible there as well.

shakogele avatar Aug 22 '21 22:08 shakogele

@ambaldwin also you asked whether my channels contain names, As I checked the result that is returned from chatClient.queryChannels contains channel objects which does not contain channel names. And I have no idea why, can you explain to me?

shakogele avatar Aug 22 '21 22:08 shakogele

The channels returned do not contain names in the data object? so, if you log channel.data, let me know what you see.

Also, in your custom implementation of a CustomDropdown component, are you using a custom SearchResultItem as well? If not, then it will use the default, and this is the component that will display names only if there is one.

Note that the searchFunction's second argument is the event, so a query might look like this:

const channelResponse = await chatClient.queryChannels(
          {
            name: { $autocomplete: event.target.value },
            members: { $in: [userId] }
          },
 );

ambaldwin avatar Aug 23 '21 17:08 ambaldwin

this is how the channel object looks like:

Screenshot 2021-08-23 at 20 52 37

shakogele avatar Aug 23 '21 18:08 shakogele

@ambaldwin thanks for your reply. I know that your code should work but it does not work for me. I am even doing this:

const channelResponse = await chatClient.queryChannels(
          {
            name: { $autocomplete: 'John' },
          },
);

without passing members filter, but it still returns an empty result (I am pretty sure that the result set contains user/channel with a name John.) So maybe it is something that is related with permissions or chat configuration?

shako1988 avatar Aug 24 '21 20:08 shako1988

Hello, I apologize for the delay - Are you still having issues? Let's try to trouble-shoot - you say you see the channel names if you use the default search function instead of providing your own. Can you send a screenshot of the logs of these channel objects with the names and/or a screenshot of the dropdown menu where you're seeing the names displayed?

ambaldwin avatar Aug 31 '21 19:08 ambaldwin