Refactor and implement queueing messages
This commit is contained in:
20
core/messaging/utils.py
Normal file
20
core/messaging/utils.py
Normal 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)()
|
||||
Reference in New Issue
Block a user