mirror of
https://mau.dev/maunium/synapse.git
synced 2024-09-05 17:12:37 +00:00
Merge pull request #104 from matrix-org/get_joined_rooms_for_user
Get joined rooms for user
This commit is contained in:
commit
9fccb0df08
@ -71,7 +71,7 @@ class EventStreamHandler(BaseHandler):
|
|||||||
self._streams_per_user[auth_user] += 1
|
self._streams_per_user[auth_user] += 1
|
||||||
|
|
||||||
rm_handler = self.hs.get_handlers().room_member_handler
|
rm_handler = self.hs.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(auth_user)
|
room_ids = yield rm_handler.get_joined_rooms_for_user(auth_user)
|
||||||
|
|
||||||
if timeout:
|
if timeout:
|
||||||
# If they've set a timeout set a minimum limit.
|
# If they've set a timeout set a minimum limit.
|
||||||
|
@ -452,7 +452,7 @@ class PresenceHandler(BaseHandler):
|
|||||||
# Also include people in all my rooms
|
# Also include people in all my rooms
|
||||||
|
|
||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(user)
|
room_ids = yield rm_handler.get_joined_rooms_for_user(user)
|
||||||
|
|
||||||
if state is None:
|
if state is None:
|
||||||
state = yield self.store.get_presence_state(user.localpart)
|
state = yield self.store.get_presence_state(user.localpart)
|
||||||
@ -596,7 +596,7 @@ class PresenceHandler(BaseHandler):
|
|||||||
localusers.add(user)
|
localusers.add(user)
|
||||||
|
|
||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(user)
|
room_ids = yield rm_handler.get_joined_rooms_for_user(user)
|
||||||
|
|
||||||
if not localusers and not room_ids:
|
if not localusers and not room_ids:
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
@ -663,7 +663,7 @@ class PresenceHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
|
|
||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(user)
|
room_ids = yield rm_handler.get_joined_rooms_for_user(user)
|
||||||
if room_ids:
|
if room_ids:
|
||||||
logger.debug(" | %d interested room IDs %r", len(room_ids), room_ids)
|
logger.debug(" | %d interested room IDs %r", len(room_ids), room_ids)
|
||||||
|
|
||||||
|
@ -197,9 +197,8 @@ class ProfileHandler(BaseHandler):
|
|||||||
|
|
||||||
self.ratelimit(user.to_string())
|
self.ratelimit(user.to_string())
|
||||||
|
|
||||||
joins = yield self.store.get_rooms_for_user_where_membership_is(
|
joins = yield self.store.get_rooms_for_user(
|
||||||
user.to_string(),
|
user.to_string(),
|
||||||
[Membership.JOIN],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for j in joins:
|
for j in joins:
|
||||||
|
@ -507,7 +507,7 @@ class RoomMemberHandler(BaseHandler):
|
|||||||
defer.returnValue((is_remote_invite_join, room_host))
|
defer.returnValue((is_remote_invite_join, room_host))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_rooms_for_user(self, user, membership_list=[Membership.JOIN]):
|
def get_joined_rooms_for_user(self, user):
|
||||||
"""Returns a list of roomids that the user has any of the given
|
"""Returns a list of roomids that the user has any of the given
|
||||||
membership states in."""
|
membership states in."""
|
||||||
|
|
||||||
@ -517,8 +517,8 @@ class RoomMemberHandler(BaseHandler):
|
|||||||
if app_service:
|
if app_service:
|
||||||
rooms = yield self.store.get_app_service_rooms(app_service)
|
rooms = yield self.store.get_app_service_rooms(app_service)
|
||||||
else:
|
else:
|
||||||
rooms = yield self.store.get_rooms_for_user_where_membership_is(
|
rooms = yield self.store.get_rooms_for_user(
|
||||||
user_id=user.to_string(), membership_list=membership_list
|
user.to_string(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# For some reason the list of events contains duplicates
|
# For some reason the list of events contains duplicates
|
||||||
|
@ -96,7 +96,9 @@ class SyncHandler(BaseHandler):
|
|||||||
return self.current_sync_for_user(sync_config, since_token)
|
return self.current_sync_for_user(sync_config, since_token)
|
||||||
|
|
||||||
rm_handler = self.hs.get_handlers().room_member_handler
|
rm_handler = self.hs.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(sync_config.user)
|
room_ids = yield rm_handler.get_joined_rooms_for_user(
|
||||||
|
sync_config.user
|
||||||
|
)
|
||||||
result = yield self.notifier.wait_for_events(
|
result = yield self.notifier.wait_for_events(
|
||||||
sync_config.user, room_ids,
|
sync_config.user, room_ids,
|
||||||
sync_config.filter, timeout, current_sync_callback
|
sync_config.filter, timeout, current_sync_callback
|
||||||
@ -227,7 +229,7 @@ class SyncHandler(BaseHandler):
|
|||||||
logger.debug("Typing %r", typing_by_room)
|
logger.debug("Typing %r", typing_by_room)
|
||||||
|
|
||||||
rm_handler = self.hs.get_handlers().room_member_handler
|
rm_handler = self.hs.get_handlers().room_member_handler
|
||||||
room_ids = yield rm_handler.get_rooms_for_user(sync_config.user)
|
room_ids = yield rm_handler.get_joined_rooms_for_user(sync_config.user)
|
||||||
|
|
||||||
# TODO (mjark): Does public mean "published"?
|
# TODO (mjark): Does public mean "published"?
|
||||||
published_rooms = yield self.store.get_rooms(is_public=True)
|
published_rooms = yield self.store.get_rooms(is_public=True)
|
||||||
|
@ -100,7 +100,7 @@ class PresenceTestCase(unittest.TestCase):
|
|||||||
self.room_members = []
|
self.room_members = []
|
||||||
|
|
||||||
room_member_handler = handlers.room_member_handler = Mock(spec=[
|
room_member_handler = handlers.room_member_handler = Mock(spec=[
|
||||||
"get_rooms_for_user",
|
"get_joined_rooms_for_user",
|
||||||
"get_room_members",
|
"get_room_members",
|
||||||
"fetch_room_distributions_into",
|
"fetch_room_distributions_into",
|
||||||
])
|
])
|
||||||
@ -111,7 +111,7 @@ class PresenceTestCase(unittest.TestCase):
|
|||||||
return defer.succeed([self.room_id])
|
return defer.succeed([self.room_id])
|
||||||
else:
|
else:
|
||||||
return defer.succeed([])
|
return defer.succeed([])
|
||||||
room_member_handler.get_rooms_for_user = get_rooms_for_user
|
room_member_handler.get_joined_rooms_for_user = get_rooms_for_user
|
||||||
|
|
||||||
def get_room_members(room_id):
|
def get_room_members(room_id):
|
||||||
if room_id == self.room_id:
|
if room_id == self.room_id:
|
||||||
|
@ -64,7 +64,7 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
|
|||||||
"set_presence_state",
|
"set_presence_state",
|
||||||
"is_presence_visible",
|
"is_presence_visible",
|
||||||
"set_profile_displayname",
|
"set_profile_displayname",
|
||||||
"get_rooms_for_user_where_membership_is",
|
"get_rooms_for_user",
|
||||||
]),
|
]),
|
||||||
handlers=None,
|
handlers=None,
|
||||||
resource_for_federation=Mock(),
|
resource_for_federation=Mock(),
|
||||||
@ -124,9 +124,9 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
|
|||||||
self.mock_update_client)
|
self.mock_update_client)
|
||||||
|
|
||||||
hs.handlers.room_member_handler = Mock(spec=[
|
hs.handlers.room_member_handler = Mock(spec=[
|
||||||
"get_rooms_for_user",
|
"get_joined_rooms_for_user",
|
||||||
])
|
])
|
||||||
hs.handlers.room_member_handler.get_rooms_for_user = (
|
hs.handlers.room_member_handler.get_joined_rooms_for_user = (
|
||||||
lambda u: defer.succeed([]))
|
lambda u: defer.succeed([]))
|
||||||
|
|
||||||
# Some local users to test with
|
# Some local users to test with
|
||||||
@ -138,7 +138,7 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
|
|||||||
self.u_potato = UserID.from_string("@potato:remote")
|
self.u_potato = UserID.from_string("@potato:remote")
|
||||||
|
|
||||||
self.mock_get_joined = (
|
self.mock_get_joined = (
|
||||||
self.datastore.get_rooms_for_user_where_membership_is
|
self.datastore.get_rooms_for_user
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -79,13 +79,13 @@ class PresenceStateTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
room_member_handler = hs.handlers.room_member_handler = Mock(
|
room_member_handler = hs.handlers.room_member_handler = Mock(
|
||||||
spec=[
|
spec=[
|
||||||
"get_rooms_for_user",
|
"get_joined_rooms_for_user",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_rooms_for_user(user):
|
def get_rooms_for_user(user):
|
||||||
return defer.succeed([])
|
return defer.succeed([])
|
||||||
room_member_handler.get_rooms_for_user = get_rooms_for_user
|
room_member_handler.get_joined_rooms_for_user = get_rooms_for_user
|
||||||
|
|
||||||
presence.register_servlets(hs, self.mock_resource)
|
presence.register_servlets(hs, self.mock_resource)
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ class PresenceListTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
hs.handlers.room_member_handler = Mock(
|
hs.handlers.room_member_handler = Mock(
|
||||||
spec=[
|
spec=[
|
||||||
"get_rooms_for_user",
|
"get_joined_rooms_for_user",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ class PresenceEventStreamTestCase(unittest.TestCase):
|
|||||||
return ["a-room"]
|
return ["a-room"]
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
hs.handlers.room_member_handler.get_rooms_for_user = get_rooms_for_user
|
hs.handlers.room_member_handler.get_joined_rooms_for_user = get_rooms_for_user
|
||||||
|
|
||||||
self.mock_datastore = hs.get_datastore()
|
self.mock_datastore = hs.get_datastore()
|
||||||
self.mock_datastore.get_app_service_by_token = Mock(return_value=None)
|
self.mock_datastore.get_app_service_by_token = Mock(return_value=None)
|
||||||
|
Loading…
Reference in New Issue
Block a user