Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Reaction.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Message
;
4
5
use
Bitrix\Im\Model\MessageViewedTable
;
6
use Bitrix\Im\V2\Common\ContextCustomer;
7
use
Bitrix\Im\V2\Message
;
8
use
Bitrix\Main\ArgumentException
;
9
use
Bitrix\Main\Type\DateTime
;
10
11
class
Reaction
12
{
13
use ContextCustomer;
14
15
public
const
LIKE
=
'LIKE'
;
16
17
private
const
ALLOWED_REACTION = [self::LIKE];
18
19
protected
string
$reaction
;
20
21
public
function
__construct
(
string
$reaction)
22
{
23
if
(!in_array($reaction, self::ALLOWED_REACTION,
true
))
24
{
25
throw
new
ArgumentException
(
'This reaction not found'
,
'$reaction'
);
26
}
27
28
$this->reaction = $reaction;
29
}
30
31
public
function
addToMessage
(
Message
$message): void
32
{
33
$dateCreate =
new
DateTime
();
34
35
$insertFields = [
36
'USER_ID'
=> $this->getContext()->getUserId(),
37
'CHAT_ID'
=> $message->
getChatId
(),
38
'MESSAGE_ID'
=> $message->
getMessageId
(),
39
'DATE_CREATE'
=> $dateCreate,
40
'REACTION'
=> $this->reaction,
41
];
42
43
$updateFields = [
44
'REACTION'
=> $this->reaction
45
];
46
47
MessageViewedTable::merge($insertFields, $updateFields, [
'USER_ID'
,
'CHAT_ID'
,
'MESSAGE_ID'
]);
48
49
//todo send push
50
}
51
52
public
function
deleteFromMessage
(
Message
$message): void
53
{
54
$readObject = MessageViewedTable::query()
55
->where(
'USER_ID'
, $this->getContext()->getUserId())
56
->where(
'MESSAGE_ID'
, $message->
getMessageId
())
57
->fetchObject()
58
;
59
60
if
($readObject ===
null
)
61
{
62
return
;
63
}
64
65
$readObject->setReaction(
null
);
66
//todo send push
67
}
68
}
Bitrix\Im\Model\MessageViewedTable
Definition
messageviewed.php:45
Bitrix\Im\V2\Message\Reaction
Definition
Reaction.php:12
Bitrix\Im\V2\Message\Reaction\__construct
__construct(string $reaction)
Definition
Reaction.php:21
Bitrix\Im\V2\Message\Reaction\$reaction
string $reaction
Definition
Reaction.php:19
Bitrix\Im\V2\Message\Reaction\addToMessage
addToMessage(Message $message)
Definition
Reaction.php:31
Bitrix\Im\V2\Message\Reaction\LIKE
const LIKE
Definition
Reaction.php:15
Bitrix\Im\V2\Message\Reaction\deleteFromMessage
deleteFromMessage(Message $message)
Definition
Reaction.php:52
Bitrix\Im\V2\Message
Definition
Message.php:44
Bitrix\Im\V2\Message\getChatId
getChatId()
Definition
Message.php:867
Bitrix\Im\V2\Message\getMessageId
getMessageId()
Definition
Message.php:816
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Im\V2\Message
Definition
AdditionalMessagePopupItem.php:3
modules
im
lib
V2
Message
Reaction.php
Создано системой
1.10.0