|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
|
7
|
|
|
* This source file is subject to the MIT license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Miliooo\Messaging\Builder\Message; |
|
12
|
|
|
|
|
13
|
|
|
use Miliooo\Messaging\Builder\Model\ReplyBuilderModel; |
|
14
|
|
|
use Miliooo\Messaging\Model\ThreadInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Builder for reply messages |
|
18
|
|
|
* |
|
19
|
|
|
* @author Michiel Boeckaert <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ReplyBuilder extends AbstractMessageBuilder implements ReplyBuilderInterface |
|
22
|
|
|
{ |
|
23
|
|
|
protected $builderModel; |
|
24
|
|
|
protected $sender; |
|
25
|
|
|
protected $recipients; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var ThreadInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $thread; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Builds a new thread object with a reply message |
|
34
|
|
|
* |
|
35
|
|
|
* @param ReplyBuilderModel $builderModel |
|
36
|
|
|
* |
|
37
|
|
|
* @return ThreadInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
public function build(ReplyBuilderModel $builderModel) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->builderModel = $builderModel; |
|
42
|
|
|
$this->sender = $this->builderModel->getSender(); |
|
43
|
|
|
$this->thread = $this->builderModel->getThread(); |
|
44
|
|
|
$this->recipients = $this->thread->getOtherParticipants($this->sender); |
|
45
|
|
|
$this->buildNewMessage($this->thread); |
|
46
|
|
|
$this->updateReplyThreadMeta(); |
|
47
|
|
|
|
|
48
|
|
|
return $this->thread; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
private function updateReplyThreadMeta() |
|
52
|
|
|
{ |
|
53
|
|
|
//update the thread meta for the sender |
|
54
|
|
|
$senderThreadMeta = $this->thread->getThreadMetaForParticipant($this->sender); |
|
55
|
|
|
$this->updateThreadMetaForSender($senderThreadMeta); |
|
56
|
|
|
|
|
57
|
|
|
//update the thread meta for the recipients |
|
58
|
|
|
foreach ($this->recipients as $recipient) { |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$recipientThreadMeta = $this->thread->getThreadMetaForParticipant($recipient); |
|
61
|
|
|
$this->updateThreadMetaForRecipient($recipientThreadMeta); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|