Пример #1
0
 if ($_POST['IM_NOTIFY_HISTORY_LOAD_MORE'] == 'Y') {
     $errorMessage = "";
     $CIMNotify = new CIMNotify();
     $arNotify = $CIMNotify->GetNotifyList(array('PAGE' => $_POST['PAGE'], 'USE_TIME_ZONE' => 'N'));
     echo CUtil::PhpToJsObject(array('NOTIFY' => $arNotify, 'ERROR' => $errorMessage));
 } else {
     if ($_POST['IM_SEND_MESSAGE'] == 'Y') {
         CUtil::decodeURIComponent($_POST);
         $tmpID = $_POST['ID'];
         if ($_POST['CHAT'] == 'Y') {
             $ar = array("FROM_USER_ID" => intval($USER->GetID()), "TO_CHAT_ID" => intval(substr($_POST['RECIPIENT_ID'], 4)), "MESSAGE" => $_POST['MESSAGE'], "MESSAGE_TYPE" => IM_MESSAGE_GROUP);
         } else {
             $ar = array("FROM_USER_ID" => intval($USER->GetID()), "TO_USER_ID" => intval($_POST['RECIPIENT_ID']), "MESSAGE" => $_POST['MESSAGE']);
         }
         $errorMessage = "";
         if (!($insertID = CIMMessage::Add($ar))) {
             if ($e = $GLOBALS["APPLICATION"]->GetException()) {
                 $errorMessage = $e->GetString();
             }
             if (StrLen($errorMessage) == 0) {
                 $errorMessage = GetMessage('UNKNOWN_ERROR');
             }
         }
         $CCTP = new CTextParser();
         $CCTP->MaxStringLen = 200;
         $CCTP->allow = array("HTML" => "N", "ANCHOR" => isset($_POST['MOBILE']) ? "N" : "Y", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
         $userTzOffset = isset($_POST['USER_TZ_OFFSET']) ? intval($_POST['USER_TZ_OFFSET']) : CTimeZone::GetOffset();
         $arResult = array('TMP_ID' => $tmpID, 'ID' => $insertID, 'SEND_DATE' => time() + $userTzOffset, 'SEND_MESSAGE' => $CCTP->convertText(htmlspecialcharsbx($ar['MESSAGE'])), 'SENDER_ID' => intval($USER->GetID()), 'RECIPIENT_ID' => $_POST['CHAT'] == 'Y' ? htmlspecialcharsbx($_POST['RECIPIENT_ID']) : intval($_POST['RECIPIENT_ID']), 'ERROR' => $errorMessage);
         if (isset($_POST['MOBILE'])) {
             $arFormat = array("today" => "today, " . GetMessage('IM_MESSAGE_FORMAT_TIME'), "" => GetMessage('IM_MESSAGE_FORMAT_DATE'));
             $arResult['SEND_DATE_FORMAT'] = FormatDate($arFormat, time() + $userTzOffset);
Пример #2
0
	public static function MessageToPrivate($fromUserId, $toUserId, $messageId, $getUserData = false, $addGenderToMessageId = true)
	{
		$fromUserId = intval($fromUserId);
		$toUserId = intval($toUserId);
		if ($fromUserId <= 0 || $toUserId <= 0)
			return false;

		$message = '';
		if ($fromUserId > 0 && $getUserData)
		{
			$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
			$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => $fromUserId), array('FIELDS' => $arSelect));
			if ($arUser = $dbUsers->Fetch())
				$message = GetMessage($messageId.($addGenderToMessageId? ($arUser["PERSONAL_GENDER"] == 'F'? 'F': 'M'): ''), Array('#USER_NAME#' => CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false)));
		}
		else
		{
			$message = GetMessage($messageId);
		}

		CIMMessage::Add(Array(
			"FROM_USER_ID" => $fromUserId,
			"TO_USER_ID" =>  $toUserId,
			"MESSAGE" => $message,
			"SYSTEM" => 'Y',
			"PUSH" => 'N',
		));

		return true;
	}
Пример #3
0
 public function SendChatMessage($dialogId, $incomingType, $message)
 {
     if (strlen($message) <= 0 || strlen($dialogId) <= 0) {
         return false;
     }
     if (CVoxImplantConfig::GetChatAction() == CVoxImplantConfig::INTERFACE_CHAT_NONE) {
         return false;
     }
     if (!CModule::IncludeModule('im')) {
         return false;
     }
     // TODO CHECK NULL USER BEFORE SEND
     $chatId = 0;
     if (substr($dialogId, 0, 4) == 'chat') {
         $chatId = intval(substr($dialogId, 4));
         CIMChat::AddMessage(array("FROM_USER_ID" => $incomingType == CVoxImplantMain::CALL_OUTGOING ? $this->userId : 0, "TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "SYSTEM" => 'Y'));
     } else {
         if (intval($dialogId) > 0) {
             CIMMessage::Add(array("FROM_USER_ID" => $incomingType == CVoxImplantMain::CALL_OUTGOING ? $this->userId : intval($dialogId), "TO_USER_ID" => $incomingType == CVoxImplantMain::CALL_OUTGOING ? intval($dialogId) : $this->userId, "MESSAGE" => $message, "SYSTEM" => 'Y'));
         }
     }
     return true;
 }
Пример #4
0
 public static function UploadFileFromDisk($chatId, $files)
 {
     if (intval($chatId) <= 0) {
         return false;
     }
     $chatRelation = CIMChat::GetRelationById($chatId);
     if (!$chatRelation[self::GetUserId()]) {
         return false;
     }
     $result['FILES'] = array();
     $messageFileId = array();
     foreach ($files as $fileId) {
         $newFile = self::SaveFromLocalDisk($chatId, substr($fileId, 4));
         if ($newFile) {
             $result['FILES'][$fileId] = self::GetFileParams($chatId, $newFile);
             $messageFileId[] = $newFile->getId();
             foreach ($chatRelation as $relation) {
                 if ($relation['MESSAGE_TYPE'] != IM_MESSAGE_PRIVATE) {
                     break;
                 }
                 if (self::GetUserId() == $relation['USER_ID']) {
                     continue;
                 }
                 \Bitrix\Disk\Driver::getInstance()->getRecentlyUsedManager()->push($relation['USER_ID'], $newFile->getId());
             }
         } else {
             $result['FILES'][$fileId]['id'] = 0;
         }
     }
     if (empty($messageFileId)) {
         return false;
     }
     $result['MESSAGE_ID'] = 0;
     $arChat = CIMChat::GetChatData(array('ID' => $chatId));
     $ar = array("TO_CHAT_ID" => $chatId, "FROM_USER_ID" => self::GetUserId(), "MESSAGE_TYPE" => $arChat['chat'][$chatId]['messageType'], "PARAMS" => array('FILE_ID' => $messageFileId));
     $messageId = CIMMessage::Add($ar);
     if ($messageId) {
         $result['MESSAGE_ID'] = $messageId;
     }
     return $result;
 }
Пример #5
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("message", $arMessage) || !array_key_exists(".", $arMessage["message"])) {
         return false;
     }
     $type = "normal";
     if (array_key_exists("type", $arMessage["message"]["."])) {
         $type = $arMessage["message"]["."]["type"];
     }
     if ($type == "error") {
         return false;
     }
     $mid = "";
     if (array_key_exists("id", $arMessage["message"]["."])) {
         $mid = $arMessage["message"]["."]["id"];
     }
     if (!in_array($type, array("chat", "groupchat", "headline", "normal"))) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "modify", "bad-request", "", $mid, "", $senderClient->GetClientDomain());
     }
     $recipientJId = "";
     if (array_key_exists("to", $arMessage["message"]["."])) {
         $recipientJId = $arMessage["message"]["."]["to"];
     }
     if (strlen($recipientJId) <= 0) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "modify", "bad-request", "", $mid, "", $senderClient->GetClientDomain());
     }
     $body = "";
     if (array_key_exists("body", $arMessage["message"])) {
         $body = $arMessage["message"]["body"]["#"];
     }
     if (strlen($body) <= 0) {
         return true;
     }
     //$body = CXMPPReceiveMessage::htmlspecialcharsback($body);
     //$body = html_entity_decode($body);
     $body = html_entity_decode($body, ENT_COMPAT, SITE_CHARSET);
     $body = str_replace("&apos;", "'", $body);
     $arSender = CXMPPUtility::GetUserByJId($senderJId);
     if (!$arSender) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "auth", "forbidden", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     $arRecipient = CXMPPUtility::GetUserByJId($recipientJId);
     if (!$arRecipient) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "cancel", "item-not-found", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     if (!CSocNetUserPerms::CanPerformOperation($arSender["ID"], $arRecipient["ID"], "message", false)) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "auth", "forbidden", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     if (IsModuleInstalled("im") && CModule::IncludeModule("im")) {
         $arMessageFields = array("FROM_USER_ID" => $arSender["ID"], "TO_USER_ID" => $arRecipient["ID"], "MESSAGE" => $body);
         CIMMessage::Add($arMessageFields);
     } else {
         $arMessageFields = array("=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_PRIVATE, "FROM_USER_ID" => $arSender["ID"], "TO_USER_ID" => $arRecipient["ID"], "MESSAGE" => $body);
         CSocNetMessages::Add($arMessageFields);
     }
     return true;
 }
