Add a get_invites_for_user method to the storage to find out the rooms a user is invited to

This commit is contained in:
Mark Haines 2015-10-13 14:08:38 +01:00
parent 54414221e4
commit cacf0688c6
2 changed files with 16 additions and 6 deletions

View File

@ -297,12 +297,8 @@ class SyncHandler(BaseHandler):
if room_sync: if room_sync:
joined.append(room_sync) joined.append(room_sync)
else: else:
invites = yield self.store.get_rooms_for_user_where_membership_is( invite_events = yield self.store.get_invites_for_user(
user_id=sync_config.user.to_string(), sync_config.user.to_string()
membership_list=[Membership.INVITE],
)
invite_events = yield self.store.get_events(
[invite.event_id for invite in invites]
) )
for room_id in joined_room_ids: for room_id in joined_room_ids:

View File

@ -110,6 +110,20 @@ class RoomMemberStore(SQLBaseStore):
membership=membership, membership=membership,
).addCallback(self._get_events) ).addCallback(self._get_events)
def get_invites_for_user(self, user_id):
""" Get all the invite events for a user
Args:
user_id (str): The user ID.
Returns:
A deferred list of event objects.
"""
return self.get_rooms_for_user_where_membership_is(
user_id, [Membership.INVITE]
).addCallback(lambda invites: self._get_events([
invites.event_id for invite in invites
]))
def get_rooms_for_user_where_membership_is(self, user_id, membership_list): def get_rooms_for_user_where_membership_is(self, user_id, membership_list):
""" Get all the rooms for this user where the membership for this user """ Get all the rooms for this user where the membership for this user
matches one in the membership list. matches one in the membership list.