GetStream / stream-chat-swift

💬 iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
https://getstream.io/chat/sdk/ios/
Other
856 stars 209 forks source link

ChatChannelListVC doesn't properly filter channels #1484

Closed srgray closed 3 years ago

srgray commented 3 years ago

What did you do?

Attempt to display ChatChannelListVC for only .messaging channels of which my user is a member

What did you expect to happen?

Only .messaging channels that my user is a member of should be displayed

What happened instead?

ChatChannelListVC displays some channels that are .livestream type

GetStream Environment

GetStream Chat version: 4.0.1 GetStream Chat frameworks: StreamChat, StreamChatUI

Additional context

See attached sample project: StreamChannelList.zip

Steps to reproduce:

tbarbugli commented 3 years ago

thank you for sharing this, looks like the relevant bits of code is

private lazy var chatChannelListVC: CNChatChannelListVC = {
        let chatChannelsVC = CNChatChannelListVC()
        let userIds = [userId] //show channels that have me in them
        let channelListController = ChatClient.shared
            .channelListController(
                query: ChannelListQuery(
                    filter: Filter.and([
                        .containMembers(userIds: userIds),
                        .equal(.type, to: .messaging)
                    ])
                )
            )
        chatChannelsVC.controller = channelListController
        return chatChannelsVC
    }()

which looks correct, we are looking into it

tbarbugli commented 3 years ago

quick update, the ChannelListQuery you use creates the right JSON payload:

{"limit":20,"watch":true,"message_limit":25,"filter_conditions":{"$and":[{"members":{"$in":["a","b"]}},{"type":{"$eq":"messaging"}}]}}

more digging required

b-onc commented 3 years ago

Hello @srgray ,

This happens because of the recent API we introduced in PR #1460 Basically,

  1. There exists a controller which observes channels for type messaging, let's call it messagingController
  2. You query channels for type livestream, you get livestream channels saved to DB
  3. messagingController gets callback shouldListNewChannel for these channels, and default answer is true
  4. messagingController lists these channels

You should implement the delegate callback shouldListNewChannel and return false for non-messaging channels

We're aware this is not ideal and looking for ways to improve this.

srgray commented 3 years ago

Hi @b-onc ,

Thanks for the suggested work-around. I am not able to get my delegate callback to fire, it is only using the default implementation declared in the protocol extension. Can you take a quick look and let me know if I am doing something wrong? StreamChannelListDelegateWorkaround.zip

b-onc commented 3 years ago

Hello @srgray , Thanks a lot for the sample project, it helped tremendously. There are 2 issues, 1 comes from user error and 1 comes from SDK User Error: You assign ViewController as delegate to ChannelListController, but ChannelListVC assigns itself as delegate, overriding yours. Your implementations won't be called. SDK Error: You can't override delegate methods in your ChannelListVC subclass because ChannelListVC doesn't implement them.

I'll PR the fix for SDK error shortly and then you'll be able to override delegate methods in your ChannelListVC subclass and return false for type != .messaging channels.