fix: system messages go to project chat (visible in ChatPanel)
Some checks failed
Deploy Tracker / deploy (push) Failing after 1s
Some checks failed
Deploy Tracker / deploy (push) Failing after 1s
This commit is contained in:
parent
f7ee6d1a7c
commit
b527e19db1
@ -10,7 +10,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||||||
from sqlalchemy.orm import selectinload, joinedload
|
from sqlalchemy.orm import selectinload, joinedload
|
||||||
|
|
||||||
from tracker.database import get_db
|
from tracker.database import get_db
|
||||||
from tracker.models import Task, Step, Project, Member, Message
|
from tracker.models import Task, Step, Project, Member, Message, Chat
|
||||||
|
|
||||||
router = APIRouter(tags=["tasks"])
|
router = APIRouter(tags=["tasks"])
|
||||||
|
|
||||||
@ -81,9 +81,24 @@ class AssignRequest(BaseModel):
|
|||||||
# --- Helpers ---
|
# --- Helpers ---
|
||||||
|
|
||||||
async def _system_message(db: AsyncSession, task: Task, content: str, project_slug: str = ""):
|
async def _system_message(db: AsyncSession, task: Task, content: str, project_slug: str = ""):
|
||||||
"""Create a system message for a task and broadcast it via WS."""
|
"""Create a system message for a task and broadcast it via WS.
|
||||||
|
|
||||||
|
Message goes to the project chat (visible in ChatPanel) with task_id reference.
|
||||||
|
"""
|
||||||
from tracker.ws.manager import manager
|
from tracker.ws.manager import manager
|
||||||
|
|
||||||
|
# Find project chat
|
||||||
|
chat_id = None
|
||||||
|
if task.project_id:
|
||||||
|
result = await db.execute(
|
||||||
|
select(Chat).where(Chat.project_id == task.project_id, Chat.kind == "project")
|
||||||
|
)
|
||||||
|
chat = result.scalar_one_or_none()
|
||||||
|
if chat:
|
||||||
|
chat_id = chat.id
|
||||||
|
|
||||||
msg = Message(
|
msg = Message(
|
||||||
|
chat_id=chat_id,
|
||||||
task_id=task.id,
|
task_id=task.id,
|
||||||
author_type="system",
|
author_type="system",
|
||||||
author_slug="system",
|
author_slug="system",
|
||||||
@ -96,15 +111,17 @@ async def _system_message(db: AsyncSession, task: Task, content: str, project_sl
|
|||||||
prefix = project_slug[:2].upper() if project_slug else "XX"
|
prefix = project_slug[:2].upper() if project_slug else "XX"
|
||||||
key = f"{prefix}-{task.number}"
|
key = f"{prefix}-{task.number}"
|
||||||
|
|
||||||
await manager.broadcast_task_event(str(task.project_id), "message.new", {
|
event_data = {
|
||||||
"id": str(msg.id),
|
"id": str(msg.id),
|
||||||
|
"chat_id": str(chat_id) if chat_id else None,
|
||||||
"task_id": str(task.id),
|
"task_id": str(task.id),
|
||||||
"task_key": key,
|
"task_key": key,
|
||||||
"author_type": "system",
|
"author_type": "system",
|
||||||
"author_slug": "system",
|
"author_slug": "system",
|
||||||
"content": content,
|
"content": content,
|
||||||
"created_at": msg.created_at.isoformat() if msg.created_at else "",
|
"created_at": msg.created_at.isoformat() if msg.created_at else "",
|
||||||
})
|
}
|
||||||
|
await manager.broadcast_task_event(str(task.project_id), "message.new", event_data)
|
||||||
|
|
||||||
|
|
||||||
def _task_out(t: Task, project_slug: str = "") -> dict:
|
def _task_out(t: Task, project_slug: str = "") -> dict:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user