summary refs log tree commit diff
path: root/synapse/storage/appservice.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-01-27 16:53:59 +0000
committerKegan Dougal <kegan@matrix.org>2015-01-27 16:53:59 +0000
commit92171f9dd1ecac24aeae2f46729f3cbbbe94f91e (patch)
tree5416bc62f0c44d52c830b9fa848d9307f54ff828 /synapse/storage/appservice.py
parentAdd AS specific classes with docstrings. (diff)
downloadsynapse-92171f9dd1ecac24aeae2f46729f3cbbbe94f91e.tar.xz
Add stub methods, TODOs and docstrings for application services.
Diffstat (limited to '')
-rw-r--r--synapse/storage/appservice.py52
1 files changed, 50 insertions, 2 deletions
diff --git a/synapse/storage/appservice.py b/synapse/storage/appservice.py
index 4c11191fe8..fbad17cb9e 100644
--- a/synapse/storage/appservice.py
+++ b/synapse/storage/appservice.py
@@ -84,16 +84,60 @@ class ApplicationServiceStore(SQLBaseStore):
         super(ApplicationServiceStore, self).__init__(hs)
         self.cache = ApplicationServiceCache()
         self.clock = hs.get_clock()
+        self._populate_cache()
+
+    def unregister_app_service(self, token):
+        """Unregisters this service.
+
+        This removes all AS specific regex and the base URL. The token is the
+        only thing preserved for future registration attempts.
+        """
+        # TODO: DELETE FROM application_services_regex WHERE id=this service
+        # TODO: SET url=NULL WHERE token=token
+        # TODO: Update cache
+        pass
+
+    def update_app_service(self, service):
+        """Update an application service, clobbering what was previously there.
+
+        Args:
+            service(ApplicationService): The updated service.
+        """
+        # NB: There is no "insert" since we provide no public-facing API to
+        # allocate new ASes. It relies on the server admin inserting the AS
+        # token into the database manually.
+
+        # TODO: UPDATE application_services, SET url WHERE token=service.token
+        # TODO: DELETE FROM application_services_regex WHERE id=this service
+        # TODO: INSERT INTO application_services_regex <new namespace regex>
+        # TODO: Update cache
+        pass
+
+    def get_services_for_event(self, event):
+        return self.cache.get_services_for_event(event)
 
     @defer.inlineCallbacks
-    def get_app_service(self, as_token):
+    def get_app_service(self, as_token, from_cache=True):
         """Get the application service with the given token.
 
         Args:
             token (str): The application service token.
+            from_cache (bool): True to get this service from the cache, False to
+                               check the database.
         Raises:
-            StoreError if there was a problem retrieving this.
+            StoreError if there was a problem retrieving this service.
         """
+
+        if from_cache:
+            for service in self.cache.services:
+                if service.token == as_token:
+                    defer.returnValue(service)
+                    return
+            defer.returnValue(None)
+            return
+
+
+        # TODO: This should be JOINed with the application_services_regex table.
         row = self._simple_select_one(
             "application_services", {"token": as_token},
             ["url", "token"]
@@ -101,3 +145,7 @@ class ApplicationServiceStore(SQLBaseStore):
         if not row:
             raise StoreError(400, "Bad application services token supplied.")
         defer.returnValue(row)
+
+    def _populate_cache(self):
+        """Populates the ApplicationServiceCache from the database."""
+        pass