20 lines
676 B
Python
20 lines
676 B
Python
from asgiref.sync import sync_to_async
|
|
from django.utils import timezone
|
|
|
|
|
|
def messages_to_string(messages: list):
|
|
"""
|
|
Converts message objects to a formatted string, showing custom_author if set.
|
|
"""
|
|
message_texts = [
|
|
f"[{msg.ts}] <{msg.custom_author if msg.custom_author else msg.session.identifier.person.name}> {msg.text}"
|
|
for msg in messages
|
|
]
|
|
return "\n".join(message_texts)
|
|
|
|
async def update_last_interaction(session):
|
|
now = timezone.now()
|
|
session.identifier.person.last_interaction = now
|
|
session.last_interaction = now
|
|
await sync_to_async(session.identifier.person.save)()
|
|
await sync_to_async(session.save)() |