Error Code 429; Too Many Requests in Streamchat SDK for SwiftUI

21 Views Asked by At

I am trying to implement chat in SwiftUI with Stream's SDK. Unfortunately I am facing too many request issue. I contacted Stream but they didn't respond.

Code:

struct ChatListView: View {

    let network: ChatNetworkModel
    let programID: String

    @State var chatController: ChatChannelListController?

    var body: some View {
        VStack {
            if let chatController {
                ChatChannelListView(
                    viewFactory: DefaultChatsListViewFactory(chatClient: StreamChatViewModel.shared.client),
                    channelListController: chatController,
                    embedInNavigationView: false
                )
            } else {
                Spacer()
                ProgressView()
                Spacer()
            }
        }
        .onAppear() {
            if let controller = StreamChatViewModel.shared.channelListController(withNetworkId: network.id, withProgramId: programID, isArchived: false) {
                controller.synchronize { error in
                    if let _ = error {
                        showError = true
                    } else {
                        self.chatController = controller
                    }
                }
            }
        }
    }

}

class StreamChatViewModel ... {
    func channelListController(withNetworkId networkId: String, withProgramId programID: String, isArchived: Bool?) -> ChatChannelListController? {
        guard let id = client.currentUserId else { return nil }
        
        let filters: [Filter<ChannelListFilterScope>] = [
            .and([
                .equal(.type, to: .messaging),
                .containMembers(userIds: [id]),
                .in(.init(rawValue: "channel_type"), values: ["normal"]),
                .in(.init(rawValue: "programUuid"), values: [programID]),
                .in(.init(rawValue: "networkId"), values: [networkId]),
                .notIn(.init(rawValue: "channel_type"), values: ["program_admin_channel", "program_admin_one_to_one"])
            ])
        ]
        
        let controller = client.channelListController(query: .init( filter: .and(filters)))
        return controller
    }
}

Chat shows up but can't interact with it since it's internally crashed due to too many request error with error code 429.

0

There are 0 best solutions below