fix: use next_batch as fallback sync token for room_messages

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-03-24 16:52:32 +02:00
parent e658f3d2ac
commit ae69ea487c

6
bot.py
View File

@@ -4119,7 +4119,11 @@ class Bot:
if not room: if not room:
return web.json_response({'error': 'room not found (bot not joined?)'}, status=404) return web.json_response({'error': 'room not found (bot not joined?)'}, status=404)
# Use room_messages API to fetch and decrypt # Use room_messages API to fetch and decrypt
resp = await self.client.room_messages(room_id, room.prev_batch or '', limit=limit) start_token = getattr(room, 'prev_batch', '') or ''
if not start_token:
# Get a sync token to use as start
start_token = self.client.next_batch or ''
resp = await self.client.room_messages(room_id, start_token, limit=limit)
messages = [] messages = []
if hasattr(resp, 'chunk'): if hasattr(resp, 'chunk'):
for event in reversed(resp.chunk): for event in reversed(resp.chunk):