summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-02-25 15:00:59 +0000
committerKegan Dougal <kegan@matrix.org>2015-02-25 15:00:59 +0000
commit2d20466f9a1349c97d5a3822eb4ee64f19bbdf27 (patch)
tree5d67e29854210f2ecd334c2809555d72d9db443d /synapse/storage
parentturns uris config options should append since it's a list (diff)
downloadsynapse-2d20466f9a1349c97d5a3822eb4ee64f19bbdf27.tar.xz
Add stub functions and work out execution flow to implement AS event stream polling.
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/appservice.py19
-rw-r--r--synapse/storage/stream.py21
2 files changed, 40 insertions, 0 deletions
diff --git a/synapse/storage/appservice.py b/synapse/storage/appservice.py
index dc3666efd4..435ccfd6fc 100644
--- a/synapse/storage/appservice.py
+++ b/synapse/storage/appservice.py
@@ -17,6 +17,7 @@ from twisted.internet import defer
 
 from synapse.api.errors import StoreError
 from synapse.appservice import ApplicationService
+from synapse.storage.roommember import RoomsForUser
 from ._base import SQLBaseStore
 
 
@@ -151,6 +152,16 @@ class ApplicationServiceStore(SQLBaseStore):
         defer.returnValue(self.services_cache)
 
     @defer.inlineCallbacks
+    def get_app_service_by_user_id(self, user_id):
+        yield self.cache_defer  # make sure the cache is ready
+
+        for service in self.services_cache:
+            if service.sender == user_id:
+                defer.returnValue(service)
+                return
+        defer.returnValue(None)
+
+    @defer.inlineCallbacks
     def get_app_service_by_token(self, token, from_cache=True):
         """Get the application service with the given token.
 
@@ -174,6 +185,14 @@ class ApplicationServiceStore(SQLBaseStore):
         # TODO: This should be JOINed with the application_services_regex table.
 
     @defer.inlineCallbacks
+    def get_app_service_rooms(self, service):
+        logger.info("get_app_service_rooms -> %s", service)
+
+        # TODO stub
+        yield self.cache_defer
+        defer.returnValue([RoomsForUser("!foo:bar", service.sender, "join")])
+
+    @defer.inlineCallbacks
     def _populate_cache(self):
         """Populates the ApplicationServiceCache from the database."""
         sql = ("SELECT * FROM application_services LEFT JOIN "
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index 3ccb6f8a61..aa3c9f8c9c 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -127,6 +127,27 @@ class _StreamToken(namedtuple("_StreamToken", "topological stream")):
 
 
 class StreamStore(SQLBaseStore):
+
+    def get_appservice_room_stream(self, service, from_key, to_key, limit=0):
+        # NB this lives here instead of appservice.py so we can reuse the
+        # 'private' StreamToken class in this file.
+        logger.info("get_appservice_room_stream -> %s", service)
+
+        if limit:
+            limit = max(limit, MAX_STREAM_SIZE)
+        else:
+            limit = MAX_STREAM_SIZE
+
+        # From and to keys should be integers from ordering.
+        from_id = _StreamToken.parse_stream_token(from_key)
+        to_id = _StreamToken.parse_stream_token(to_key)
+
+        if from_key == to_key:
+            return defer.succeed(([], to_key))
+
+        # TODO stub
+        return defer.succeed(([], to_key))
+
     @log_function
     def get_room_events_stream(self, user_id, from_key, to_key, room_id,
                                limit=0, with_feedback=False):