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

Channel list filter logic broken #2556

Closed Subtextaps closed 1 year ago

Subtextaps commented 1 year ago

What did you do?

When updating the SDK from 4.27.0 to 4.30.0 the channel list filter logic seems to break.

What did you expect to happen?

With 4.27.0 the following piece of code would show a channel list containing all "public" livestream channels (meaning channels that any user can watch without being a member) as well as all channels of which the user is a member.

if let chatID = self.userStatusHandler.userStatus.chatID {

            let filter = Filter<ChannelListFilterScope>
                .or(
                    [.equal(.type, to: .livestream),
                     .containMembers(userIds: [chatID])
                ]
                )

        self.channelListController = self.chatClient.channelListController(
            query: .init(filter:
                    filter)
            )

        self.channelListController?.synchronize ({ [weak self] error in
            if let error = error {
                print(error.localizedDescription)
                self?.alertContent = AlertContent(title: "Fejl", message: "Noget gik galt. Prøv at lukke appen helt og åbne igen", dismissButtonText: "Ok")
                self?.showAlert = true
                return
            }
            else {

                DispatchQueue.main.async {
                self?.channelListViewModel = ViewModelsFactory.makeChannelListViewModel(
                    channelListController: self?.channelListController)

                    self?.chatService.currentAlert = .none
                    self?.showAlert = false
                    self?.showChatIntro = false
                    self?.showChannels = true

                }
            }
        })
    }

What happened instead?

After updating only channels of which the user is a member are shown. The livestream channels of which the user is not a member are no longer shown. Sometimes the list does show all the channels in the query briefly, right after the channel list appears. But they are removed after a second or so.

GetStream Environment

GetStream Chat version: 4.30.0 GetStream Chat frameworks: StreamChat, StreamChatSwiftUI iOS version: 16.3.1 Swift version: 5.0 Xcode version: 14.3 Device: iPhone 11

Additional context

Subtextaps commented 1 year ago

If I set the filter to the following no channels are shown in the channel list even though we have multiple livestream channels set up: let filter = Filter .equal(.type, to: .livestream)

But If I do:

let filter = Filter .equal(.type, to: .messaging)

the filter works as expected and the channel list shows the messaging channels.

ipavlidakis commented 1 year ago

Hi @Subtextaps,

Thanks for reporting this. We introduced some changes for filters in 4.27.0 but there weren't any further changes in the releases after.

Just to try eliminating issue sources, you can try to disable auto-filtering in your client's configuration link:

config.isChannelAutomaticFilteringEnabled = false

and see if the problem persists.

Best, Ilias

Subtextaps commented 1 year ago

Hi Ilias,

Thanks for the suggestion. I've tried it but it doesn't seem to change anything.

I've added a short video that shows the problem. The channels coming and going in the channel list are all of the livestream type. I suspect this might be a backend issue. Did you change anything related to the livestream channel type that might cause this?

https://user-images.githubusercontent.com/10029295/229504997-1469290f-3eea-4e20-b3b3-8ddef981a101.mp4

Best,

Thomas

ipavlidakis commented 1 year ago

Hi Thomas,

There haven't been any backend changes as far as we are aware. Is there any way you can rollback to 4.27.0 and verify that the issue is not reproducible in it?

Best, Ilias

Subtextaps commented 1 year ago

Hi Ilias,

I'm getting compiler errors in your AttachmentPickerView when using 4.27.0 in combination with Xcode 14.3 which was my reason for updating to 4.30.0 in the first place. When I roll back to 4.27.0 the compiler error returns and I'm unable to build the app. Please see attached.

So right now I'm kind of stuck with 4.30.0 unless I roll back a ton of stuff.

Skærmbillede 2023-04-03 kl  14 43 37

Best,

Thomas

Subtextaps commented 1 year ago

If I step through the initialization of the channelListController I get this error a bunch of times in the Xcode console

Skærmbillede 2023-04-03 kl  15 00 39

Subtextaps commented 1 year ago

Hi Ilias,

Upon further digging I found that if I set both the query and the filter parameters of the channelListController to be identical I'm able to get the ChannelListView to return a stable list of the livestream channels.

This is not mentioned in your SwiftUI documentation (https://getstream.io/chat/docs/sdk/ios/swiftui/channel-list-components/query-filters/) so I'm wondering if this is the right way to go?

If so how would I go about filtering out the channels of which the current user is a member in the filter parameter (that is: What is identical to calling this .containMembers(userIds: [chatID] on the chatChannel instance)?

Here's the code snippet:

if let chatID = self.userStatusHandler.userStatus.chatID {

            let filter = Filter<ChannelListFilterScope>
                .equal(.type, to: .livestream)

        self.channelListController = self.chatClient.channelListController(
            query: .init(filter:
                    filter),
            filter: { chatChannel in
                chatChannel.type == .livestream

            }
            ) 
Subtextaps commented 1 year ago

I went with this and it seems to work.

Could you please have a look and let me know if this a valid and stable way to go as this is not how it's described in your SwiftUI documentation?

let filter = Filter .or( [.equal(.type, to: .livestream), .containMembers(userIds: [chatID]) ] )

        self.channelListController = self.chatClient.channelListController(
            query: .init(filter:
                    filter),
            filter: { chatChannel in
                chatChannel.type == .livestream
                ||
                chatChannel.membership?.memberRole == .member
            })
nuno-vieira commented 1 year ago

Hi @Subtextaps!

Thank you for your report! We were able to reproduce the issue and identify the root cause 👍

We will let you know once we have a fix.

In the meantime, your workaround will be fine, but your filter will work automatically without providing a filter block once we provide the fix.

Best, Nuno

nuno-vieira commented 1 year ago

Hi @Subtextaps!

The fix is already on develop and it will be available in the next release 👍

Best, Nuno

Subtextaps commented 1 year ago

Great to hear – thanks for your help with this🙏🏼

Best,

Thomas

polqf commented 1 year ago

Hi @Subtextaps, 4.31.0 is out, and contains the fix for this issue.

Let us know if you need anything else from us