fix: broadcast message.new from REST API via WebSocket
Some checks failed
Deploy Tracker / deploy (push) Failing after 0s
Some checks failed
Deploy Tracker / deploy (push) Failing after 0s
This commit is contained in:
parent
74d9e826bc
commit
a50fd946eb
@ -120,6 +120,41 @@ async def create_message(req: MessageCreate, db: AsyncSession = Depends(get_db))
|
|||||||
select(Message).where(Message.id == msg.id).options(selectinload(Message.attachments))
|
select(Message).where(Message.id == msg.id).options(selectinload(Message.attachments))
|
||||||
)
|
)
|
||||||
msg = result2.scalar_one()
|
msg = result2.scalar_one()
|
||||||
|
|
||||||
|
# Broadcast via WebSocket
|
||||||
|
from tracker.ws.manager import manager
|
||||||
|
msg_data = {
|
||||||
|
"id": str(msg.id),
|
||||||
|
"chat_id": req.chat_id,
|
||||||
|
"task_id": req.task_id,
|
||||||
|
"author_type": msg.author_type,
|
||||||
|
"author_slug": msg.author_slug,
|
||||||
|
"content": msg.content,
|
||||||
|
"mentions": msg.mentions or [],
|
||||||
|
"created_at": msg.created_at.isoformat(),
|
||||||
|
}
|
||||||
|
|
||||||
|
project_id = None
|
||||||
|
if req.chat_id:
|
||||||
|
chat_result = await db.execute(select(Chat).where(Chat.id == uuid.UUID(req.chat_id)))
|
||||||
|
chat = chat_result.scalar_one_or_none()
|
||||||
|
if chat and chat.project_id:
|
||||||
|
project_id = str(chat.project_id)
|
||||||
|
elif chat and chat.kind == "lobby":
|
||||||
|
await manager.broadcast_all(
|
||||||
|
{"type": "message.new", "data": msg_data},
|
||||||
|
exclude=msg.author_slug,
|
||||||
|
)
|
||||||
|
return _message_out(msg)
|
||||||
|
|
||||||
|
if project_id:
|
||||||
|
await manager.broadcast_message(project_id, msg_data, author_slug=msg.author_slug)
|
||||||
|
else:
|
||||||
|
await manager.broadcast_all(
|
||||||
|
{"type": "message.new", "data": msg_data},
|
||||||
|
exclude=msg.author_slug,
|
||||||
|
)
|
||||||
|
|
||||||
return _message_out(msg)
|
return _message_out(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user