mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-09-08 12:22:11 +00:00
Add RoomMemberStore.get_users_in_room, so that we can get the list of joined users without having to retrieve the full events
This commit is contained in:
parent
96a5ba41f5
commit
f0128f9600
@ -245,14 +245,12 @@ class RoomMemberHandler(BaseHandler):
|
||||
self.distributor.declare("user_left_room")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_room_members(self, room_id, membership=Membership.JOIN):
|
||||
def get_room_members(self, room_id):
|
||||
hs = self.hs
|
||||
|
||||
memberships = yield self.store.get_room_members(
|
||||
room_id=room_id, membership=membership
|
||||
)
|
||||
users = yield self.store.get_users_in_room(room_id)
|
||||
|
||||
defer.returnValue([hs.parse_userid(m.user_id) for m in memberships])
|
||||
defer.returnValue([hs.parse_userid(u) for u in users])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def fetch_room_distributions_into(self, room_id, localusers=None,
|
||||
@ -531,11 +529,10 @@ class RoomListHandler(BaseHandler):
|
||||
def get_public_room_list(self):
|
||||
chunk = yield self.store.get_rooms(is_public=True)
|
||||
for room in chunk:
|
||||
joined_members = yield self.store.get_room_members(
|
||||
joined_users = yield self.store.get_users_in_room(
|
||||
room_id=room["room_id"],
|
||||
membership=Membership.JOIN
|
||||
)
|
||||
room["num_joined_members"] = len(joined_members)
|
||||
room["num_joined_members"] = len(joined_users)
|
||||
# FIXME (erikj): START is no longer a valid value
|
||||
defer.returnValue({"start": "START", "end": "END", "chunk": chunk})
|
||||
|
||||
|
@ -123,6 +123,19 @@ class RoomMemberStore(SQLBaseStore):
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_users_in_room(self, room_id):
|
||||
def f(txn):
|
||||
sql = (
|
||||
"SELECT m.user_id FROM room_memberships as m"
|
||||
" INNER JOIN current_state_events as c"
|
||||
" ON m.event_id = c.event_id"
|
||||
" WHERE m.membership = ? AND m.room_id = ?"
|
||||
)
|
||||
|
||||
txn.execute(sql, (Membership.JOIN, room_id))
|
||||
return [r[0] for r in txn.fetchall()]
|
||||
return self.runInteraction("get_users_in_room", f)
|
||||
|
||||
def get_room_members(self, room_id, membership=None):
|
||||
"""Retrieve the current room member list for a room.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user