UIKIt Channel and User Filters

I am looking at UIKit samples and need to be able to filter group channels by custom type (actually would prefer to filter by meta data key and value, but looks like that only supports filter by key and not filter by both key and value). Also I have a user filter case as well.

This is a specific example in iOS that I am attempting, but I also need to be able to do the same in Android and also on the web site.

1. Filter Group Channels by Custom Type:

In iOS, I want to present a SBUChannelListViewController and update the channelListQuery SBDGroupChannelListQuery to provide the filtered list when the view controller appears. However, it seems that that functionality is not exposed. Meaning I don’t see how I can modify the query by either making a series of method calls or deriving a new class based on SBUChannelListViewController to override functionality.

This is to support the scenario where our users belong to one or more communities and the user will have a specific community selected in our app. So when a user is pulling up the chat for the current community, I need to make sure group channels returned for the user are also group channels in a specific community (custom type).

2. Filter Users

When a user wants to create a new conversation, I want to be able to provide a list of users with multiple sections. The example of sections I am using are: 1) Admins, 2) Friends, 3) Others. Is this possible in UIKit to be able to provide a custom sectioned contact list? Also I would also be applying the currently selected community that the connected chat user is in when gathering the possible chat contacts to create a conversation with.

2 Likes

@Eric

Would this guide help?

How to filter channel using custom-type - External.pdf (204.2 KB)

Hi, I am Android developer for UIKit.

  1. We provide custom type as a List of String. I think you can define your type for group channel as each strings.

  2. I am sorry that I didn’t understand what community means. We don’t support the relationship among users yet. I think you can build the relationship of users in your applications and apply this to your custom views. You can check the Android custom sample below link.
    https://github.com/sendbird/SendBird-Android/tree/master/uikit/uikit-custom-sample

Thanks, I read the guide you posted and it is the concept I am attempting to do in iOS, Android UIKit. I am looking at iOS currently and do not see how I can modify the search query in the SBUChannelListViewController.

There is an instance variable, channelListQuery, that I would like to be able to override as the default query by adding 1 additional criteria which is the custom type. So far I do not see an interface for being able to modify the query. Also I would like this filter to always be applied when I use that viewcontroller.

Thank you for the Android resources. I should add that I am also using Xamarin and so far have not created a binding library successfully for Android UIKit. So I have not been able to test the scenario on Android yet.

I have been able to create a Xamarin binding to a proxy library on iOS, and so I am able to attempt the custom filter on iOS. However, I have become stuck in not seeing a way to apply the channel type filter in iOS UIKit because the variable I need is not exposed. Am I missing some other method call that I need? Can you recommend a specific code sample that shows applying a filter on channel type in iOS UIKit. This is what I am trying to do:

  1. Create a SBUChannelListViewController instance
  2. Set the custom channel type filter
  3. Present or Push the created SBUChannelListViewController
  4. Verify that the created SBUChannelListViewController is now presented and the group channels returned are the expected channels of the custom type

@eric.kim

Is what I am attempting to do possible in UIKit currently? I want to use UIKit so I can avoid building layouts and UIKit looks to have all the layouts I need.

The only change I need to make aside from adjusting the styles is to add a custom type group channel filter to the channelListQuery. When I look at the SDK, I can see how to do this to get a list of group channels filtered by custom channel type for my user. However, when I attempt to do this in UIKit, it looks like the functionality I need exists and is named channelListQuery, but that I cannot access that variable and attempt to modify the default group channel list returned. My goal is to verify if this is possible with UIKit on iOS, Android, and Web.

We have a DB where we define the relationships between users and communities and we can assign the communities as custom group channels in SendBird. Then we will be able to use the functionality we have defined by simply adding the custom group channel type to the channel list queries so that whenever a user gets a list of channels, it will filter by the custom group channel that we will store on our side. Also when we create a group channel we will assign this custom channel type at that time.

