chat,frontend: better chat entry algorithm (wip)
This commit is contained in:
1 parent
92102a235c
commit
5ae94ca513
4 files changed
+325
-114
No files matched your search
@@ -92,17 +92,6 @@ class ChatMixin:
|
||||
# TODO: Stop repetition.
|
||||
# There's db.Message and chat.Message, also should be combined somehow, or wrap db always.
|
||||
return [message_json(msg) for msg in messages]
|
||||
|
||||
async def get_chat_thread_heads(self, chat_id, limit_message_id=None):
|
||||
chat = await self.get_chat(chat_id)
|
||||
messages = await chat.load_thread_heads(limit_message_id)
|
||||
return [message_json(msg) for msg in messages]
|
||||
|
||||
async def get_thread_messages(self, chat_id, thread_id, limit_message_id=None):
|
||||
chat = await self.get_chat(chat_id)
|
||||
thread = chat.get_thread(thread_id)
|
||||
messages = await thread.load_page(limit_message_id)
|
||||
return [message_json(msg) for msg in messages]
|
||||
|
||||
async def create_chat_thread(self, chat_id, parent_id=None, name=None):
|
||||
if tmp.is_tmp_id(chat_id):
|
||||
@@ -116,6 +105,29 @@ class ChatMixin:
|
||||
print(f"Created thread #{thread.id}: {thread.name}")
|
||||
return thread.id
|
||||
|
||||
async def get_chat_threads(self, chat_id):
|
||||
threads = await db.Thread.filter(chat_id=chat_id).all()
|
||||
return [{
|
||||
'id': it.id,
|
||||
'parentId': it.parent_id,
|
||||
'name': it.name,
|
||||
'description': it.description,
|
||||
'firstMessageId': it.first_message_id,
|
||||
'lastMessageId': it.last_message_id,
|
||||
'messageCount': it.message_count,
|
||||
} for it in threads]
|
||||
|
||||
async def get_thread_messages(self, chat_id, thread_id, limit_message_id=None):
|
||||
chat = await self.get_chat(chat_id)
|
||||
thread = chat.get_thread(thread_id)
|
||||
messages = await thread.load_page(limit_message_id)
|
||||
return [message_json(msg) for msg in messages]
|
||||
|
||||
async def get_chat_thread_heads(self, chat_id, limit_message_id=None):
|
||||
chat = await self.get_chat(chat_id)
|
||||
messages = await chat.load_thread_heads(limit_message_id)
|
||||
return [message_json(msg) for msg in messages]
|
||||
|
||||
async def fork_chat_thread(self, thread_id, message_id=None, name=None):
|
||||
"""Move all messages from message_id onwards into a new child thread.
|
||||
If none is given, this is basically create_chat_thread with an implicit chat id."""
|
||||
@@ -125,6 +137,15 @@ class ChatMixin:
|
||||
if message_id is not None:
|
||||
await db.Message.filter(thread_id=thread_id, id__gte=message_id).update(thread_id=new_id)
|
||||
|
||||
# Notify users. what a heavy operation!
|
||||
|
||||
chat = await db.Chat.get(id=thread.chat_id)
|
||||
messages = await db.Message.filter(thread_id=new_id).all()
|
||||
print("Chat: " + repr(chat))
|
||||
print("Fork message list: " + repr(messages))
|
||||
for msg in messages:
|
||||
self.notify_message_to_user(chat.user_id, msg, True)
|
||||
|
||||
return new_id
|
||||
|
||||
async def add_agent_to_chat(self, chat_id, agent_id):
|
||||
|
||||
Reference in new issue
Block a user