fix: chat read limit failing on chats with empty or non-text messages

With a chat read limit set, reading an imported chat that held empty or non-text message content ended in an error instead of the chat. Such content is now counted and cut as plain text.
This commit is contained in:
Classic298 2026-11-03 19:48:29 +01:00
parent 4e21ddc8d8
commit e288cdc470

View file

@ -1752,13 +1752,13 @@ async def view_chat(
truncation = {}
max_chars = await Config.get('chats.view_max_chars')
if max_chars and sum(len(message['content']) for message in messages) > max_chars:
if max_chars and sum(len(str(message['content'] or '')) for message in messages) > max_chars:
remaining_chars = max_chars
kept_messages = []
for message in messages:
if remaining_chars <= 0:
break
content = message['content'][:remaining_chars]
content = str(message['content'] or '')[:remaining_chars]
kept_messages.append({**message, 'content': content})
remaining_chars -= len(content)
truncation = {