Пример #6
0
 $tmpID = $_POST['ID'];
 $insertID = 0;
 $errorMessage = "";
 if ($_POST['CHAT'] == 'Y' && substr($_POST['RECIPIENT_ID'], 0, 4) == 'chat') {
     $userId = $USER->GetId();
     $chatId = intval(substr($_POST['RECIPIENT_ID'], 4));
     if (CIMChat::GetGeneralChatId() == $chatId && !CIMChat::CanSendMessageToGeneralChat($userId)) {
         $errorMessage = GetMessage('IM_ERROR_GROUP_CANCELED');
     } else {
         $ar = array("FROM_USER_ID" => $userId, "TO_CHAT_ID" => $chatId, "MESSAGE" => $_POST['MESSAGE']);
         $insertID = CIMChat::AddMessage($ar);
     }
 } else {
     if (substr($_POST['RECIPIENT_ID'], 0, 4) != 'chat') {
         $ar = array("FROM_USER_ID" => intval($USER->GetID()), "TO_USER_ID" => intval($_POST['RECIPIENT_ID']), "MESSAGE" => $_POST['MESSAGE']);
         $insertID = CIMMessage::Add($ar);
     } else {
         $errorMessage = GetMessage('IM_ACCESS_ERROR');
     }
 }
 if (!$insertID && !$errorMessage) {
     if ($e = $GLOBALS["APPLICATION"]->GetException()) {
         $errorMessage = $e->GetString();
     }
     if (StrLen($errorMessage) == 0) {
         $errorMessage = GetMessage('IM_UNKNOWN_ERROR');
     }
 }
 $params = CIMMessageParam::Get(array($insertID));
 $arMessages = CIMMessageLink::prepareShow(array(), $params);
 $CCTP = new CTextParser();
