Skip to content

Commit 516b740

Browse files
committed
linting & fix tests
1 parent ad230c4 commit 516b740

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

synapse/rest/admin/media.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,31 +319,33 @@ async def on_GET(
319319
)
320320

321321
start_ts = 0
322-
#start_index = 0
323-
if '-' in start: # indicates we have a next_batch token
322+
start_index = 0
323+
if "-" in start: # indicates we have a next_batch token
324324
# Batch tokens are structured as `timestamp-index`, where `index` is relative
325325
# to the timestamp. This is done to support pages having many records with
326326
# the same timestamp (like existing servers having a ton of `ts=0` records).
327327
#
328328
# Dev note: The structure of the `from` token is partially documented in the
329329
# admin API. Do not change the behaviour without consulting the docs.
330-
parts = start.split('-', maxsplit=1)
330+
parts = start.split("-", maxsplit=1)
331331
start_ts = int(parts[0])
332332
start_index = int(parts[1])
333-
else:
333+
elif len(start) > 0:
334334
start_index = int(start)
335335

336336
mxcs_with_ts = await self.store.get_quarantined_media_mxcs_and_timestamps(
337337
start_ts, start_index, limit, local_or_remote == "local"
338338
)
339339

340340
res: JsonDict = {
341-
"media": (mxc for mxc, _ in mxcs_with_ts),
341+
"media": [mxc for mxc, _ in mxcs_with_ts],
342342
}
343343

344344
if len(mxcs_with_ts) > 0:
345345
max_ts = mxcs_with_ts[-1][1] if mxcs_with_ts else 0
346-
count_of_max_ts = sum(1 for _, ts in mxcs_with_ts if ts == max_ts)
346+
count_of_max_ts = (
347+
sum(1 for _, ts in mxcs_with_ts if ts == max_ts) + start_index
348+
)
347349
res["next_batch"] = f"{max_ts}-{count_of_max_ts}"
348350

349351
return HTTPStatus.OK, res

tests/rest/admin/test_media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def _quarantine(media_id: str) -> None:
906906
)
907907
self.assertEqual(200, channel.code, msg=channel.json_body)
908908
self.assertEqual(0, len(channel.json_body["media"]))
909-
self.assertNone(channel.json_body["next_batch"])
909+
self.assertNotIn("next_batch", channel.json_body)
910910

911911

912912
class QuarantineMediaByIDTestCase(_AdminMediaTests):

0 commit comments

Comments
 (0)