예제 #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)]);
 }
예제 #2
0
 public function testStartsAsUnreadAndCanBeMarkedAsRead()
 {
     $fromUser = \Mockery::mock('\\Mentoring\\User\\User');
     $body = 'This is my message';
     $createdAt = new \DateTime();
     $message = new Message($fromUser, $body, $createdAt);
     $this->assertFalse($message->isRead());
     $message->markRead();
     $this->assertTrue($message->isRead());
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * Check to see if this conversation already holds a reference to the given message.
  *
  * @param Message $message
  * @return bool
  */
 public function hasMessage(Message $message)
 {
     foreach ($this->messages as $existing) {
         if ($existing === $message || $existing->getId() && $existing->getId() == $message->getId()) {
             return true;
         }
     }
     return false;
 }