So in summary, I want to use UIKit but need to always filter by a custom group channel type. There will be no cases where I need to return all of a user’s group channels. Instead, I will only return a filtered custom group channel list that I will maintain on my side (I will just need to be able to pass in the CurrentGroupChannelType filter string in order to get the list of group channels I need for the logged in user.

Thanks

Hello @Eric, sorry for the late checking!

I will answer about 4 things. And I’d like to ask you about the parts that need additional confirmation.

  1. Create a SBUChannelListViewController instance

    • Check out this function in the sample.
    • /Customize/Manager/Features/ChannelListCustomManager.swift -> func listQueryCustom()
  2. Set the custom channel type filter

    • Check out this function in the sample.
    • /Customize/Manager/Features/ChannelListCustomManager.swift -> func listQueryCustom()
    • When initializing SBUChannelListViewController in this function, set the customTypesFilter in the listQuery.
      • e,g listQuery?.customTypesFilter = [YOUR_TYPES]
  3. Present or Push the created SBUChannelListViewController

    • Check out this function in the sample.
    • /Customize/Manager/Features/ChannelListCustomManager.swift -> func functionOverridingCustom()
  4. Verify that the created SBUChannelListViewController is now presented and the group channels returned are the expected channels of the custom type

    • Can you explain it in more detail?
  • And last, please check this code for a sample of filter users.
    • /Customize/Manager/Features/InviteUserCustomManager.swift -> func userListCustom()
    • You can use the user list filtered directly when initializing SBUInviteUserViewController.
    • Unfortunately, SBUInviteUserViewController does not support query customizing.

This is the UIKit iOS sample GitHub link.

Please feel free to mention me if you need additional questions or more information!

2 Likes

Hi Eric, I am from React/JS team

As far as I understand, you have 2 use cases

1. Filter Group Channels by Custom Type:

“…our users belong to one or more communities and the user will have a specific community selected in our app. So when a user is pulling up the chat for the current community, I need to make sure group channels returned for the user are also group channels in a specific community (custom type).”

I think this is possible with some tweaking, let me get back to you with a sample for this

2. Filter Users

When a user wants to create a new conversation, I want to be able to provide a list of users with multiple sections

This case, I think might not be possible to support by default, you might have to create your own component to do this

Anyways, let me get back to you with samples in codesandbox(might take 1-2 days)
I hope its not confusing that many people are replying you at the sametime :frowning_face:

1 Like

For Android, How to implement custom channel type creation, query.

  1. You can create a channel with params. Please refer to CustomCreateChannelFragment class in our sample code
    @Override
    protected void onBeforeCreateGroupChannel(@NonNull GroupChannelParams params) {
        super.onBeforeCreateGroupChannel(params);
        params.addUserIds(userIds)
                .setCustomType("your type");
    }
  1. You can query your custom type channel. Please refer to CustomChannelListActivity class in our sample code
    @Override
    protected ChannelListFragment createChannelListFragment() {
        GroupChannelListQuery groupChannelListQuery = GroupChannel.createMyGroupChannelListQuery();
        groupChannelListQuery.setCustomTypesFilter(yourTypeList);

    return new ChannelListFragment.Builder(R.style.CustomChannelListStyle)
            .setGroupChannelListQuery(groupChannelListQuery)
            .build();
    }

If you want to set your custom user list, please refer to BaseApplication.getCustomUserListQuery() in our custom sample.

1 Like

@Tez
Thank you, that is what I was looking for. I seemed to have not had that exact version of the sample where the the query filter was exposed. I was able to update and verify I have the latest and used the strings you referenced to locate those examples.

@Doo_Rim
Thank you that is the Android sample that I was looking for. I am working through iOS first and then will try your example and let you know if I have any problems.

1 Like

@Sravan_S
Thank you for checking on examples for me. I am prepared to make some modifications if needed, but I would also prefer to implement the way you recommend so that I can apply updates more easily. No problem if it takes a couple days to get back to me. I will be testing iOS and Android in the meantime.

Sorry I had to make a second post in order to mention more than two people.

@Tez

I was able to successfully filter my group channel list by channel type following your example in my app.

I revisited your sample app from: https://github.com/sendbird/UIKit-iOS-Swift , and ran into some build errors after following the instructions listed. Previously I had run your sample, but I must have been on an older version. So I have been unsuccessful attempting to build the latest sample.

Now I have confirmed to have:

  • SendBirdSDK (3.0.195)
  • SendBirdUIKit (1.1.2):
  • COCOAPODS: 1.7.5
  • Xcode Version 11.3.1 (11C504).

I had errors described in this section: Unknown attribute error handling. After making the pre-action build script, I have the following 5 remaining build errors.

SendBirdUIKit-Sample Group

Swift Compiler Error Group

/SB.iOS/SendBirdUIKit-Sample/Customize/Manager/Features/ChannelListCustomManager.swift:58:45: Cannot invoke initializer for type ‘CustomChannelListCell’ with no arguments

/SB.iOS/SendBirdUIKit-Sample/Customize/Manager/Features/ChannelListCustomManager.swift:58:45: Overloads for ‘CustomChannelListCell’ exist with these partially matching parameter lists: (coder: NSCoder), (style: UITableViewCell.CellStyle, reuseIdentifier: String?)

/SB.iOS/SendBirdUIKit-Sample/Customize/Manager/Features/ChannelCustomManager.swift:48:59: Missing argument for parameter ‘frame’ in call

/SB.iOS/SendBirdUIKit-Sample/Customize/View/Channel/SubView/CustomNewMessageInfo.swift:12:47: ‘init(frame:)’ declared here

/SB.iOS/SendBirdUIKit-Sample/Customize/Manager/Features/ChannelCustomManager.swift:52:45: Missing argument for parameter ‘frame’ in call

/SB.iOS/SendBirdUIKit-Sample/Customize/View/Common/CustomEmptyView.swift:14:14: ‘init(frame:)’ declared here

/SB.iOS/SendBirdUIKit-Sample/Customize/Manager/Features/ChannelCustomManager.swift:91:49: Cannot invoke initializer for type ‘CustomUserMessageCell’ with no arguments

/SB.iOS/SendBirdUIKit-Sample/Customize/Manager/Features/ChannelCustomManager.swift:91:49: Overloads for ‘CustomUserMessageCell’ exist with these partially matching parameter lists: (coder: NSCoder), (style: UITableViewCell.CellStyle, reuseIdentifier: String?)

/SB.iOS/SendBirdUIKit-Sample/Customize/Manager/Features/ChannelListCustomManager.swift:46:41: Missing argument for parameter ‘frame’ in call

Please let me know if there is something I am missing. My goal is to build your latest ios sample app.

Thanks

1 Like

Hi @Eric!

The problem you have reported is the problem related to the initializer in Swift5.1 and earlier versions. There has been a change in the initializer in Apple since Swift5.2 version.
But I think that’s a problem that can happen to other developers, too.
So, the problem that occurred in the lower version was fixed and updated quickly thanks to your report! Thank you for finding the problem.

Please update the sample project and retest it. :smiley:

Thanks @Tez!

I was able to update and run the sample.

I did get a link error when building:

ld: library not found for -lPods-SendBirdUIKit-Sample

So I removed that framework reference and was able to launch the app. I am now testing the sample features.

Thanks