From bf1c7299b13a65381a141539b0dc5a81bbaaaaa7 Mon Sep 17 00:00:00 2001 From: afornerot Date: Wed, 17 Jul 2019 17:06:05 +0200 Subject: [PATCH] svg --- .../Resources/views/Chat/client.html.twig | 43 +++++++++++++++---- .../WebsocketBundle/Topic/WebsocketTopic.php | 40 ++++++++++------- 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig index 4fb12b52..b8e9c08c 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/views/Chat/client.html.twig @@ -49,8 +49,11 @@
{% for message in messages %} -
-
+
+
+
+ +
{{message.user.lastname}} {{message.user.firstname}}
@@ -76,7 +79,6 @@ {% if app.user %} var _WS_URI = "wss://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}"; var _WS_URI = "wss://{{ gos_web_socket_server_host }}:5555"; - console.log(_WS_URI); var webSocket = WS.connect(_WS_URI); @@ -96,30 +98,55 @@ //the callback function in "subscribe" is called everytime an event is published in that channel. session.subscribe("websocket/channel/{{groupid}}", function (uri, payload) { if(payload.msg) { - html ="
"; - html+="
"; + html ="
"; + html+="
"; + html+="
"; + if(payload.msg.userid=={{app.user.id}}) { + html+=""; + } + html+="
"; html+="
" html+="
"+payload.msg.lastname+"
"+new Date(payload.msg.submitdate.date).toLocaleDateString("fr-FR", dateoptions)+"
"; html+="
"+payload.msg.message+"
"; html+="
"; html+="
"; $(".mychat").prepend(html); + + - console.log("Received message", payload.msg); + console.log("Received message by "+payload.msg.userid+" = ",payload.msg); } if(payload.log) { console.log("Received message", payload.log); } + + if(payload.del) { + $("#message-"+payload.del).remove(); + } + + if(payload.alert) { + alert(payload.alert); + } }); $( "#sendbtn" ).click(function() { var data = CKEDITOR.instances["chat_message"].getData(); - if(data) session.publish("websocket/channel/{{groupid}}", data); - CKEDITOR.instances["chat_message"].setData(''); + if(data) { + event={type: "add", message: data}; + session.publish("websocket/channel/{{groupid}}", event); + CKEDITOR.instances["chat_message"].setData(''); + } + }); + $(document).on('click', '.delmessage', function(){ + console.log("suppression"); + id=$(this).data("id"); + event={type: "del", id: id}; + session.publish("websocket/channel/{{groupid}}", event); }); }) {% endif %} }); + {% endblock %} \ No newline at end of file diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php index cca73541..ed9f9ffb 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Topic/WebsocketTopic.php @@ -79,29 +79,39 @@ class WebsocketTopic implements TopicInterface $usergroup=$this->em->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(['keyvalue'=> $userkey]); if(!$usergroup) { - $topic->broadcast(['log' => 'user NOT IN GROUP = '.$userkey]); + $topic->broadcast(['log' => 'user NOT IN GROUP']); } else { $user=$usergroup->getUser(); } if($group&&$usergroup&&$user) { - $message=new Message(); - $message->setTopic($event); - $message->setUser($user); - $message->setGroup($group); - $this->em->persist($message); - $this->em->flush(); + if($event["type"]=="add") { + $message=new Message(); + $message->setTopic($event["message"]); + $message->setUser($user); + $message->setGroup($group); + $this->em->persist($message); + $this->em->flush(); - $return["lastname"]=$user->getLastname()." ".$user->getFirstname(); - $return["avatar"]=$user->getAvatar(); - $return["submitdate"]=$message->getSubmitdate(); - $return["message"]=$event; + $return["id"]=$message->getId(); + $return["lastname"]=$user->getLastname()." ".$user->getFirstname(); + $return["avatar"]=$user->getAvatar(); + $return["submitdate"]=$message->getSubmitdate(); + $return["message"]=$event["message"]; + $return["userid"]=$user->getId(); - //this will broadcast the message to ALL subscribers of this topic. - $topic->broadcast([ - 'msg' => $return, - ]); + //this will broadcast the message to ALL subscribers of this topic. + $topic->broadcast(['msg' => $return]); + } + + if($event["type"]=="del") { + $message=$this->em->getRepository("CadolesWebsocketBundle:Message")->find($event["id"]); + if($message&&($usergroup->getFgmanager()||$message->getUser()==$user)) { + $topic->broadcast(['del' => $message->getId()]); + } + else $topic->broadcast(['log' => "Suppression interdite"]); + } } }