/** * Sends a message to a conversation * * @param Player $from The sender * @param Conversation $to The conversation that will receive the message * @param Form $form The message's form * @param Form $form The form before it handled the request * @param Form $cloned * @throws HTTPException Thrown if the user doesn't have the * SEND_PRIVATE_MSG permission * @return void */ private function sendMessage(Player $from, Conversation $to, &$form, $cloned) { if (!$from->hasPermission(Permission::SEND_PRIVATE_MSG)) { throw new ForbiddenException("You are not allowed to send messages"); } $message = $form->get('message')->getData(); $message = $to->sendMessage($from, $message); $this->getFlashBag()->add('success', "Your message was sent successfully"); // Let javascript know the message's ID $this->attributes->set('id', $message->getId()); // Reset the form $form = $cloned; // Notify everyone that we sent a new message $event = new NewMessageEvent($message, false); $this->dispatch(Events::MESSAGE_NEW, $event); }