summary refs log tree commit diff
path: root/synapse/storage/appservice.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-02-25 17:15:25 +0000
committerKegan Dougal <kegan@matrix.org>2015-02-25 17:15:25 +0000
commit2b8ca84296b228b7cef09244605e4f2760349538 (patch)
tree770c0503383e8f1dbe539252e4d91034f01a6e81 /synapse/storage/appservice.py
parentAdd stub functions and work out execution flow to implement AS event stream p... (diff)
downloadsynapse-2b8ca84296b228b7cef09244605e4f2760349538.tar.xz
Add support for extracting matching room_ids and room_aliases for a given AS.
Diffstat (limited to 'synapse/storage/appservice.py')
-rw-r--r--synapse/storage/appservice.py50
1 files changed, 48 insertions, 2 deletions
diff --git a/synapse/storage/appservice.py b/synapse/storage/appservice.py
index 435ccfd6fc..c8f0ce44f4 100644
--- a/synapse/storage/appservice.py
+++ b/synapse/storage/appservice.py
@@ -153,6 +153,19 @@ class ApplicationServiceStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def get_app_service_by_user_id(self, user_id):
+        """Retrieve an application service from their user ID.
+
+        All application services have associated with them a particular user ID.
+        There is no distinguishing feature on the user ID which indicates it
+        represents an application service. This function allows you to map from
+        a user ID to an application service.
+
+        Args:
+            user_id(str): The user ID to see if it is an application service.
+        Returns:
+            synapse.appservice.ApplicationService or None.
+        """
+
         yield self.cache_defer  # make sure the cache is ready
 
         for service in self.services_cache:
@@ -163,7 +176,7 @@ class ApplicationServiceStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def get_app_service_by_token(self, token, from_cache=True):
-        """Get the application service with the given token.
+        """Get the application service with the given appservice token.
 
         Args:
             token (str): The application service token.
@@ -186,10 +199,43 @@ class ApplicationServiceStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def get_app_service_rooms(self, service):
-        logger.info("get_app_service_rooms -> %s", service)
+        """Get a list of RoomsForUser for this application service.
+
+        Application services may be "interested" in lots of rooms depending on
+        the room ID, the room aliases, or the members in the room. This function
+        takes all of these into account and returns a list of RoomsForUser which
+        represent the entire list of room IDs that this application service
+        wants to know about.
+
+        Args:
+            service: The application service to get a room list for.
+        Returns:
+            A list of RoomsForUser.
+        """
+        # FIXME: This is assuming that this store has methods from
+        # RoomStore, DirectoryStore, which is a bad assumption to
+        # make as it makes testing trickier and coupling less obvious.
+
+        # get all rooms matching the room ID regex.
+        room_entries = yield self.get_all_rooms()  # RoomEntry list
+        matching_room_id_list = [
+            r.room_id for r in room_entries if
+            service.is_interested_in_room(r.room_id)
+        ]
+
+        # resolve room IDs for matching room alias regex.
+        room_alias_mappings = yield self.get_all_associations()
+        matching_alias_list = [
+            r.room_id for r in room_alias_mappings if
+            service.is_interested_in_alias(r.room_alias)
+        ]
+
+        # get all rooms for every user for this AS.
 
         # TODO stub
         yield self.cache_defer
+
+
         defer.returnValue([RoomsForUser("!foo:bar", service.sender, "join")])
 
     @defer.inlineCallbacks