diff --git a/backend/routers/comments.py b/backend/routers/comments.py index cdd859918f057d91800741f616988e5794496449..d1b57e921222f275b6482dc331ace73816279833 100644 --- a/backend/routers/comments.py +++ b/backend/routers/comments.py @@ -21,7 +21,7 @@ async def create_comment(place: str, connect_id: str = Cookie(...), comment: sch user = crud.get_user(connect_id, db) if user: saved_comment = crud.create_comment(user, place, comment, db) - await manager.broadcast(json.dumps(saved_comment.dict(), default=str)) + await manager.broadcast(json.dumps({"type": "comment", "comment": saved_comment.dict()}, default=str)) return saved_comment else: raise Exception diff --git a/frontend/src/components/Comments.js b/frontend/src/components/Comments.js index e0a52e00181886f8f4f91b7bec8a2fda5fead7fc..714bec6aeb12f3d677c47252e4a619ec7f8b07a1 100644 --- a/frontend/src/components/Comments.js +++ b/frontend/src/components/Comments.js @@ -117,9 +117,9 @@ export default function Messages({ place, infos, lastMessage }) { useEffect(() => { if (lastMessage?.data) { let new_message = JSON.parse(lastMessage.data); - if (new_message.username != user) { + if (new_message.type == "comment" && new_message.comment.username != user) { setMessages((messages) => { - messages.push(new_message); + messages.push(new_message.comment); return messages; }); }