• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_chat.php
  • Класс: CIMChat
  • Вызов: CIMChat::SetOwner
public function SetOwner($chatId, $userId, $checkPermission = true)
{
	$chatId = intval($chatId);
	$userId = intval($userId);

	$chat = IMModelChatTable::getById($chatId)->fetch();
	if (!$chat)
		return false;

	if ($checkPermission && $chat['AUTHOR_ID'] != $this->user_id)
		return false;

	if ($userId == $chat['AUTHOR_ID'])
		return true;

	$arRelation = self::GetRelationById($chatId, false, true, false);
	if (!isset($arRelation[$userId]))
		return false;

	IMModelChatTable::update($chatId, Array('AUTHOR_ID' => $userId));
	IMModelRelationTable::update($arRelation[$userId]['ID'], Array('MANAGER' => 'Y'));
	if (isset($arRelation[$chat['AUTHOR_ID']]))
	{
		IMModelRelationTable::update($arRelation[$chat['AUTHOR_ID']]['ID'], Array('MANAGER' => 'N'));
	}

	if (CModule::IncludeModule('pull'))
	{
		BitrixPullEvent::add(array_keys($arRelation), Array(
			'module_id' => 'im',
			'command' => 'chatOwner',
			'params' => Array(
				'dialogId' => 'chat'.$chatId,
				'chatId' => (int)$chatId,
				'userId' => $userId
			),
			'extra' => BitrixImCommon::getPullExtra()
		));
	}

	return true;
}