fix: auto-resolve chat_id from task's project for agent messages
Some checks failed
Deploy Tracker / deploy (push) Failing after 3s
Some checks failed
Deploy Tracker / deploy (push) Failing after 3s
This commit is contained in:
parent
f94af46895
commit
f267089f64
@ -87,8 +87,22 @@ async def create_message(req: MessageCreate, request: Request, db: AsyncSession
|
||||
author_id = member.id
|
||||
author_type = member.type
|
||||
|
||||
# Resolve chat_id from task's project if not provided
|
||||
resolved_chat_id = uuid.UUID(req.chat_id) if req.chat_id else None
|
||||
if not resolved_chat_id and req.task_id:
|
||||
from ..models.task import Task
|
||||
task_r = await db.execute(select(Task).where(Task.id == uuid.UUID(req.task_id)))
|
||||
task_obj = task_r.scalar_one_or_none()
|
||||
if task_obj and task_obj.project_id:
|
||||
chat_r = await db.execute(
|
||||
select(Chat).where(Chat.project_id == task_obj.project_id, Chat.kind == ChatKind.PROJECT)
|
||||
)
|
||||
project_chat = chat_r.scalar_one_or_none()
|
||||
if project_chat:
|
||||
resolved_chat_id = project_chat.id
|
||||
|
||||
msg = Message(
|
||||
chat_id=uuid.UUID(req.chat_id) if req.chat_id else None,
|
||||
chat_id=resolved_chat_id,
|
||||
task_id=uuid.UUID(req.task_id) if req.task_id else None,
|
||||
parent_id=uuid.UUID(req.parent_id) if req.parent_id else None,
|
||||
author_type=author_type,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user