Add stub methods, TODOs and docstrings for application services.
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
|