diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Group.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Group.php index 0a3463dd..4dcfbb5f 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Group.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Group.php @@ -153,7 +153,7 @@ class Group * @var ArrayCollection $message * @var Message * - * @ORM\OneToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="user", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="group", cascade={"persist"}, orphanRemoval=true) */ protected $messages; diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php index 77c8882c..fd550b54 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php @@ -260,7 +260,12 @@ class User implements UserInterface, \Serializable * @ORM\OneToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="user", cascade={"persist"}, orphanRemoval=true) */ private $messages; - + + /** + * @ORM\ManyToMany(targetEntity="Cadoles\WebsocketBundle\Entity\Message", mappedBy="readers") + */ + protected $messagereaders; + //== CODE A NE PAS REGENERER /** @@ -1382,4 +1387,38 @@ class User implements UserInterface, \Serializable { return $this->messages; } + + /** + * Add messagereader + * + * @param \Cadoles\WebsocketBundle\Entity\Message $messagereader + * + * @return User + */ + public function addMessagereader(\Cadoles\WebsocketBundle\Entity\Message $messagereader) + { + $this->messagereaders[] = $messagereader; + + return $this; + } + + /** + * Remove messagereader + * + * @param \Cadoles\WebsocketBundle\Entity\Message $messagereader + */ + public function removeMessagereader(\Cadoles\WebsocketBundle\Entity\Message $messagereader) + { + $this->messagereaders->removeElement($messagereader); + } + + /** + * Get messagereaders + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getMessagereaders() + { + return $this->messagereaders; + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css index d55535d7..3cc6cd67 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css @@ -100,6 +100,10 @@ body { font-size: 35px; } +.navbar-top-links li a .badge { + margin-left: 10px; +} + @media (max-width: 767px) { .navbar-default .navbar-header #title { display: none; diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/base.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/base.html.twig index 282d47bc..def1f202 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/base.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/base.html.twig @@ -152,7 +152,7 @@ {% block localexternalscript %} {% endblock %} - + + + {% endif %} {% endblock %} {% block localjavascript %} @@ -235,7 +267,55 @@ responsive: true, iDisplayLength: 10, order: [[ 1, "asc" ]], - }); + }); + + // Init socket de counter + var _WS_URI = "wss://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}"; + var _WS_URI = "wss://{{ gos_web_socket_server_host }}:5555"; + + var webSocket = WS.connect(_WS_URI); + var globalsession; + + webSocket.on("socket/connect", function (session) { + globalsession=session; + session.call("websocket/rpc/update_connection_data", {"userid": "{{app.user.id}}" }).then( + function (result) + { + //console.log("RPC Valid!", result); + }, + function (error, desc) + { + //console.log("RPC Error", error, desc); + } + ); + + // The callback function in "subscribe" is called everytime an event is published in that channel. + session.subscribe("websocket/counter", function (uri, payload) { + if(payload.log) { + console.log("Received message", payload.log); + } + if(payload.alert) { + alert(payload.alert); + } + if(payload.from!={{app.user.id}}) { + menu=$("a[data-group='"+payload.group+"']"); + if(menu.length) { + if(payload.add) { + console.log("Ajout counter pour group "+payload.group+" by "+payload.from); + if(menu.children(".badge").length) { + menu.children(".badge").html(+(menu.children(".badge").html())+1); + } + else menu.append("1"); + // Détruire le badge associé car normalement de fait on a lu les notif + if(usage=="group") { + $("#badge-"+groupid).remove() + } + // Cacher les actions possibles sur la page $("#menuupdate").hide(); @@ -377,4 +462,9 @@ $(location).attr('href', url); }; + // Permet de déclencher l'évenement de modification des counter + function counter(event) { + $('#refreshcounter').data("event",event); + $('#refreshcounter').click(); + }; {% endblock %} diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php index b3d98772..88089007 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Controller/ChatController.php @@ -74,6 +74,7 @@ class ChatController extends Controller 'border' => $border, 'colorbodyback' => $colorbodyback, 'colorbodyfont' => $colorbodyfont, + 'fgmanager' => ($usergroup->getFgmanager()||$user->getRole()=="ROLE_ADMIN"||$user->getRole()=="ROLE_MODO"), 'form' => $form->createView() ]); } diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Entity/Message.php b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Entity/Message.php index 94c467c5..3de5d076 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Entity/Message.php +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Entity/Message.php @@ -40,6 +40,17 @@ class Message */ private $group; + /** + * @ORM\ManyToMany(targetEntity="Cadoles\CoreBundle\Entity\User", inversedBy="messagereaders", cascade={"persist"}) + * @ORM\JoinTable(name="messageuser", + * joinColumns={@ORM\JoinColumn(name="message", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="user", referencedColumnName="id")} + * ) + */ + protected $readers; + + + /** * Constructor */ @@ -155,4 +166,38 @@ class Message { return $this->group; } + + /** + * Add reader + * + * @param \Cadoles\CoreBundle\Entity\User $reader + * + * @return Message + */ + public function addReader(\Cadoles\CoreBundle\Entity\User $reader) + { + $this->readers[] = $reader; + + return $this; + } + + /** + * Remove reader + * + * @param \Cadoles\CoreBundle\Entity\User $reader + */ + public function removeReader(\Cadoles\CoreBundle\Entity\User $reader) + { + $this->readers->removeElement($reader); + } + + /** + * Get readers + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getReaders() + { + return $this->readers; + } } diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/RPC/RPCService.php b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/RPC/RPCService.php index 2af3d867..fe14c55b 100755 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/RPC/RPCService.php +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/RPC/RPCService.php @@ -21,6 +21,7 @@ class RPCService implements RpcInterface { */ public function updateConnectionData(ConnectionInterface $connection, WampRequest $request, $params) { $connection->userkey = $params['userkey']; + $connection->userid = $params['userid']; return array("result" => array_sum($params)); } diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/services.yml b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/services.yml index b08c02ba..afd6cf98 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/services.yml +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/services.yml @@ -5,6 +5,12 @@ services: tags: - { name: gos_web_socket.topic } + cadoles.websocket.counter: + class: Cadoles\WebsocketBundle\Topic\WebsocketCounter + arguments: ['@gos_web_socket.websocket.client_manipulator','@doctrine.orm.entity_manager','@service_container'] + tags: + - { name: gos_web_socket.topic } + cadoles.websocket.rpc: class: Cadoles\WebsocketBundle\RPC\RPCService tags: diff --git a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/topic.yml b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/topic.yml index 5a2b9dee..571f1e34 100644 --- a/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/topic.yml +++ b/src/ninegate-1.0/src/Cadoles/WebsocketBundle/Resources/config/topic.yml @@ -6,6 +6,11 @@ websocket_topic: group: pattern: '[-+]?\d+' +websocket_counter: + channel: websocket/counter + handler: + callback: 'websocket.counter' + websocket_rpc: channel: websocket/rpc/{method} handler: 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 b8e9c08c..c3731080 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 @@ -26,6 +26,7 @@ .msgavatar { float:left; height:40px; + text-align: center; } .msgdiv { float:left; @@ -52,7 +53,9 @@