Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Reaction.php
1<?php
2
4
6use Bitrix\Im\V2\Common\ContextCustomer;
10
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}
__construct(string $reaction)
Definition Reaction.php:21
addToMessage(Message $message)
Definition Reaction.php:31
deleteFromMessage(Message $message)
Definition Reaction.php:52