16 private const ADD_ANCHOR_EVENT =
'addAnchor';
17 private const DELETE_ANCHOR_EVENT =
'deleteAnchor';
18 private const DELETE_CHAT_ANCHORS_EVENT =
'deleteChatAnchors';
19 private const DELETE_ALL_ANCHORS_EVENT =
'deleteAllAnchors';
23 foreach ($anchorCollection as $anchorItem)
25 $this->send(self::ADD_ANCHOR_EVENT, $anchorItem);
31 $this->send(self::ADD_ANCHOR_EVENT, $anchorItem);
36 foreach ($anchorCollection as $anchorItem)
38 $this->
delete($anchorItem);
44 $this->send(self::DELETE_ANCHOR_EVENT, $anchorItem);
49 if (!Loader::includeModule(
'pull'))
58 $this->deleteByPrivateChat($chatId,
$userId);
64 'dialogId' => $chat->getDialogId(),
71 'command' => static::DELETE_CHAT_ANCHORS_EVENT,
72 'params' => $parameters,
81 if (!Loader::includeModule(
'pull'))
88 'command' => static::DELETE_ALL_ANCHORS_EVENT,
89 'params' => [
'userId' =>
$userId],
96 private function send(
string $eventName,
AnchorItem $anchorItem): void
98 if (!Loader::includeModule(
'pull'))
105 $parameters = [...$anchorItem->toRestFormat()];
109 $this->sendToPrivateChat($parameters, $eventName, $anchorItem);
114 $parameters[
'dialogId'] = $chat->getDialogId();
117 'command' => $eventName,
118 'params' => $parameters,
122 Event::add([$anchorItem->
getUserId()], $pull);
125 private function sendToPrivateChat(
array $parameters,
string $eventName, AnchorItem $anchorItem): void
130 $recipientId = $anchorItem->getUserId();
132 $parameters[
'dialogId'] = $chat->getCompanion($recipientId)->getId();
133 Event::add($recipientId, [
135 'command' => $eventName,
136 'params' => $parameters,
141 private function deleteByPrivateChat(
int $chatId,
int $userId): void
147 'dialogId' => $chat->getCompanion(
$userId)->getId(),
154 'command' => static::DELETE_CHAT_ANCHORS_EVENT,
155 'params' => $parameters,