/** * Update the elastica index when a new message is sent * * @param NewMessageEvent $event The event */ public function onNew(NewMessageEvent $event) { if ($event->isFirst()) { // A new discussion was created, add it to the elasticsearch index $this->groupPersister->insertOne($event->getMessage()->getGroup()); } $this->messagePersister->insertOne($event->getMessage()); }
/** * Called every time a new message is sent * @param NewMessageEvent $event The event */ public function onNewMessage(NewMessageEvent $event) { // Get a list of everyone who can see the message so we can notify them - // the sender of the message is excluded $conversation = $event->getMessage()->getConversation(); $author = $event->getMessage()->getAuthor()->getId(); $recipients = $conversation->getWaitingForEmailIDs($author, !$event->isFirst()); // The websocket will handle emails if it is enabled if (!WebSocketAdapter::isEnabled()) { $this->sendEmails('New message received', $recipients, 'message', array('message' => $event->getMessage())); } $event->getMessage()->getConversation()->markUnread($author); \Notification::pushEvent('message', array('message' => $event->getMessage(), 'recipients' => $recipients)); }