-
Notifications
You must be signed in to change notification settings - Fork 183
/
Sender.php
60 lines (52 loc) · 1.65 KB
/
Sender.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Ornicar\MessageBundle\Sender;
use Ornicar\MessageBundle\ModelManager\MessageManagerInterface;
use Ornicar\MessageBundle\ModelManager\ThreadManagerInterface;
use Ornicar\MessageBundle\Model\MessageInterface;
use Ornicar\MessageBundle\Event\MessageEvent;
use Ornicar\MessageBundle\Event\OrnicarMessageEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Sends messages
*
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
*/
class Sender implements SenderInterface
{
/**
* The message manager
*
* @var MessageManagerInterface
*/
protected $messageManager;
/**
* The thread manager
*
* @var ThreadManagerInterface
*/
protected $threadManager;
/**
* The event dispatcher
*
* @var EventDispatcherInterface
*/
protected $dispatcher;
public function __construct(MessageManagerInterface $messageManager, ThreadManagerInterface $threadManager, EventDispatcherInterface $dispatcher)
{
$this->messageManager = $messageManager;
$this->threadManager = $threadManager;
$this->dispatcher = $dispatcher;
}
/**
* Sends the message by persisting it to the message manager and undeletes the thread for all participants
*
* @param MessageInterface $message
*/
public function send(MessageInterface $message)
{
$this->threadManager->saveThread($message->getThread(), false);
$this->messageManager->saveMessage($message);
$message->getThread()->setIsDeleted(false);
$this->dispatcher->dispatch(OrnicarMessageEvents::POST_SEND, new MessageEvent($message));
}
}