Commit abbb06ba authored by Mat's avatar Mat

chathub, le case /history

parent b4ad93d7
......@@ -105,7 +105,8 @@ class ChatHub implements MessageComponentInterface
*
* @param \Ratchet\ConnectionInterface $from The socket/connection that sent the message to your application
* @param string $msg The message received
* @throws \Exception
* @return string
* @throws \Twig\Error\Error
*/
function onMessage(ConnectionInterface $from, $msg)
{
......@@ -134,11 +135,27 @@ class ChatHub implements MessageComponentInterface
break;
case '/history':
// récupère le destinataire
$dest = $data->dest;
// appelle getUser
$username = $this->getUser($token);
// récupère l'historique des messages entre les 2 utilisateurs
$messageRepo = $this->getDoctrine()->getManager()->getRepository(Message::class);
$messageRepo->
$messages = $messageRepo->getHistory($username, $dest);
// passe l'historique dans le fragment twig
$twig = $this->container->get('templating');
$fragment = $twig->render('@Socket/Chat/usersHistory.html.twig', array(
'messages' => $messages
));
// retourne le fragment en json
return json_encode(array(
'action' => 'refreseh_messages',
'view' => $fragment
));
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment