Skip to content

Commit

Permalink
gitter: Fix occupants for GitterRoom
Browse files Browse the repository at this point in the history
The limit parameter was not used which defaults to 30
and returns maximum 100 users at a time. Hence, it fails
to return all the members in the room.
In order to tackle this, we need to iterate by skipping
100 members with every API request. Also users count
needs to be updated everytime list of occupants is
requested as new users may join a room in realtime.

Closes errbotio#38
  • Loading branch information
nvzard committed Mar 12, 2019
1 parent 14a428b commit 0d5c095
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions gitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,22 @@ def topic(self):
else:
raise RoomNotFoundError("Cannot find the room '{}'".format(self.uri))

def _user_count(self):
json_rooms = self._backend.readAPIRequest('rooms')
for json_room in json_rooms:
if json_room['id'] is self.idd:
return json_room['userCount']

@property
def occupants(self):
occupants = []
json_users = self._backend.readAPIRequest('rooms/%s/users' % self._idd)
for json_user in json_users:
occupants.append(GitterRoomOccupant.build_from_json(self, json_user))
user_count = self._user_count()
for skip in range(0, user_count, 100):
# 100 is the maximum number of users Gitter API can return.
json_users = self._backend.readAPIRequest(
'rooms/%s/users?skip={}?limit={}'.format(self.idd, skip, 100))
for json_user in json_users:
occupants.append(GitterRoomOccupant.build_from_json(self, json_user))
return occupants

def __eq_(self, other):
Expand Down

0 comments on commit 0d5c095

Please sign in to comment.