2

I am trying to fetch all channels of a user(channel of which that user is a member). So, I got to know about this :

        const filter = {
            type: 'messaging',
            members: { $in: [`${req.body.id}`] },
        };
        const sort = { last_message_at: -1 };
        const channelList = await client.queryChannels(filter, sort, {
            watch: true,
            state: true,
        });

, by sending current user id as req.body.id.I have made a separate function for it. And when the user enters that page, I need to call that function. But when I am doing this, I am getting this error as a response :

"StreamChat error code 4: QueryChannels failed with error: "Watch or Presence requires an active websocket connection, please make sure to include your websocket connection_id"

Please suggest whether I am doing anything wrong to fulfill this task or what I am doing wrong here.

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
Harshita
  • 372
  • 4
  • 16
  • 1
    You need to call `connect` on `client` which will take you to a setting user via `setUser` because you want channel events with `watch: true`. – ferhatelmas Apr 20 '20 at 11:05

1 Answers1

4

It looks like you are sending watch: true to queryChannels but setUser was not called or did not complete yet.

To fix this: call await client.setUser({id}) and wait for its completion (hence the await) before queryChannels.

Tommaso Barbugli
  • 11,781
  • 2
  • 42
  • 41