public function findByMessages(User $user, array $messages)
    {
        $messageIds = array();

        foreach ($messages as $message) {
            $messageIds[] = $message->getId();
        }

        $dql = '
            SELECT um
            FROM Claroline\MessageBundle\Entity\UserMessage um
            JOIN um.user u
            JOIN um.message m
            WHERE m.id IN (:messageIds)
            AND u.id = :userId
            ORDER BY m.date DESC
        ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('messageIds', $messageIds);
        $query->setParameter('userId', $user->getId());

        return $query->getResult();
    }