Skip to content
Snippets Groups Projects
Commit d57481de authored by Antoine Gaudron-Desjardins's avatar Antoine Gaudron-Desjardins
Browse files

change websocket message structure

parent 409de85d
Branches
No related tags found
1 merge request!40Websocket
Pipeline #44141 passed with warnings
......@@ -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
......
......@@ -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;
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment