|
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\Event; |
|
12
|
|
|
|
|
13
|
|
|
use Miliooo\Messaging\Model\MessageInterface; |
|
14
|
|
|
use Miliooo\Messaging\Model\MessageMetaInterface; |
|
15
|
|
|
use Miliooo\Messaging\User\ParticipantInterface; |
|
16
|
|
|
use Miliooo\Messaging\Model\ThreadInterface; |
|
17
|
|
|
use Symfony\Component\EventDispatcher\Event; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Model for messages from whom the read status has changed. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Michiel Boeckaert <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ReadStatusMessageEvent extends Event |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* The message from whom the read status has changed. |
|
28
|
|
|
* |
|
29
|
|
|
* @var MessageInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $message; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The participant from whom the read status has changed. |
|
35
|
|
|
* |
|
36
|
|
|
* @var ParticipantInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $participant; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param MessageInterface $message |
|
44
|
|
|
* @param ParticipantInterface $participant |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(MessageInterface $message, ParticipantInterface $participant) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->message = $message; |
|
49
|
|
|
$this->participant = $participant; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Gets the message where the read status has changed. |
|
54
|
|
|
* |
|
55
|
|
|
* @return MessageInterface |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getMessage() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->message; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Gets the thread for the given message. |
|
64
|
|
|
* |
|
65
|
|
|
* @return ThreadInterface |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getThread() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->message->getThread(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Gets the old read status. |
|
74
|
|
|
* |
|
75
|
|
|
* @return integer one of MessageInterface read status constants |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getPreviousReadStatus() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->message->getMessageMetaForParticipant($this->participant)->getPreviousReadStatus(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Gets the new read status. |
|
84
|
|
|
* |
|
85
|
|
|
* @return integer one of MessageInterface read status constants |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getReadStatus() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->message->getMessageMetaForParticipant($this->participant)->getReadStatus(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Returns whether the message has been read for the first time by the given participant. |
|
94
|
|
|
* |
|
95
|
|
|
* @return boolean true if read for the first time, false otherwise |
|
96
|
|
|
*/ |
|
97
|
|
|
public function isFirstTimeRead() |
|
98
|
|
|
{ |
|
99
|
|
|
if ($this->getPreviousReadStatus() === MessageMetaInterface::READ_STATUS_NEVER_READ |
|
|
|
|
|
|
100
|
|
|
&& $this->getReadStatus() === MessageMetaInterface::READ_STATUS_READ) { |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
return true; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return false; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Gets the participant for whom the read status of the message has changed. |
|
110
|
|
|
* |
|
111
|
|
|
* @return ParticipantInterface The participant for whom the message read status has changed. |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getParticipant() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->participant; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|