From 96d6fff44787a53863b1321ed28f1636aa5dc78a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Jun 2016 11:33:53 +0100 Subject: [PATCH] Fix 'A next_batch token can be used in the v1 messages API' --- synapse/streams/config.py | 14 +++++++++----- synapse/types.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/synapse/streams/config.py b/synapse/streams/config.py index 4f089bfb94..49be3c222a 100644 --- a/synapse/streams/config.py +++ b/synapse/streams/config.py @@ -14,7 +14,7 @@ # limitations under the License. from synapse.api.errors import SynapseError -from synapse.types import StreamToken +from synapse.types import StreamToken, SyncNextBatchToken import logging @@ -72,14 +72,18 @@ class PaginationConfig(object): if direction not in ['f', 'b']: raise SynapseError(400, "'dir' parameter is invalid.") - from_tok = get_param("from") + raw_from_tok = get_param("from") to_tok = get_param("to") try: - if from_tok == "END": + from_tok = None + if raw_from_tok == "END": from_tok = None # For backwards compat. - elif from_tok: - from_tok = StreamToken.from_string(from_tok) + elif raw_from_tok: + try: + from_tok = SyncNextBatchToken.from_string(raw_from_tok).stream_token + except: + from_tok = StreamToken.from_string(raw_from_tok) except: raise SynapseError(400, "'from' paramater is invalid") diff --git a/synapse/types.py b/synapse/types.py index bde9e8e2c5..13cdc737fb 100644 --- a/synapse/types.py +++ b/synapse/types.py @@ -174,7 +174,7 @@ class SyncPaginationState( class StreamToken( - namedtuple("Token", ( + namedtuple("StreamToken", ( "room_key", "presence_key", "typing_key",