From 43cbde4653ee988fc0b68c9a54a864a54f07d8e3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 25 May 2016 15:54:32 +0100 Subject: Basic extra include pagination impl --- synapse/types.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'synapse/types.py') diff --git a/synapse/types.py b/synapse/types.py index fd7c0ffe7a..cf950a0c36 100644 --- a/synapse/types.py +++ b/synapse/types.py @@ -129,7 +129,7 @@ class SyncNextBatchToken( if pa: pa = SyncPaginationState.from_dict(pa) return cls( - stream_token=StreamToken.from_string(d["t"]), + stream_token=StreamToken.from_arr(d["t"]), pagination_state=pa, ) except: @@ -137,7 +137,7 @@ class SyncNextBatchToken( def to_string(self): return encode_base64(json.dumps({ - "t": self.stream_token.to_string(), + "t": self.stream_token.to_arr(), "pa": self.pagination_state.to_dict() if self.pagination_state else None, })) @@ -196,6 +196,20 @@ class StreamToken( def to_string(self): return self._SEPARATOR.join([str(k) for k in self]) + @classmethod + def from_arr(cls, arr): + try: + keys = arr + while len(keys) < len(cls._fields): + # i.e. old token from before receipt_key + keys.append("0") + return cls(*keys) + except: + raise SynapseError(400, "Invalid Token") + + def to_arr(self): + return self + @property def room_stream_id(self): # TODO(markjh): Awful hack to work around hacks in the presence tests -- cgit 1.5.1