Continue AI features and improve protocol support
This commit is contained in:
@@ -2,13 +2,26 @@ from asgiref.sync import sync_to_async
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def messages_to_string(messages: list):
|
||||
def messages_to_string(messages: list, author_rewrites: dict | None = None):
|
||||
"""
|
||||
Converts message objects to a formatted string, showing custom_author if set.
|
||||
"""
|
||||
author_rewrites = {
|
||||
str(key).strip().upper(): str(value)
|
||||
for key, value in (author_rewrites or {}).items()
|
||||
}
|
||||
|
||||
def _author_label(message):
|
||||
author = (
|
||||
message.custom_author
|
||||
if message.custom_author
|
||||
else message.session.identifier.person.name
|
||||
)
|
||||
mapped = author_rewrites.get(str(author).strip().upper())
|
||||
return mapped if mapped else author
|
||||
|
||||
message_texts = [
|
||||
f"[{msg.ts}] <{msg.custom_author if msg.custom_author else msg.session.identifier.person.name}> {msg.text}"
|
||||
for msg in messages
|
||||
f"[{msg.ts}] <{_author_label(msg)}> {msg.text}" for msg in messages
|
||||
]
|
||||
return "\n".join(message_texts)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user