1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Message\Lib; |
6
|
|
|
|
7
|
|
|
use Stu\Module\PlayerSetting\Lib\UserEnum; |
8
|
|
|
use Stu\Orm\Entity\ContactInterface; |
9
|
|
|
use Stu\Orm\Entity\PrivateMessageInterface; |
10
|
|
|
use Stu\Orm\Entity\UserInterface; |
11
|
|
|
use Stu\Orm\Repository\ContactRepositoryInterface; |
12
|
|
|
use Stu\Orm\Repository\IgnoreListRepositoryInterface; |
13
|
|
|
use Stu\Orm\Repository\PrivateMessageRepositoryInterface; |
14
|
|
|
|
15
|
|
|
final class PrivateMessageListItem implements PrivateMessageListItemInterface |
16
|
|
|
{ |
17
|
|
|
private PrivateMessageRepositoryInterface $privateMessageRepository; |
18
|
|
|
|
19
|
|
|
private ContactRepositoryInterface $contactRepository; |
20
|
|
|
|
21
|
|
|
private IgnoreListRepositoryInterface $ignoreListRepository; |
22
|
|
|
|
23
|
|
|
private PrivateMessageInterface $message; |
24
|
|
|
|
25
|
|
|
private int $currentUserId; |
26
|
|
|
|
27
|
|
|
private ?UserInterface $sender = null; |
28
|
|
|
|
29
|
|
|
private ?bool $senderignore = null; |
30
|
|
|
|
31
|
|
|
private ?ContactInterface $sendercontact = null; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
PrivateMessageRepositoryInterface $privateMessageRepository, |
35
|
|
|
ContactRepositoryInterface $contactRepository, |
36
|
|
|
IgnoreListRepositoryInterface $ignoreListRepository, |
37
|
|
|
PrivateMessageInterface $message, |
38
|
|
|
int $currentUserId |
39
|
|
|
) { |
40
|
|
|
$this->privateMessageRepository = $privateMessageRepository; |
41
|
|
|
$this->contactRepository = $contactRepository; |
42
|
|
|
$this->ignoreListRepository = $ignoreListRepository; |
43
|
|
|
$this->message = $message; |
44
|
|
|
$this->currentUserId = $currentUserId; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getSender(): UserInterface |
48
|
|
|
{ |
49
|
|
|
if ($this->sender === null) { |
50
|
|
|
$this->sender = $this->message->getSender(); |
51
|
|
|
} |
52
|
|
|
return $this->sender; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getDate(): int |
56
|
|
|
{ |
57
|
|
|
return $this->message->getDate(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function isMarkableAsNew(): bool |
61
|
|
|
{ |
62
|
|
|
if ($this->message->getNew() === false) { |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
$this->message->setNew(false); |
66
|
|
|
|
67
|
|
|
$this->privateMessageRepository->save($this->message); |
68
|
|
|
|
69
|
|
|
return true; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function isMarkableAsReceipt(): bool |
73
|
|
|
{ |
74
|
|
|
if ($this->message->getInboxPmId() === null) { |
75
|
|
|
return false; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (!$this->message->getSender()->isShowPmReadReceipt() || !$this->message->getRecipient()->isShowPmReadReceipt()) { |
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$inboxPm = $this->privateMessageRepository->find($this->message->getInboxPmId()); |
83
|
|
|
|
84
|
|
|
if ($inboxPm === null) { |
85
|
|
|
return true; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return !$inboxPm->getNew(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getText(): string |
92
|
|
|
{ |
93
|
|
|
return $this->message->getText(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getHref(): ?string |
97
|
|
|
{ |
98
|
|
|
return $this->message->getHref(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getNew(): bool |
102
|
|
|
{ |
103
|
|
|
return $this->message->getNew(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getId(): int |
107
|
|
|
{ |
108
|
|
|
return $this->message->getId(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function displayUserLinks(): bool |
112
|
|
|
{ |
113
|
|
|
return $this->getSender() && $this->getSender()->getId() !== UserEnum::USER_NOONE; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getReplied(): bool |
117
|
|
|
{ |
118
|
|
|
return $this->message->getReplied(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function senderIsIgnored(): bool |
122
|
|
|
{ |
123
|
|
|
if ($this->senderignore === null) { |
124
|
|
|
$this->senderignore = $this->ignoreListRepository->exists( |
125
|
|
|
$this->currentUserId, |
126
|
|
|
$this->message->getSenderId() |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
return $this->senderignore; |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function senderIsContact(): ?ContactInterface |
133
|
|
|
{ |
134
|
|
|
if ($this->sendercontact === null) { |
135
|
|
|
$this->sendercontact = $this->contactRepository->getByUserAndOpponent( |
136
|
|
|
$this->currentUserId, |
137
|
|
|
$this->message->getSenderId() |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
return $this->sendercontact; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function hasTranslation(): bool |
144
|
|
|
{ |
145
|
|
|
$text = $this->getText(); |
146
|
|
|
return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|