summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-08-29 17:39:33 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-08-29 17:39:33 +0100
commit6dd50da54ea944610eb3836621c45a2d6b2a532b (patch)
tree9ba22386eb6b5bd82d16240095d2913424d9e4ca
parentAvoid hardcoding names of individual stream token keys in its own implementat... (diff)
downloadsynapse-6dd50da54ea944610eb3836621c45a2d6b2a532b.tar.xz
Define a new event stream data source for typing notifications (currently null)
-rw-r--r--synapse/handlers/typing.py14
-rw-r--r--synapse/streams/events.py20
-rw-r--r--synapse/types.py2
-rw-r--r--tests/rest/test_presence.py8
4 files changed, 33 insertions, 11 deletions
diff --git a/synapse/handlers/typing.py b/synapse/handlers/typing.py
index 9fab0ff37c..8a1e3dc5e8 100644
--- a/synapse/handlers/typing.py
+++ b/synapse/handlers/typing.py
@@ -145,3 +145,17 @@ class TypingNotificationHandler(BaseHandler):
             typing):
         # TODO(paul) steal this from presence.py
         pass
+
+
+class TypingNotificationEventSource(object):
+    def __init__(self, hs):
+        self.hs = hs
+
+    def get_new_events_for_user(self, user, from_token, limit):
+        return ([], 0)
+
+    def get_current_token_part(self):
+        return 0
+
+    def get_pagination_rows(self, user, pagination_config, key):
+        return ([], 0)
diff --git a/synapse/streams/events.py b/synapse/streams/events.py
index 321faf4b03..4bec6605bd 100644
--- a/synapse/streams/events.py
+++ b/synapse/streams/events.py
@@ -19,6 +19,7 @@ from synapse.types import StreamToken
 
 from synapse.handlers.presence import PresenceEventSource
 from synapse.handlers.room import RoomEventSource
+from synapse.handlers.typing import TypingNotificationEventSource
 
 
 class NullSource(object):
@@ -41,6 +42,7 @@ class EventSources(object):
     SOURCE_TYPES = {
         "room": RoomEventSource,
         "presence": PresenceEventSource,
+        "typing": TypingNotificationEventSource,
     }
 
     def __init__(self, hs):
@@ -49,15 +51,19 @@ class EventSources(object):
             for name, cls in EventSources.SOURCE_TYPES.items()
         }
 
-    @staticmethod
-    def create_token(events_key, presence_key):
-        return StreamToken(events_key=events_key, presence_key=presence_key)
-
     @defer.inlineCallbacks
     def get_current_token(self):
-        events_key = yield self.sources["room"].get_current_token_part()
-        presence_key = yield self.sources["presence"].get_current_token_part()
-        token = EventSources.create_token(events_key, presence_key)
+        token = StreamToken(
+            events_key=(
+                yield self.sources["room"].get_current_token_part()
+            ),
+            presence_key=(
+                yield self.sources["presence"].get_current_token_part()
+            ),
+            typing_key=(
+                yield self.sources["typing"].get_current_token_part()
+            )
+        )
         defer.returnValue(token)
 
 
diff --git a/synapse/types.py b/synapse/types.py
index aa6f589a20..d93b02a56e 100644
--- a/synapse/types.py
+++ b/synapse/types.py
@@ -97,7 +97,7 @@ class RoomID(DomainSpecificString):
 class StreamToken(
     namedtuple(
         "Token",
-        ("events_key", "presence_key")
+        ("events_key", "presence_key", "typing_key")
     )
 ):
     _SEPARATOR = "_"
diff --git a/tests/rest/test_presence.py b/tests/rest/test_presence.py
index 0f5fc21432..ab0d580c7c 100644
--- a/tests/rest/test_presence.py
+++ b/tests/rest/test_presence.py
@@ -295,7 +295,9 @@ class PresenceEventStreamTestCase(unittest.TestCase):
         # all be ours
 
         # I'll already get my own presence state change
-        self.assertEquals({"start": "0_1", "end": "0_1", "chunk": []}, response)
+        self.assertEquals({"start": "0_1_0", "end": "0_1_0", "chunk": []},
+            response
+        )
 
         self.mock_datastore.set_presence_state.return_value = defer.succeed(
                 {"state": ONLINE})
@@ -306,10 +308,10 @@ class PresenceEventStreamTestCase(unittest.TestCase):
                 state={"state": ONLINE})
 
         (code, response) = yield self.mock_resource.trigger("GET",
-                "/events?from=0_1&timeout=0", None)
+                "/events?from=0_1_0&timeout=0", None)
 
         self.assertEquals(200, code)
-        self.assertEquals({"start": "0_1", "end": "0_2", "chunk": [
+        self.assertEquals({"start": "0_1_0", "end": "0_2_0", "chunk": [
             {"type": "m.presence",
              "content": {
                  "user_id": "@banana:test",