From afb646dc1e7a91ee7a050632d1e5a5883830d18c Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Tue, 2 Dec 2014 18:00:51 +0000 Subject: Allow GET /room/:room_id/messages without 'limit' parameter to default to 10 --- synapse/rest/room.py | 4 +++- synapse/streams/config.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/synapse/rest/room.py b/synapse/rest/room.py index cc6ffb9aff..3147d7a60b 100644 --- a/synapse/rest/room.py +++ b/synapse/rest/room.py @@ -327,7 +327,9 @@ class RoomMessageListRestServlet(RestServlet): @defer.inlineCallbacks def on_GET(self, request, room_id): user = yield self.auth.get_user_by_req(request) - pagination_config = PaginationConfig.from_request(request) + pagination_config = PaginationConfig.from_request(request, + default_limit=10, + ) with_feedback = "feedback" in request.args handler = self.handlers.message_handler msgs = yield handler.get_messages( diff --git a/synapse/streams/config.py b/synapse/streams/config.py index 0317e78c08..2114c940e7 100644 --- a/synapse/streams/config.py +++ b/synapse/streams/config.py @@ -47,7 +47,8 @@ class PaginationConfig(object): self.limit = int(limit) if limit is not None else None @classmethod - def from_request(cls, request, raise_invalid_params=True): + def from_request(cls, request, raise_invalid_params=True, + default_limit=None): def get_param(name, default=None): lst = request.args.get(name, []) if len(lst) > 1: @@ -84,6 +85,9 @@ class PaginationConfig(object): if limit is not None and not limit.isdigit(): raise SynapseError(400, "'limit' parameter must be an integer.") + if limit is None: + limit = default_limit + try: return PaginationConfig(from_tok, to_tok, direction, limit) except: -- cgit 1.4.1