Esempio n. 1
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;
 }
Esempio n. 2
0
	public static function MessageToChat($chatId, $messageId, $userId = 0, $getUserData = false, $addGenderToMessageId = true)
	{
		$chatId = intval($chatId);
		if ($chatId <= 0 || strlen($messageId) <= 0)
			return false;

		$userId = intval($userId);
		$message = '';

		if ($userId > 0 && $getUserData)
		{
			$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
			$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => $userId), 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);
		}

		CIMChat::AddMessage(Array(
			"FROM_USER_ID" => $userId,
			"TO_CHAT_ID" => $chatId,
			"MESSAGE" => $message,
			"SYSTEM" => 'Y',
		));

		return true;
	}
Esempio n. 3
0
     $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'];
         $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');