forked from FriendsOfSymfony/FOSMessageBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.php
74 lines (63 loc) · 1.65 KB
/
Message.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace FOS\MessageBundle\Document;
use FOS\MessageBundle\Model\Message as BaseMessage;
abstract class Message extends BaseMessage
{
/**
* Tells if the message is spam or flood
* This denormalizes Thread.isSpam
*
* @var boolean
*/
protected $isSpam = false;
/**
* The unreadForParticipants array will contain a participant's ID if the
* message is not read by the participant and the message is not spam.
*
* @var array of participant ID's
*/
protected $unreadForParticipants = array();
/**
* @param boolean
* @return null
*/
public function setIsSpam($isSpam)
{
$this->isSpam = (boolean) $isSpam;
}
/**
* DENORMALIZATION
*
* All following methods are relative to denormalization
*/
/**
* Performs denormalization tricks
*/
public function denormalize()
{
$this->doSenderIsRead();
$this->doEnsureUnreadForParticipantsArray();
}
/**
* Ensures that the sender is considered to have read this message
*/
protected function doSenderIsRead()
{
$this->setIsReadByParticipant($this->getSender(), true);
}
/**
* Ensures that the unreadForParticipants array is updated.
*/
protected function doEnsureUnreadForParticipantsArray()
{
$this->unreadForParticipants = array();
if ($this->isSpam) {
return;
}
foreach ($this->metadata as $metadata) {
if (!$metadata->getIsRead()) {
$this->unreadForParticipants[] = $metadata->getParticipant()->getId();
}
}
}
}