pusher / chatkit-server-node

Node.js SDK for Pusher Chatkit
https://pusher.com/chatkit
MIT License
16 stars 9 forks source link

getRooms members_list data is always null / different to user.getRooms #40

Closed dcsan closed 5 years ago

dcsan commented 5 years ago

What?

I'm using a query getRooms https://docs.pusher.com/chatkit/reference/server-node#get-rooms

this shows every room has an empty member_user_ids but when I iterate through the users, with getUserRooms it shows different info.

This is after using your console, and also trying manually to add users to rooms.

Suggested improvements

If a user is in a room, then they should show up in that room when using the API to check room info.

for all rooms you can see the 'lobby' is supposedly empty:

  Rabbit all rooms=> [ { created_at: '2019-01-28T06:31:30Z',
    created_by_id: 'dcsan',
    id: '19398582',
    member_user_ids: null,
    name: 'lobby',
    private: false,
    updated_at: '2019-01-28T06:31:30Z' },
  { created_at: '2019-02-15T07:13:27Z',
    created_by_id: 'genie',
    id: '19408194',
    member_user_ids: null,
    name: 'testing',
    private: false,
    updated_at: '2019-02-15T07:13:27Z' },
  { created_at: '2019-02-15T07:17:03Z',
    created_by_id: 'genie',
    id: '19408196',
    member_user_ids: null,
    name: 'empty',
    private: false,
    updated_at: '2019-02-15T07:17:03Z' } ] +302ms

when using a different API and checking a user's rooms, the lobby and other rooms now have members:

  Rabbit getUserRooms result=> Promise { <pending> } +1ms
  Rabbit userStatus for userId: dcsan +1ms
  Rabbit getUserRooms.then res [ { created_at: '2019-01-28T06:31:30Z',
    created_by_id: 'dcsan',
    id: '19398582',
    member_user_ids: [ 'adminBot', 'dcsan', 'genie' ],
    name: 'lobby',
    private: false,
    updated_at: '2019-01-28T06:31:30Z' },
  { created_at: '2019-02-15T07:13:27Z',
    created_by_id: 'genie',
    id: '19408194',
    member_user_ids: [ 'dcsan', 'genie' ],
    name: 'testing',
    private: false,
    updated_at: '2019-02-15T07:13:27Z' },
  { created_at: '2019-02-15T07:17:03Z',
    created_by_id: 'genie',
    id: '19408196',
    member_user_ids: [ 'dcsan', 'genie' ],
    name: 'empty',
    private: false,
    updated_at: '2019-02-15T07:17:03Z' },
  { created_at: '2019-02-15T07:17:10Z',
    created_by_id: 'genie',
    id: '19408197',
    member_user_ids: [ 'genie' ],
    name: 'private',
    private: true,
    updated_at: '2019-02-15T07:17:10Z' } ] +300ms

because of #39 I also tried it both ways:

  static async status(userId = 'genie') {
    let allRooms = await Rabbit.chatkit.getRooms({})
    debug.info('all rooms=>', allRooms)

    Rabbit.chatkit.getRooms({})
      .then(allRooms => {
        debug.info('all rooms=>', allRooms)
      })
  }

Is there some weird options to the chatkit.getRooms({}) that somehow masks the users in that room?

FWIW I am connecting like this (in my own Class wrapper) It seems to accept a userId like the client lib, but this does not have any effect.

  static async connect() {

    Rabbit.chatkit = await new Chatkit.default({
      instanceLocator: ChatkitConfig.INSTANCE_LOCATOR,
      // userId: userId,
      key: ChatkitConfig.SECRET_KEY
    })
    debug.info('init done')
  }

Basically seems that getRooms is not checking and lying on members, always null. This is a simple bug to fix I guess.

eliasbaixas commented 5 years ago

We've hit this bug too, and its pretty annoying, is it going to get fixed ? ETA ?

dearsina commented 5 years ago

I am using the PHP SDK, and I'm hitting the same bug. I thought it was because the rooms were private, but I can see from your dumps that it seems to affect all types of rooms. Please keep me posted on any updates.

I started implementing Chatkit and Channels only a few days ago, and I just wanted to say a big thank you to Pusher for a pretty solid product with very helpful documentation.

callum-oakley commented 5 years ago

This behaviour actually is by design, though I'm the first to admit it makes more sense from the perspective of the client SDK than from the server SDK.

On the client, you can't see the members of a room unless you yourself are a member of the room, so getting a room from the context of a user (getUserRooms) shows you the memberships, but getting all rooms irrespective of memberships (getRooms) does not. However, from the perspective of the server SDK this distinction does seem a little pointless. I'll bring this up internally as a feature request. Thanks for bringing it to our attention!

Closing this issue because this is a feature request against the API, not an issue with the node SDK specifically.

dcsan commented 5 years ago

haha, so there is method to the madness!

GlebkaF commented 5 years ago

Hey guys, what's new with member_user_ids always null issue?

dcsan commented 5 years ago

@GlebkaF they said above it's by design... confusing though.

but @callum-oakley in that case it would be better to return a descriptive error message like not_a_member somewhere?

GlebkaF commented 5 years ago

How can i get rooms list with members via nodejs-sdk? I end up with this solution, but it's horrible:

const roomsWithMembers = Promise.all(chatkit.getRooms(...).map(({ id } ) => chatkit.getRoom({ roomId: id}))