summary refs log tree commit diff
path: root/synapse/handlers/appservice.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-02-05 13:19:46 +0000
committerKegan Dougal <kegan@matrix.org>2015-02-05 13:19:46 +0000
commit51d63ac329a2613c0a7195e6183d70f789b7d823 (patch)
treeb8a0c41fefa5b141865025cfbc4ef0a83d6e346d /synapse/handlers/appservice.py
parentAdd unit test for appservice_handler.query_room_alias_exists (diff)
downloadsynapse-51d63ac329a2613c0a7195e6183d70f789b7d823.tar.xz
Glue AS work to general event notifications. Add more exception handling when poking ASes.
Diffstat (limited to 'synapse/handlers/appservice.py')
-rw-r--r--synapse/handlers/appservice.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py
index 2c6d4e2815..ef94215133 100644
--- a/synapse/handlers/appservice.py
+++ b/synapse/handlers/appservice.py
@@ -23,7 +23,6 @@ import synapse.util.stringutils as stringutils
 
 import logging
 
-
 logger = logging.getLogger(__name__)
 
 
@@ -58,6 +57,7 @@ class ApplicationServicesHandler(object):
         yield self.store.update_app_service(app_service)
         defer.returnValue(app_service)
 
+    @defer.inlineCallbacks
     def unregister(self, token):
         logger.info("Unregister as_token=%s", token)
         yield self.store.unregister_app_service(token)
@@ -81,34 +81,45 @@ class ApplicationServicesHandler(object):
         # all services which match that user regex.
         unknown_user = yield self._is_unknown_user(event.sender)
         if unknown_user:
-            user_query_services = yield self._get_services_for_event(
-                event=event,
-                restrict_to=ApplicationService.NS_USERS
-            )
-            for user_service in user_query_services:
-                # this needs to block XXX: Need to feed response back to caller
-                is_known_user = yield self.appservice_api.query_user(
-                    user_service, event.sender
-                )
-                if is_known_user:
-                    # the user exists now,so don't query more ASes.
-                    break
+            yield self.query_user_exists(event)
 
         # Fork off pushes to these services - XXX First cut, best effort
         for service in services:
             self.appservice_api.push(service, event)
 
+    @defer.inlineCallbacks
+    def query_user_exists(self, event):
+        """Check if an application services knows this event.sender exists.
+
+        Args:
+            event: An event sent by the user to query
+        Returns:
+            True if this user exists.
+        """
+        # TODO Would be nice for this to accept a user ID instead of an event.
+        user_query_services = yield self._get_services_for_event(
+            event=event,
+            restrict_to=ApplicationService.NS_USERS
+        )
+        for user_service in user_query_services:
+            is_known_user = yield self.appservice_api.query_user(
+                user_service, event.sender
+            )
+            if is_known_user:
+                defer.returnValue(True)
+        defer.returnValue(False)
 
     @defer.inlineCallbacks
     def query_room_alias_exists(self, room_alias):
         """Check if an application service knows this room alias exists.
 
         Args:
-            room_alias(str): The room alias to query.
+            room_alias(RoomAlias): The room alias to query.
         Returns:
             namedtuple: with keys "room_id" and "servers" or None if no
             association can be found.
         """
+        room_alias = room_alias.to_string()
         alias_query_services = yield self._get_services_for_event(
             event=None,
             restrict_to=ApplicationService.NS_ALIASES,