Ejemplo n.º 1
0
 public function sendNotificationForNewMessage(Conversation $conversation, Message $message)
 {
     $send_to = $conversation->withUser($message->getFromUser());
     if (!$send_to->hasSendNotifications()) {
         // dont send if the user unchecked the "notify" setting on the profile form
         return;
     }
     $this->sendEmail($send_to, 'You received a new message', 'email/new-message.twig', ['message_from' => $message->getFromUser()->getName(), 'message_link' => $this->urlGenerator->generate('conversation.view', ['conversation_id' => $conversation->getId()], UrlGeneratorInterface::ABSOLUTE_URL)]);
 }
Ejemplo n.º 2
0
 public function createAction(Application $app, Request $request)
 {
     $user = $app['session']->get('user');
     $form = $app['form.factory']->create(new ConversationStartForm());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $form_data = $form->getData();
         if (!($to_user = $app['user.manager']->fetchUserById($form_data['to']))) {
             throw new UserNotFoundException();
         }
         $conversation = Conversation::startNew($user, $to_user, $form_data['subject'], $form_data['body']);
         $app['conversation_repository']->save($conversation);
         return $app->redirect($app['url_generator']->generate('conversation.view', ['conversation_id' => $conversation->getId()]));
     }
     // TODO: make a view that allows you to see / edit errors
     $app['session']->getFlashBag()->add('danger', 'A problem occurred when trying to send your message. Please try again.');
     return $app->redirect($app['url_generator']->generate('conversation.index'));
 }
Ejemplo n.º 3
0
 /**
  * @return Conversation
  */
 protected function createSimpleConversation()
 {
     $conversation = Conversation::startNew(\Mockery::mock('Mentoring\\User\\User'), \Mockery::mock('Mentoring\\User\\User'), 'My subject', 'My opening message');
     return $conversation;
 }
Ejemplo n.º 4
0
 protected function hydrateConversation(array $convo_data)
 {
     $messages_data = $this->dbal->fetchAll('SELECT * FROM messages WHERE conversation_id = :conversation_id', ['conversation_id' => $convo_data['id']]);
     $messages = [];
     foreach ($messages_data as $message_data) {
         $messages[] = $message = new Message($this->userService->fetchUserById($message_data['from_user_id']), $message_data['body'], new \DateTime($message_data['created_at']));
         $message->setId($message_data['id']);
         if ($message_data['is_read']) {
             $message->markRead();
         }
     }
     $conversation = new Conversation($this->userService->fetchUserById($convo_data['from_user_id']), $this->userService->fetchUserById($convo_data['to_user_id']), $convo_data['subject'], $messages[0]);
     $conversation->setId($convo_data['id']);
     foreach ($messages as $message) {
         $conversation->addMessage($message);
     }
     $this->in_memory_convos[$conversation->getId()] = $conversation;
     return $conversation;
 }