Пример #7
0
	public static function UploadFileFromDisk($chatId, $files)
	{
		if (intval($chatId) <= 0)
			return false;

		$chatRelation = CIMChat::GetRelationById($chatId);
		if (!$chatRelation[self::GetUserId()])
			return false;

		$result['FILES'] = Array();
		$messageFileId = Array();
		foreach ($files as $fileId)
		{
			$newFile = self::SaveFromLocalDisk($chatId, substr($fileId, 4));
			if ($newFile)
			{
				$result['FILES'][$fileId] = self::GetFileParams($chatId, $newFile);
				$messageFileId[] = $newFile->getId();
			}
			else
			{
				$result['FILES'][$fileId]['id'] = 0;
			}
		}
		if (empty($messageFileId))
		{
			return false;
		}

		$result['MESSAGE_ID'] = 0;
		$arChat = CIMChat::GetChatData(Array('ID' => $chatId));
		$ar = Array(
			"TO_CHAT_ID" => $chatId,
			"FROM_USER_ID" => self::GetUserId(),
			"MESSAGE_TYPE" => $arChat['chat'][$chatId]['type'] == IM_MESSAGE_PRIVATE? IM_MESSAGE_PRIVATE: IM_MESSAGE_GROUP,
			"PARAMS" => Array(
				'FILE_ID' => $messageFileId
			)
		);
		$messageId = CIMMessage::Add($ar);
		if ($messageId)
		{
			$result['MESSAGE_ID'] = $messageId;
		}

		return $result;
	}
