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

Filtering in ChannelList does not work correctly #2440

Closed ezgiozkan closed 1 year ago

ezgiozkan commented 1 year ago

Messages with the type "team" in ChatChannelListVC should not be listed. However, messages of this type continue to arrive, or messages with the type "messaging" do not appear, and the list returns empty.

func getMessageListVC(userId: String) -> ChatChannelListVC {
        let channelList = ChannelListViewController()
        let query = ChannelListQuery(filter: .and([.containMembers(userIds: [userId]), .nonEmpty, .notEqual(.type, to: .livestream), .notEqual(.type, to: .team)]))
        channelList.controller = ChatClient.shared?.channelListController(query: query)

        return channelList
    }

GetStream Environment

GetStream Chat version: 4.20.0 GetStream Chat frameworks: StreamChat, StreamChatUI Xcode version: 13.4.1

polqf commented 1 year ago

Hi @ezgiozkan,

Are you probably having 2 channel lists active at the same time? Please check the documentation and use the filter block: https://getstream.io/chat/docs/sdk/ios/client/controllers/channels/#2-create-a-controller

nuno-vieira commented 1 year ago

Closing the issue for now, let us know if you still have problems when introducing the filter blocks.

Best, Nuno

ezgiozkan commented 1 year ago

I am using filtering as in the document. However, channels with .team type are displayed in the list as the message is received. The filtering process does not work correctly. I am rewriting the code I used for you to review.

let query = ChannelListQuery(filter: .and([.containMembers(userIds: [userId]), .nonEmpty, .notEqual(.type, to: .team)]))

As an extra note, the same filtering method works correctly for channels whose type is .livestream. But it doesn't work properly for channels with team type.

nuno-vieira commented 1 year ago

@ezgiozkan

The filter you are missing is in the channelController.

let controller = ChatClient.shared.channelListController(query: query, filter: { channel in
    // the filtering logic goes here.
    return !channel.messages.isEmpty && channel.lastActiveMembers.contains(userId) && channel.type != "team"
})

Something like that.

Best, Nuno