mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Allow GET /room/:room_id/messages without 'limit' parameter to default to 10
This commit is contained in:
parent
d8b35250a5
commit
afb646dc1e
@ -327,7 +327,9 @@ class RoomMessageListRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, room_id):
|
def on_GET(self, request, room_id):
|
||||||
user = yield self.auth.get_user_by_req(request)
|
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
|
with_feedback = "feedback" in request.args
|
||||||
handler = self.handlers.message_handler
|
handler = self.handlers.message_handler
|
||||||
msgs = yield handler.get_messages(
|
msgs = yield handler.get_messages(
|
||||||
|
@ -47,7 +47,8 @@ class PaginationConfig(object):
|
|||||||
self.limit = int(limit) if limit is not None else None
|
self.limit = int(limit) if limit is not None else None
|
||||||
|
|
||||||
@classmethod
|
@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):
|
def get_param(name, default=None):
|
||||||
lst = request.args.get(name, [])
|
lst = request.args.get(name, [])
|
||||||
if len(lst) > 1:
|
if len(lst) > 1:
|
||||||
@ -84,6 +85,9 @@ class PaginationConfig(object):
|
|||||||
if limit is not None and not limit.isdigit():
|
if limit is not None and not limit.isdigit():
|
||||||
raise SynapseError(400, "'limit' parameter must be an integer.")
|
raise SynapseError(400, "'limit' parameter must be an integer.")
|
||||||
|
|
||||||
|
if limit is None:
|
||||||
|
limit = default_limit
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return PaginationConfig(from_tok, to_tok, direction, limit)
|
return PaginationConfig(from_tok, to_tok, direction, limit)
|
||||||
except:
|
except:
|
||||||
|
Loading…
Reference in New Issue
Block a user