diff options
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/login.py | 2 | ||||
-rw-r--r-- | synapse/handlers/message.py | 10 | ||||
-rw-r--r-- | synapse/handlers/presence.py | 63 | ||||
-rw-r--r-- | synapse/handlers/register.py | 15 | ||||
-rw-r--r-- | synapse/handlers/room.py | 26 | ||||
-rw-r--r-- | synapse/handlers/typing.py | 16 |
6 files changed, 53 insertions, 79 deletions
diff --git a/synapse/handlers/login.py b/synapse/handlers/login.py index 3f152e18f0..99d15261d4 100644 --- a/synapse/handlers/login.py +++ b/synapse/handlers/login.py @@ -54,7 +54,7 @@ class LoginHandler(BaseHandler): # pull out the hash for this user if they exist user_info = yield self.store.get_user_by_id(user_id=user) if not user_info: - logger.warn("Attempted to login as %s but they do not exist.", user) + logger.warn("Attempted to login as %s but they do not exist", user) raise LoginError(403, "", errcode=Codes.FORBIDDEN) stored_hash = user_info[0]["password_hash"] diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 65861033e9..c6f6ab14d1 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -114,8 +114,12 @@ class MessageHandler(BaseHandler): user = self.hs.parse_userid(user_id) - events, next_token = yield data_source.get_pagination_rows( - user, pagin_config, room_id + events, next_key = yield data_source.get_pagination_rows( + user, pagin_config.get_source_config("room"), room_id + ) + + next_token = pagin_config.from_token.copy_and_replace( + "room_key", next_key ) chunk = { @@ -264,7 +268,7 @@ class MessageHandler(BaseHandler): presence_stream = self.hs.get_event_sources().sources["presence"] pagination_config = PaginationConfig(from_token=now_token) presence, _ = yield presence_stream.get_pagination_rows( - user, pagination_config, None + user, pagination_config.get_source_config("presence"), None ) public_rooms = yield self.store.get_rooms(is_public=True) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index b2af09f090..2ccc2245b7 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -76,9 +76,7 @@ class PresenceHandler(BaseHandler): "stopped_user_eventstream", self.stopped_user_eventstream ) - distributor.observe("user_joined_room", - self.user_joined_room - ) + distributor.observe("user_joined_room", self.user_joined_room) distributor.declare("collect_presencelike_data") @@ -156,14 +154,12 @@ class PresenceHandler(BaseHandler): defer.returnValue(True) if (yield self.store.user_rooms_intersect( - [u.to_string() for u in observer_user, observed_user] - )): + [u.to_string() for u in observer_user, observed_user])): defer.returnValue(True) if (yield self.store.is_presence_visible( - observed_localpart=observed_user.localpart, - observer_userid=observer_user.to_string(), - )): + observed_localpart=observed_user.localpart, + observer_userid=observer_user.to_string())): defer.returnValue(True) defer.returnValue(False) @@ -171,7 +167,8 @@ class PresenceHandler(BaseHandler): @defer.inlineCallbacks def get_state(self, target_user, auth_user): if target_user.is_mine: - visible = yield self.is_presence_visible(observer_user=auth_user, + visible = yield self.is_presence_visible( + observer_user=auth_user, observed_user=target_user ) @@ -219,9 +216,9 @@ class PresenceHandler(BaseHandler): ) if state["presence"] not in self.STATE_LEVELS: - raise SynapseError(400, "'%s' is not a valid presence state" % - state["presence"] - ) + raise SynapseError(400, "'%s' is not a valid presence state" % ( + state["presence"], + )) logger.debug("Updating presence state of %s to %s", target_user.localpart, state["presence"]) @@ -229,7 +226,7 @@ class PresenceHandler(BaseHandler): state_to_store = dict(state) state_to_store["state"] = state_to_store.pop("presence") - statuscache=self._get_or_offline_usercache(target_user) + statuscache = self._get_or_offline_usercache(target_user) was_level = self.STATE_LEVELS[statuscache.get_state()["presence"]] now_level = self.STATE_LEVELS[state["presence"]] @@ -649,8 +646,9 @@ class PresenceHandler(BaseHandler): del state["user_id"] if "presence" not in state: - logger.warning("Received a presence 'push' EDU from %s without" - + " a 'presence' key", origin + logger.warning( + "Received a presence 'push' EDU from %s without a" + " 'presence' key", origin ) continue @@ -745,7 +743,7 @@ class PresenceHandler(BaseHandler): defer.returnValue((localusers, remote_domains)) def push_update_to_clients(self, observed_user, users_to_push=[], - room_ids=[], statuscache=None): + room_ids=[], statuscache=None): self.notifier.on_new_user_event( users_to_push, room_ids, @@ -765,8 +763,7 @@ class PresenceEventSource(object): presence = self.hs.get_handlers().presence_handler if (yield presence.store.user_rooms_intersect( - [u.to_string() for u in observer_user, observed_user] - )): + [u.to_string() for u in observer_user, observed_user])): defer.returnValue(True) if observed_user.is_mine: @@ -823,15 +820,12 @@ class PresenceEventSource(object): def get_pagination_rows(self, user, pagination_config, key): # TODO (erikj): Does this make sense? Ordering? - from_token = pagination_config.from_token - to_token = pagination_config.to_token - observer_user = user - from_key = int(from_token.presence_key) + from_key = int(pagination_config.from_key) - if to_token: - to_key = int(to_token.presence_key) + if pagination_config.to_key: + to_key = int(pagination_config.to_key) else: to_key = -1 @@ -841,7 +835,7 @@ class PresenceEventSource(object): updates = [] # TODO(paul): use a DeferredList ? How to limit concurrency. for observed_user in cachemap.keys(): - if not (to_key < cachemap[observed_user].serial < from_key): + if not (to_key < cachemap[observed_user].serial <= from_key): continue if (yield self.is_visible(observer_user, observed_user)): @@ -849,30 +843,15 @@ class PresenceEventSource(object): # TODO(paul): limit - updates = [(k, cachemap[k]) for k in cachemap - if to_key < cachemap[k].serial < from_key] - if updates: clock = self.clock earliest_serial = max([x[1].serial for x in updates]) data = [x[1].make_event(user=x[0], clock=clock) for x in updates] - if to_token: - next_token = to_token - else: - next_token = from_token - - next_token = next_token.copy_and_replace( - "presence_key", earliest_serial - ) - defer.returnValue((data, next_token)) + defer.returnValue((data, earliest_serial)) else: - if not to_token: - to_token = from_token.copy_and_replace( - "presence_key", 0 - ) - defer.returnValue(([], to_token)) + defer.returnValue(([], 0)) class UserPresenceCache(object): diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 94b7890b5e..88eb51a8ed 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -64,9 +64,11 @@ class RegistrationHandler(BaseHandler): user_id = user.to_string() token = self._generate_token(user_id) - yield self.store.register(user_id=user_id, + yield self.store.register( + user_id=user_id, token=token, - password_hash=password_hash) + password_hash=password_hash + ) self.distributor.fire("registered_user", user) else: @@ -181,8 +183,11 @@ class RegistrationHandler(BaseHandler): data = yield httpCli.post_urlencoded_get_json( creds['idServer'], "/_matrix/identity/api/v1/3pid/bind", - {'sid': creds['sid'], 'clientSecret': creds['clientSecret'], - 'mxid': mxid} + { + 'sid': creds['sid'], + 'clientSecret': creds['clientSecret'], + 'mxid': mxid, + } ) defer.returnValue(data) @@ -223,5 +228,3 @@ class RegistrationHandler(BaseHandler): } ) defer.returnValue(data) - - diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index cb5bd17d2b..ffc0892f1a 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -170,11 +170,6 @@ class RoomCreationHandler(BaseHandler): content=content ) - yield self.hs.get_handlers().room_member_handler.change_membership( - join_event, - do_auth=False - ) - content = {"membership": Membership.INVITE} for invitee in invite_list: invite_event = self.event_factory.create_event( @@ -616,23 +611,14 @@ class RoomEventSource(object): return self.store.get_room_events_max_id() @defer.inlineCallbacks - def get_pagination_rows(self, user, pagination_config, key): - from_token = pagination_config.from_token - to_token = pagination_config.to_token - limit = pagination_config.limit - direction = pagination_config.direction - - to_key = to_token.room_key if to_token else None - + def get_pagination_rows(self, user, config, key): events, next_key = yield self.store.paginate_room_events( room_id=key, - from_key=from_token.room_key, - to_key=to_key, - direction=direction, - limit=limit, + from_key=config.from_key, + to_key=config.to_key, + direction=config.direction, + limit=config.limit, with_feedback=True ) - next_token = from_token.copy_and_replace("room_key", next_key) - - defer.returnValue((events, next_token)) + defer.returnValue((events, next_key)) diff --git a/synapse/handlers/typing.py b/synapse/handlers/typing.py index 0ca4e5c31e..d88a53242c 100644 --- a/synapse/handlers/typing.py +++ b/synapse/handlers/typing.py @@ -96,9 +96,10 @@ class TypingNotificationHandler(BaseHandler): remotedomains = set() rm_handler = self.homeserver.get_handlers().room_member_handler - yield rm_handler.fetch_room_distributions_into(room_id, - localusers=localusers, remotedomains=remotedomains, - ignore_user=user) + yield rm_handler.fetch_room_distributions_into( + room_id, localusers=localusers, remotedomains=remotedomains, + ignore_user=user + ) for u in localusers: self.push_update_to_clients( @@ -130,8 +131,9 @@ class TypingNotificationHandler(BaseHandler): localusers = set() rm_handler = self.homeserver.get_handlers().room_member_handler - yield rm_handler.fetch_room_distributions_into(room_id, - localusers=localusers) + yield rm_handler.fetch_room_distributions_into( + room_id, localusers=localusers + ) for u in localusers: self.push_update_to_clients( @@ -142,7 +144,7 @@ class TypingNotificationHandler(BaseHandler): ) def push_update_to_clients(self, room_id, observer_user, observed_user, - typing): + typing): # TODO(paul) steal this from presence.py pass @@ -158,4 +160,4 @@ class TypingNotificationEventSource(object): return 0 def get_pagination_rows(self, user, pagination_config, key): - return ([], pagination_config.from_token) + return ([], pagination_config.from_key) |