Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Encode batch tokens better
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jun 27, 2016
1 parent 4b7abed commit 6c137b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def __init__(self, order, limit, tags):
super(SyncPaginationConfig, self).__init__(order, limit, tags)


SYNC_PAGINATION_TAGS_INCLUDE_ALL = "include_all"
SYNC_PAGINATION_TAGS_IGNORE = "ignore"
SYNC_PAGINATION_TAGS_INCLUDE_ALL = "m.include_all"
SYNC_PAGINATION_TAGS_IGNORE = "m.ignore"
SYNC_PAGINATION_VALID_TAGS_OPTIONS = (
SYNC_PAGINATION_TAGS_INCLUDE_ALL, SYNC_PAGINATION_TAGS_IGNORE,
)

SYNC_PAGINATION_ORDER_TS = "o"
SYNC_PAGINATION_ORDER_TS = "m.origin_server_ts"
SYNC_PAGINATION_VALID_ORDERS = (SYNC_PAGINATION_ORDER_TS,)


Expand Down
12 changes: 9 additions & 3 deletions synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def replace(self, **kwargs):
return self._replace(**kwargs)


_ORDER_ENCODE = {"m.origin_server_ts": "o"}
_ORDER_DECODE = {v: k for k, v in _ORDER_ENCODE.items()}
_TAG_ENCODE = {"m.include_all": "i", "m.ignore": "x"}
_TAG_DECODE = {v: k for k, v in _TAG_ENCODE.items()}


class SyncPaginationState(
namedtuple("SyncPaginationState", (
"order",
Expand All @@ -159,16 +165,16 @@ class SyncPaginationState(
@classmethod
def from_dict(cls, d):
try:
return cls(d["o"], d["v"], d["l"], d["t"])
return cls(_ORDER_DECODE[d["o"]], d["v"], d["l"], _TAG_DECODE[d["t"]])
except:
raise SynapseError(400, "Invalid Token")

def to_dict(self):
return {
"o": self.order,
"o": _ORDER_ENCODE[self.order],
"v": self.value,
"l": self.limit,
"t": self.tags,
"t": _TAG_ENCODE[self.tags],
}

def replace(self, **kwargs):
Expand Down

0 comments on commit 6c137b3

Please sign in to comment.