From 516b74068b7e08c81e59a969ee97855113fd26df Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 15 Dec 2025 23:28:36 -0700 Subject: [PATCH] linting & fix tests --- synapse/rest/admin/media.py | 14 ++++++++------ tests/rest/admin/test_media.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/synapse/rest/admin/media.py b/synapse/rest/admin/media.py index ed809dca3e..14627fc8db 100644 --- a/synapse/rest/admin/media.py +++ b/synapse/rest/admin/media.py @@ -319,18 +319,18 @@ class ListQuarantinedMedia(RestServlet): ) start_ts = 0 - #start_index = 0 - if '-' in start: # indicates we have a next_batch token + start_index = 0 + if "-" in start: # indicates we have a next_batch token # Batch tokens are structured as `timestamp-index`, where `index` is relative # to the timestamp. This is done to support pages having many records with # the same timestamp (like existing servers having a ton of `ts=0` records). # # Dev note: The structure of the `from` token is partially documented in the # admin API. Do not change the behaviour without consulting the docs. - parts = start.split('-', maxsplit=1) + parts = start.split("-", maxsplit=1) start_ts = int(parts[0]) start_index = int(parts[1]) - else: + elif len(start) > 0: start_index = int(start) mxcs_with_ts = await self.store.get_quarantined_media_mxcs_and_timestamps( @@ -338,12 +338,14 @@ class ListQuarantinedMedia(RestServlet): ) res: JsonDict = { - "media": (mxc for mxc, _ in mxcs_with_ts), + "media": [mxc for mxc, _ in mxcs_with_ts], } if len(mxcs_with_ts) > 0: max_ts = mxcs_with_ts[-1][1] if mxcs_with_ts else 0 - count_of_max_ts = sum(1 for _, ts in mxcs_with_ts if ts == max_ts) + count_of_max_ts = ( + sum(1 for _, ts in mxcs_with_ts if ts == max_ts) + start_index + ) res["next_batch"] = f"{max_ts}-{count_of_max_ts}" return HTTPStatus.OK, res diff --git a/tests/rest/admin/test_media.py b/tests/rest/admin/test_media.py index 89b00380e9..37882ce4bd 100644 --- a/tests/rest/admin/test_media.py +++ b/tests/rest/admin/test_media.py @@ -906,7 +906,7 @@ class ListQuarantinedMediaTestCase(_AdminMediaTests): ) self.assertEqual(200, channel.code, msg=channel.json_body) self.assertEqual(0, len(channel.json_body["media"])) - self.assertNone(channel.json_body["next_batch"]) + self.assertNotIn("next_batch", channel.json_body) class QuarantineMediaByIDTestCase(_AdminMediaTests):