6use Bitrix\Im\V2\Common\ContextCustomer;
20 private bool $isBackgroundMode =
true;
21 private int $quotaOfFetchMetadata = 5;
23 public function getCount(
int $chatId, ?
int $startId =
null): int
25 $filter = Query::filter()->where(
'CHAT_ID', $chatId);
27 if (isset($startId) && $startId > 0)
29 $filter->where(
'MESSAGE_ID',
'>=', $startId);
32 return LinkUrlTable::getCount($filter);
41 if ($this->isBackgroundMode)
61 if (!$deleteResult->isSuccess())
63 return $result->addErrors($deleteResult->getErrors());
68 if (!$saveResult->isSuccess())
70 return $result->addErrors($saveResult->getErrors());
82 if (count($urls) === 0)
92 $deleteResult = $urls->
delete();
94 if (!$deleteResult->isSuccess())
99 foreach ($urls as $url)
102 ->setContext($this->context)
107 return $deleteResult;
112 $this->isBackgroundMode = $isBackgroundMode;
119 $this->quotaOfFetchMetadata = $quota;
129 if ($urlCollection->hasUnsaved())
131 $saveResult = $this->
saveUrls($urlCollection);
132 if ($saveResult->isSuccess())
138 $result->addErrors($saveResult->getErrors());
147 return $urls->
save();
152 $urlEntities = LinkUrlTable::query()
162 $urls = \Bitrix\Im\V2\Entity\Url\UrlItem::getUrlsFromText($message->
getMessage());
163 $urlCollection = new \Bitrix\Im\V2\Entity\Url\UrlCollection();
164 $countUrlsWithMetadata = 0;
166 foreach ($urls as $url)
168 $withFetchMetadata = $countUrlsWithMetadata < $this->quotaOfFetchMetadata;
169 $urlCollection[] = new \Bitrix\Im\V2\Entity\Url\UrlItem($url, $withFetchMetadata);
170 $countUrlsWithMetadata++;
173 return UrlCollection::linkEntityToMessage($urlCollection, $message);
178 foreach ($urls as $url)
180 $recipient = $url->getEntity()->getRichData()->getAllowedUsers();
181 if ($recipient ===
null)
184 ->setContext($this->context)
185 ->sendFull($url, self::ADD_URL_EVENT, [
'CHAT_ID' => $url->getChatId()])
191 ->setContext($this->context)
192 ->sendFull($url, self::ADD_URL_EVENT, [
'RECIPIENT' => $recipient])
save(bool $isGroupSave=false)
fillMetadata(bool $withHtml=true)
initUrlsByMessage(Message $message)
deleteUrls(UrlCollection $urls)
saveUrlsFromMessage(Message $message)
setBackgroundMode(bool $isBackgroundMode)
sendAddPush(UrlCollection $urls)
saveUrls(UrlCollection $urls)
saveUrlsFromMessageInternal(Message $message)
getCount(int $chatId, ?int $startId=null)
getUrlsByMessage(Message $message)
deleteUrlsByMessage(Message $message)
setQuotaOfFetchMetadata(int $quota)
updateUrlsFromMessage(Message $message)