Refactor and implement queueing messages

This commit is contained in:
2025-02-12 18:45:21 +00:00
parent 213df9176e
commit 018d2f87c7
23 changed files with 804 additions and 338 deletions

20
core/messaging/utils.py Normal file
View File

@@ -0,0 +1,20 @@
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)()