Пример #8
0
 public static function UndeliveredMessageAgent()
 {
     if (!CModule::IncludeModule("socialnetwork")) {
         return false;
     }
     $activateNewAgent = false;
     $dbMessage = CSocNetMessages::GetList(array("ID" => "ASC"), array("DATE_VIEW" => "", "TO_DELETED" => "N", "MESSAGE_TYPE" => "P"), false, array("nTopCount" => '500'), array("ID", "FROM_USER_ID", "TO_USER_ID", "MESSAGE", "DATE_CREATE"));
     while ($arMessage = $dbMessage->Fetch()) {
         $ar = array("FROM_USER_ID" => intval($arMessage["FROM_USER_ID"]), "TO_USER_ID" => intval($arMessage["TO_USER_ID"]), "MESSAGE" => $arMessage["MESSAGE"], "MESSAGE_DATE" => $arMessage["DATE_CREATE"]);
         CIMMessage::Add($ar);
         CSocNetMessages::Update($arMessage["ID"], array("TO_DELETED" => "Y", "FROM_DELETED" => "Y"));
         $activateNewAgent = true;
     }
     return $activateNewAgent ? "CIMConvert::UndeliveredMessageAgent();" : "";
 }
Пример #9
0
	public static function CallCommand($recipientId, $command, $params = Array())
	{
		global $USER;

		if ($USER->GetID() <= 0 || intval($recipientId) <= 0)
			return false;

		if (!CModule::IncludeModule("pull"))
			return false;

		$arParams = Array(
			'command' => $command,
			'senderId' => $USER->GetID()
		);

		if ($command == 'signaling')
		{
			$arParams['peer'] = $params['peer'];
		}
		else if ($command == 'invite')
		{
			$arParams['video'] = isset($params['video']) && $params['video'] == 'Y'? true: false;

			$arUserData = CIMContactList::GetUserData(Array('ID' => array($USER->GetID(), $recipientId), 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y'));
			$arParams['users'] = $arUserData['users'];
			$arParams['hrphoto'] = $arUserData['hrphoto'];
		}
		else if ($command == 'busy')
		{
			$arParams['video'] = isset($params['video']) && $params['video'] == 'Y'? true: false;

			$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
			$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => $USER->GetID()), array('FIELDS' => $arSelect));
			$arUsers = Array();
			if ($arUser = $dbUsers->Fetch())
			{
				$arUsers['NAME'] = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
				$arUsers['GENDER'] = $arUser["PERSONAL_GENDER"] == 'F'? 'F': 'M';

				CIMMessage::Add(Array(
					"FROM_USER_ID" => intval($recipientId),
					"TO_USER_ID" => $USER->GetID(),
					"MESSAGE" => GetMessage("IM_CALL_CHAT_BUSY_".$arUsers['GENDER'], Array('#USER_NAME#' => $arUsers['NAME'])),
					"PUSH" => 'N',
					"SYSTEM" => 'Y',
				));
			}
		}
		else if ($command == 'waitTimeout')
		{
			$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
			$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => $recipientId), array('FIELDS' => $arSelect));
			$arUsers = Array();
			if ($arUser = $dbUsers->Fetch())
			{
				$arUsers['NAME'] = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);

				CIMMessage::Add(Array(
					"FROM_USER_ID" => $USER->GetID(),
					"TO_USER_ID" => intval($recipientId),
					"MESSAGE" => GetMessage("IM_CALL_CHAT_WAIT", Array('#USER_NAME#' => $arUsers['NAME'])),
					"PUSH" => 'N',
					"SYSTEM" => 'Y',
				));
			}
		}
		else if ($command == 'start')
		{
			CIMMessage::Add(Array(
				"FROM_USER_ID" => $USER->GetID(),
				"TO_USER_ID" =>  intval($recipientId),
				"MESSAGE" => GetMessage("IM_CALL_CHAT_START"),
				"SYSTEM" => 'Y',
				"PUSH" => 'N',
				"READED" => 'Y',
			));
		}
		else if ($command == 'errorAccess')
		{
			$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
			$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => $USER->GetID()), array('FIELDS' => $arSelect));
			$arUsers = Array();
			if ($arUser = $dbUsers->Fetch())
			{
				$arUsers['NAME'] = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);

				CIMMessage::Add(Array(
					"FROM_USER_ID" => $USER->GetID(),
					"TO_USER_ID" => intval($recipientId),
					"MESSAGE" => GetMessage("IM_CALL_CHAT_ERROR", Array('#USER_NAME#' => $arUsers['NAME'])),
					"SYSTEM" => 'Y',
					"PUSH" => 'N',
					"READED" => 'Y',
				));
			}
		}
		else if ($command == 'errorOffline')
		{
			$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
			$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => intval($recipientId)), array('FIELDS' => $arSelect));
			$arUsers = Array();
			if ($arUser = $dbUsers->Fetch())
			{
				$arUsers['NAME'] = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);

				CIMMessage::Add(Array(
					"FROM_USER_ID" => $USER->GetID(),
					"TO_USER_ID" =>  intval($recipientId),
					"MESSAGE" => GetMessage("IM_CALL_CHAT_OFFLINE", Array('#USER_NAME#' => $arUsers['NAME'])),
					"SYSTEM" => 'Y',
				));
			}
		}
		else if ($command == 'decline')
		{
			if ($params['CONNECTED'] == 'Y')
			{
				CIMMessage::Add(Array(
					"FROM_USER_ID" => $USER->GetID(),
					"TO_USER_ID" =>  intval($recipientId),
					"MESSAGE" => GetMessage("IM_CALL_CHAT_END"),
					"PUSH" => 'N',
					"SYSTEM" => 'Y',
					"READED" => 'Y',
				));
			}
			else
			{
				$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
				$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => $USER->GetID()), array('FIELDS' => $arSelect));
				$arUsers = Array();
				if ($arUser = $dbUsers->Fetch())
				{
					$arUsers['NAME'] = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
					$arUsers['GENDER'] = $arUser["PERSONAL_GENDER"] == 'F'? 'F': 'M';

					CIMMessage::Add(Array(
						"FROM_USER_ID" => $USER->GetID(),
						"TO_USER_ID" =>  intval($recipientId),
						"MESSAGE" => GetMessage("IM_CALL_CHAT_DECLINE_".$arUsers['GENDER'], Array('#USER_NAME#' => $arUsers['NAME'])),
						"PUSH" => 'N',
						"SYSTEM" => 'Y',
						"READED" => $params['ACTIVE'] == 'Y'? 'Y': $params['INITIATOR'] == 'Y'? 'N': 'Y',
					));
				}
			}
		}
		else if ($command == 'busy_self')
		{
			CIMMessage::Add(Array(
				"FROM_USER_ID" => $USER->GetID(),
				"TO_USER_ID" =>  intval($recipientId),
				"MESSAGE" => GetMessage("IM_CALL_CHAT_END"),
				"PUSH" => 'N',
				"SYSTEM" => 'Y',
				"READED" => 'Y',
			));
		}
		else if ($command == 'wait' || $command == 'accept' || $command == 'ready' || $command == 'decline_self' || $command == 'accept_self' )
		{
		}
		else
			return false;


		CPullStack::AddByUser(intval($recipientId), Array(
			'module_id' => 'im',
			'command' => 'call',
			'params' => $arParams,
		));

		if ($command == 'accept' || $command == 'decline')
		{
			$arParams['command'] = $command.'_self';
			CPullStack::AddByUser($USER->GetID(), Array(
				'module_id' => 'im',
				'command' => 'call',
				'params' => $arParams,
			));
		}

		return true;
	}