• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Chat.php
  • Класс: BitrixImV2Chat
  • Вызов: Chat::changeAuthor
public function changeAuthor(): void
{
	$currentAuthorId = $this->getAuthorId();
	$relations = $this->getRelations();
	$authorRelation = $relations->getByUserId($currentAuthorId, $this->getId());
	if ($authorRelation !== null)
	{
		$authorRelation->setManager(false);
	}
	$otherRealUserRelation = $relations->filter(static function (Relation $relation) use ($currentAuthorId) {
		$user = $relation->getUser();

		return $user->getId() !== $currentAuthorId
			&& $user->isActive()
			&& !$user->isBot()
			&& !$user->isExtranet()
			&& !$user->isConnector()
		;
	})->getAny();

	if (!$otherRealUserRelation instanceof Relation)
	{
		return;
	}

	$this->setAuthorId($otherRealUserRelation->getUserId());
	$otherRealUserRelation->setManager(true);
	$relations->save(true);
}