5use Bitrix\Im\Model\RelationTable;
6use Bitrix\Im\V2\Chat\OpenLineLiveChat;
7use Bitrix\Im\V2\Entity\User\UserCollection;
8use Bitrix\Im\V2\Entity\User\UserPopupItem;
9use Bitrix\Im\V2\Rest\PopupData;
10use Bitrix\Im\V2\Rest\PopupDataAggregatable;
11use Bitrix\Im\V2\Rest\RestConvertible;
12use Bitrix\Im\V2\Service\Context;
13use Bitrix\Main\ORM\Query\Query;
14use Bitrix\Main\UserTable;
31 'LAST_SEND_MESSAGE_ID',
47 return Relation::class;
50 public static function find(
67 return new static(
$query->fetchAll());
73 foreach ($this as $relation)
75 $rest[] = $relation->toRestFormat(
$option);
93 $relations =
new static();
101 ->setChatId($chat->getId())
102 ->setMessageType($chat->
getType())
103 ->setNotifyBlock(
false)
106 $relations->add($relation);
114 if (isset(self::$startIdStaticCache[$chatId][
$userId]))
116 return self::$startIdStaticCache[$chatId][
$userId];
119 $relation = static::find([
'CHAT_ID' => $chatId,
'USER_ID' =>
$userId], [], 1)->getByUserId(
$userId, $chatId);
121 if ($relation ===
null)
126 return $relation->getStartId() ?? 0;
131 return $this->relationsByUserId[$chatId][
$userId] ??
null;
136 if (isset($this->activeOnly))
141 $this->activeOnly =
new static();
143 foreach ($this as $relation)
146 if ($relation->getUser()->isActive() && ($isLiveChat || !$relation->getUser()->isConnector()))
148 $this->activeOnly->add($relation);
157 if (isset($this->notifyOnly))
162 $this->notifyOnly =
new static();
164 foreach ($this as $relation)
166 if (!($relation->getNotifyBlock() ??
false))
168 $this->notifyOnly->add($relation);
177 return isset($this->relationsByUserId[$chatId][
$userId]);
183 foreach ($this as $relation)
185 $userIds[$relation->getUserId()] = $relation->getUserId();
224 if (isset(
$filter[
'!USER_ID']))
236 if (isset(
$filter[
'MESSAGE_TYPE']))
238 $query->where(
'MESSAGE_TYPE', (
string)
$filter[
'MESSAGE_TYPE']);
241 foreach ([
'ID',
'USER_ID',
'LAST_SEND_MESSAGE_ID'] as $allowedFieldToOrder)
243 if (isset(
$order[$allowedFieldToOrder]))
245 $orderField = $allowedFieldToOrder;
246 $relationOrder[$allowedFieldToOrder] =
$order[$allowedFieldToOrder];
251 if (isset($orderField))
253 $query->setOrder($relationOrder);
259 if (isset($orderField) && $relationOrder[$orderField] ===
'ASC')
263 $query->where($orderField, $operator, (
int)
$filter[
'LAST_ID']);
271 if (isset(
$filter[
'ONLY_INTERNAL_TYPE']) &&
$filter[
'ONLY_INTERNAL_TYPE'])
276 ->whereNotIn(
'USER.EXTERNAL_AUTH_ID', UserTable::getExternalUserTypes())
277 ->whereNull(
'USER.EXTERNAL_AUTH_ID')
283 if (\
Bitrix\
Main\Loader::includeModule(
'extranet'))
285 $query->where(
'USER.IS_INTRANET_USER',
true);
294 if (isset(
$filter[
'IS_HIDDEN']))
303 parent::offsetSet(
$key, $value);
305 if ($value->getUserId() !==
null && $value->getChatId() !==
null)
307 $this->relationsByUserId[$value->getChatId()][$value->getUserId()] = $value;
308 if ($value->getStartId() !==
null)
310 static::$startIdStaticCache[$value->getChatId()][$value->getUserId()] = $value->getStartId();
314 $this->activeOnly =
null;
315 $this->notifyOnly =
null;
321 $value = $this[
$key] ??
null;
324 unset($this->relationsByUserId[$value->getChatId()][$value->getUserId()]);
325 unset(static::$startIdStaticCache[$value->getChatId()][$value->getUserId()]);
327 parent::offsetUnset(
$key);
329 $this->activeOnly =
null;
330 $this->notifyOnly =
null;
338 unset($this[$relation->getId()]);
340 unset($this->relationsByUserId[$chatId][
$userId]);
341 unset(self::$startIdStaticCache[$chatId][
$userId]);
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getType($chatData, bool $camelCase=true)
static getRestEntityName()
toRestFormat(array $option=[])
static getCollectionElementClass()
static processFilters(Query $query, array $filter, array $order)
static getStartId(int $userId, int $chatId)
getPopupData(array $excludedList=[])
static array $startIdStaticCache
static find(array $filter, array $order=[], ?int $limit=null, ?Context $context=null, array $select=self::COMMON_FIELDS)
static createFake(array $userIds, Chat $chat)
onAfterRelationDelete(int $chatId, int $userId)
getByUserId(int $userId, int $chatId)
hasUser(int $userId, int $chatId)
offsetSet($offset, $value)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(empty($signedUserToken)) $key