Ejemplo n.º 1
0
 public function GetUnreadMessage($arParams = array())
 {
     global $DB;
     $bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N' ? false : true;
     $lastId = !isset($arParams['LAST_ID']) || $arParams['LAST_ID'] == null ? null : IntVal($arParams['LAST_ID']);
     $order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC' ? 'ASC' : 'DESC';
     $loadDepartment = isset($arParams['LOAD_DEPARTMENT']) && $arParams['LOAD_DEPARTMENT'] == 'N' ? false : true;
     $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N' ? false : true;
     $bGroupByChat = isset($arParams['GROUP_BY_CHAT']) && $arParams['GROUP_BY_CHAT'] == 'Y' ? true : false;
     $bUserLoad = isset($arParams['USER_LOAD']) && $arParams['USER_LOAD'] == 'N' ? false : true;
     $bFileLoad = isset($arParams['FILE_LOAD']) && $arParams['FILE_LOAD'] == 'N' ? false : true;
     $arExistUserData = isset($arParams['EXIST_USER_DATA']) && is_array($arParams['EXIST_USER_DATA']) ? $arParams['EXIST_USER_DATA'] : array();
     $messageType = isset($arParams['MESSAGE_TYPE']) && in_array($arParams['MESSAGE_TYPE'], array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT)) ? $arParams['MESSAGE_TYPE'] : 'ALL';
     $arMessages = array();
     $arUnreadMessage = array();
     $arUsersMessage = array();
     $arResult = array('message' => array(), 'unreadMessage' => array(), 'usersMessage' => array(), 'users' => array(), 'userInGroup' => array(), 'woUserInGroup' => array(), 'files' => array(), 'countMessage' => 0, 'chat' => array(), 'userChatBlockStatus' => array(), 'userInChat' => array(), 'result' => false);
     $bLoadMessage = $bSpeedCheck ? CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_GROUP) : false;
     $count = CIMMessenger::SpeedFileGet($this->user_id, IM_SPEED_GROUP);
     if (!$bLoadMessage || $bLoadMessage && intval($count) > 0) {
         $ssqlLastId = "R1.LAST_ID";
         $ssqlStatus = " AND R1.STATUS < " . IM_STATUS_READ;
         if (!is_null($lastId) && intval($lastId) > 0 && !CIMMessenger::CheckXmppStatusOnline()) {
             $ssqlLastId = intval($lastId);
             $ssqlStatus = "";
         }
         $arRelations = array();
         if (strlen($ssqlStatus) > 0) {
             $strSql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tR1.USER_ID,\n\t\t\t\t\t\tR1.CHAT_ID,\n\t\t\t\t\t\tR1.LAST_ID\n\t\t\t\t\tFROM\n\t\t\t\t\t\tb_im_relation R1\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tR1.USER_ID = " . $this->user_id . "\n\t\t\t\t\t\t" . ($messageType == 'ALL' ? "AND R1.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "')" : "AND R1.MESSAGE_TYPE = '" . $messageType . "'") . "\n\t\t\t\t\t\t" . $ssqlStatus . "\n\t\t\t\t";
             $dbSubRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             while ($arRes = $dbSubRes->Fetch()) {
                 $arRelations[] = $arRes;
             }
         }
         $arMessageId = array();
         $arMessageChatId = array();
         $arLastMessage = array();
         $arMark = array();
         $arChat = array();
         $arPrepareResult = array();
         $arFilteredResult = array();
         if (!empty($arRelations)) {
             if (!$bTimeZone) {
                 CTimeZone::Disable();
             }
             $strSql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tM.ID,\n\t\t\t\t\t\tM.CHAT_ID,\n\t\t\t\t\t\tM.MESSAGE,\n\t\t\t\t\t\t" . $DB->DatetimeToTimestampFunction('M.DATE_CREATE') . " DATE_CREATE,\n\t\t\t\t\t\tM.AUTHOR_ID,\n\t\t\t\t\t\tR1.STATUS R1_STATUS,\n\t\t\t\t\t\tR1.MESSAGE_TYPE MESSAGE_TYPE\n\t\t\t\t\tFROM b_im_message M\n\t\t\t\t\tINNER JOIN b_im_relation R1 ON M.ID > " . $ssqlLastId . " AND M.CHAT_ID = R1.CHAT_ID AND R1.USER_ID != M.AUTHOR_ID\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tR1.USER_ID = " . $this->user_id . "\n\t\t\t\t\t\t" . ($messageType == 'ALL' ? "AND R1.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "')" : "AND R1.MESSAGE_TYPE = '" . $messageType . "'") . "\n\t\t\t\t\t\t" . $ssqlStatus . "\n\t\t\t\t";
             if (!$bTimeZone) {
                 CTimeZone::Enable();
             }
             $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             $CCTP = new CTextParser();
             $CCTP->MaxStringLen = 200;
             $CCTP->allow = array("HTML" => "N", "ANCHOR" => $this->bHideLink ? "N" : "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => $this->bHideLink ? "N" : "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
             while ($arRes = $dbRes->Fetch()) {
                 $arPrepareResult[$arRes['CHAT_ID']][$arRes['ID']] = $arRes;
             }
             foreach ($arPrepareResult as $chatId => $arRes) {
                 if (count($arPrepareResult[$chatId]) > 100) {
                     $arPrepareResult[$chatId] = array_slice($arRes, -100, 100);
                 }
                 $arFilteredResult = array_merge($arFilteredResult, $arPrepareResult[$chatId]);
             }
             unset($arPrepareResult);
         }
         foreach ($arFilteredResult as $arRes) {
             $arUsers[] = $arRes['AUTHOR_ID'];
             $arMessages[$arRes['ID']] = array('id' => $arRes['ID'], 'chatId' => $arRes['CHAT_ID'], 'senderId' => $arRes['AUTHOR_ID'], 'recipientId' => $arRes['CHAT_ID'], 'date' => $arRes['DATE_CREATE'], 'text' => $arRes['MESSAGE'], 'messageType' => $arRes['MESSAGE_TYPE']);
             if ($bGroupByChat) {
                 $arMessages[$arRes['ID']]['conversation'] = $arRes['CHAT_ID'];
                 $arMessages[$arRes['ID']]['unread'] = $this->user_id != $arRes['AUTHOR_ID'] ? 'Y' : 'N';
             } else {
                 $arUsersMessage[$arRes['CHAT_ID']][] = $arRes['ID'];
                 if ($this->user_id != $arRes['AUTHOR_ID']) {
                     $arUnreadMessage[$arRes['CHAT_ID']][] = $arRes['ID'];
                 }
             }
             if ($arRes['R1_STATUS'] == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"])) {
                 $arMark[$arRes["CHAT_ID"]] = $arRes["ID"];
             }
             if (!isset($arLastMessage[$arRes["CHAT_ID"]]) || $arLastMessage[$arRes["CHAT_ID"]] < $arRes["ID"]) {
                 $arLastMessage[$arRes["CHAT_ID"]] = $arRes["ID"];
             }
             $arChat[$arRes["CHAT_ID"]] = $arRes["CHAT_ID"];
             $arMessageId[] = $arRes['ID'];
             $arMessageChatId[$arRes['CHAT_ID']][$arRes["ID"]] = $arRes["ID"];
         }
         $params = CIMMessageParam::Get($arMessageId);
         if ($bFileLoad) {
             foreach ($arMessageChatId as $chatId => $messages) {
                 $files = array();
                 foreach ($messages as $messageId) {
                     $arMessages[$messageId]['params'] = $params[$messageId];
                     if (isset($params[$messageId]['FILE_ID'])) {
                         foreach ($params[$messageId]['FILE_ID'] as $fileId) {
                             $files[$fileId] = $fileId;
                         }
                     }
                 }
                 $arMessageFiles = CIMDisk::GetFiles($chatId, $files);
                 foreach ($arMessageFiles as $key => $value) {
                     $arResult['files'][$chatId][$key] = $value;
                 }
             }
         } else {
             foreach ($params as $messageId => $param) {
                 $arMessages[$messageId]['params'] = $param;
             }
         }
         if (!empty($arMessages)) {
             foreach ($arMark as $chatId => $lastSendId) {
                 CIMMessage::SetLastSendId($chatId, $this->user_id, $lastSendId);
             }
         } else {
             foreach ($arRelations as $relation) {
                 CIMMessage::SetLastId($relation['CHAT_ID'], $relation['USER_ID']);
             }
         }
         if ($bGroupByChat) {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$arLastMessage[$value['conversation']]]['counter']++;
                 if ($arLastMessage[$value['conversation']] != $value['id']) {
                     unset($arMessages[$key]);
                 } else {
                     $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                     $arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "\$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $value['text'])))), '<br>');
                     $arUsersMessage[$value['conversation']][] = $value['id'];
                     if ($value['unread'] == 'Y') {
                         $arUnreadMessage[$value['conversation']][] = $value['id'];
                     }
                     unset($arMessages[$key]['conversation']);
                     unset($arMessages[$key]['unread']);
                 }
             }
         } else {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                 $arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "\$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $value['text'])))), '<br>');
             }
         }
         $arResult['message'] = $arMessages;
         $arResult['unreadMessage'] = $arUnreadMessage;
         $arResult['usersMessage'] = $arUsersMessage;
         $arChat = self::GetChatData(array('ID' => $arChat, 'USE_CACHE' => 'N'));
         if (!empty($arChat)) {
             $arResult['chat'] = $arChat['chat'];
             $arResult['userChatBlockStatus'] = $arChat['userChatBlockStatus'];
             $arResult['userInChat'] = $arChat['userInChat'];
             foreach ($arChat['userInChat'] as $value) {
                 $arUsers[] = $value;
             }
         }
         if ($bUserLoad && !empty($arUsers)) {
             $arUserData = CIMContactList::GetUserData(array('ID' => array_diff(array_unique($arUsers), $arExistUserData), 'DEPARTMENT' => $loadDepartment ? 'Y' : 'N'));
             $arResult['users'] = $arUserData['users'];
             $arResult['userInGroup'] = $arUserData['userInGroup'];
             $arResult['woUserInGroup'] = $arUserData['woUserInGroup'];
         } else {
             $arResult['users'] = array();
             $arResult['userInGroup'] = array();
             $arResult['userInGroup'] = array();
         }
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
         if (!$bGroupByChat) {
             CIMMessenger::SpeedFileCreate($this->user_id, $arResult['countMessage'], IM_SPEED_GROUP);
         }
         $arResult['result'] = true;
     } else {
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
     }
     return $arResult;
 }
Ejemplo n.º 2
0
	public function GetUnreadMessage($arParams = Array())
	{
		global $DB;

		$bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N'? false: true;
		$lastId = !isset($arParams['LAST_ID']) || $arParams['LAST_ID'] == null? null: IntVal($arParams['LAST_ID']);
		$order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC'? 'ASC': 'DESC';
		$loadDepartment = isset($arParams['LOAD_DEPARTMENT']) && $arParams['LOAD_DEPARTMENT'] == 'N'? false: true;
		$bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N'? false: true;
		$bGroupByChat = isset($arParams['GROUP_BY_CHAT']) && $arParams['GROUP_BY_CHAT'] == 'Y'? true: false;
		$bUserLoad = isset($arParams['USER_LOAD']) && $arParams['USER_LOAD'] == 'N'? false: true;
		$bFileLoad = isset($arParams['FILE_LOAD']) && $arParams['FILE_LOAD'] == 'N'? false: true;
		$arExistUserData = isset($arParams['EXIST_USER_DATA']) && is_array($arParams['EXIST_USER_DATA'])? $arParams['EXIST_USER_DATA']: Array();
		$bSmiles = isset($arParams['USE_SMILES']) && $arParams['USE_SMILES'] == 'N'? false: true;

		$arMessages = Array();
		$arUnreadMessage = Array();
		$arUsersMessage = Array();

		$arResult = Array(
			'message' => Array(),
			'unreadMessage' => Array(),
			'usersMessage' => Array(),
			'users' => Array(),
			'files' => Array(),
			'userInGroup' => Array(),
			'woUserInGroup' => Array(),
			'countMessage' => 0,
			'result' => false
		);
		$bLoadMessage = $bSpeedCheck? CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_MESSAGE): false;
		$count = CIMMessenger::SpeedFileGet($this->user_id, IM_SPEED_MESSAGE);
		if (!$bLoadMessage || ($bLoadMessage && intval($count) > 0))
		{
			$ssqlLastId = "R1.LAST_ID";
			$ssqlStatus = " AND R1.STATUS < ".IM_STATUS_READ;
			if (!is_null($lastId) && intval($lastId) > 0 && !CIMMessenger::CheckXmppStatusOnline())
			{
				$ssqlLastId = intval($lastId);
				$ssqlStatus = "";
			}

			if (!$bTimeZone)
				CTimeZone::Disable();
			$strSql ="
				SELECT
					M.ID,
					M.CHAT_ID,
					M.MESSAGE,
					".$DB->DatetimeToTimestampFunction('M.DATE_CREATE')." DATE_CREATE,
					M.AUTHOR_ID,
					M.NOTIFY_EVENT,
					R1.USER_ID R1_USER_ID,
					R1.STATUS R1_STATUS,
					M.AUTHOR_ID R2_USER_ID
				FROM b_im_message M
				INNER JOIN b_im_relation R1 ON M.ID > ".$ssqlLastId." AND M.CHAT_ID = R1.CHAT_ID AND R1.USER_ID != M.AUTHOR_ID
				WHERE R1.USER_ID = ".$this->user_id." AND R1.MESSAGE_TYPE = '".IM_MESSAGE_PRIVATE."' ".$ssqlStatus."
			";
			if (!$bTimeZone)
				CTimeZone::Enable();
			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

			$arLastMessage = Array();
			$arMark = Array();
			$arMessageId = Array();
			$arMessageChatId = Array();

			while ($arRes = $dbRes->Fetch())
			{
				$arUsers[] = $arRes['R1_USER_ID'];
				$arUsers[] = $arRes['R2_USER_ID'];
				if ($this->user_id == $arRes['AUTHOR_ID'])
				{
					$arRes['TO_USER_ID'] = $arRes['R2_USER_ID'];
					$arRes['FROM_USER_ID'] = $arRes['R1_USER_ID'];
					$convId = $arRes['TO_USER_ID'];
				}
				else
				{
					$arRes['TO_USER_ID'] = $arRes['R1_USER_ID'];
					$arRes['FROM_USER_ID'] = $arRes['R2_USER_ID'];
					$convId = $arRes['FROM_USER_ID'];
				}

				$arMessages[$arRes['ID']] = Array(
					'id' => $arRes['ID'],
					'chatId' => $arRes['CHAT_ID'],
					'senderId' => $arRes['FROM_USER_ID'],
					'recipientId' => $arRes['TO_USER_ID'],
					'date' => $arRes['DATE_CREATE'],
					'system' => $arRes['NOTIFY_EVENT'] == 'private'? 'N': 'Y',
					'text' => $arRes['MESSAGE'],
				);
				if ($bGroupByChat)
				{
					$arMessages[$arRes['ID']]['conversation'] = $convId;
					$arMessages[$arRes['ID']]['unread'] = $this->user_id != $arRes['AUTHOR_ID']? 'Y': 'N';
				}
				else
				{
					$arUsersMessage[$convId][] = $arRes['ID'];
					if ($this->user_id != $arRes['AUTHOR_ID'])
						$arUnreadMessage[$convId][] = $arRes['ID'];
				}

				if ($arRes['R1_STATUS'] == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"]))
					$arMark[$arRes["CHAT_ID"]] = $arRes["ID"];

				if (!isset($arLastMessage[$convId]) || $arLastMessage[$convId] < $arRes["ID"])
					$arLastMessage[$convId] = $arRes["ID"];

				$arMessageId[] = $arRes['ID'];
				$arMessageChatId[$arRes['CHAT_ID']][$arRes["ID"]] = $arRes["ID"];
			}
			$params = CIMMessageParam::Get($arMessageId);
			if ($bFileLoad)
			{
				foreach ($arMessageChatId as $chatId => $messages)
				{
					$files = Array();
					foreach ($messages as $messageId)
					{
						$arMessages[$messageId]['params'] = $params[$messageId];

						if (isset($params[$messageId]['FILE_ID']))
						{
							foreach ($params[$messageId]['FILE_ID'] as $fileId)
							{
								$files[$fileId] = $fileId;
							}
						}
					}

					$arMessageFiles = CIMDisk::GetFiles($chatId, $files);
					foreach ($arMessageFiles as $key => $value)
					{
						$arResult['files'][$chatId][$key] = $value;
					}
				}
			}
			else
			{
				foreach ($params as $messageId => $param)
				{
					$arMessages[$messageId]['params'] = $param;
				}
			}

			if (!empty($arMessages))
			{
				$CCTP = new CTextParser();
				$CCTP->MaxStringLen = 200;
				$CCTP->allow = array("HTML" => "N", "ANCHOR" => $this->bHideLink? "N": "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => ($bSmiles? "Y": "N"), "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
			}

			foreach ($arMark as $chatId => $lastSendId)
				self::SetLastSendId($chatId, $this->user_id, $lastSendId);

			if ($bGroupByChat)
			{
				foreach ($arMessages as $key => $value)
				{
					$arMessages[$arLastMessage[$value['conversation']]]['counter']++;
					if ($arLastMessage[$value['conversation']] != $value['id'])
					{
						unset($arMessages[$key]);
					}
					else
					{
						$arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
						$arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\[s\].*?\[\/s\]/i", "", $value['text'])))) , '<br>');

						$arUsersMessage[$value['conversation']][] = $value['id'];

						if ($value['unread'] == 'Y')
							$arUnreadMessage[$value['conversation']][] = $value['id'];

						unset($arMessages[$key]['conversation']);
						unset($arMessages[$key]['unread']);
					}
				}
			}
			else
			{
				foreach ($arMessages as $key => $value)
				{
					$arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
					$arMessages[$key]['text_mobile'] = strip_tags(preg_replace("/<img.*?data-code=\"([^\"]*)\".*?>/i", "$1", $CCTP->convertText(htmlspecialcharsbx(preg_replace("/\[s\].*?\[\/s\]/i", "", $value['text'])))) , '<br>');
				}
			}

			$arResult['message'] = $arMessages;
			$arResult['unreadMessage'] = $arUnreadMessage;
			$arResult['usersMessage'] = $arUsersMessage;

			if ($bUserLoad && !empty($arUsers))
			{
				$arUserData = CIMContactList::GetUserData(Array('ID' => array_diff(array_unique($arUsers), $arExistUserData), 'DEPARTMENT' => ($loadDepartment? 'Y': 'N')));
				$arResult['users'] = $arUserData['users'];
				$arResult['userInGroup'] = $arUserData['userInGroup'];
				$arResult['woUserInGroup'] = $arUserData['woUserInGroup'];
			}
			else
			{
				$arResult['users'] = Array();
				$arResult['userInGroup'] = Array();
				$arResult['userInGroup'] = Array();
			}

			$arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
			if (!$bGroupByChat)
				CIMMessenger::SpeedFileCreate($this->user_id, $arResult['countMessage'], IM_SPEED_MESSAGE);
			$arResult['result'] = true;
		}
		else
		{
			$arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
		}

		return $arResult;
	}
Ejemplo n.º 3
0
 public function GetUnreadMessage($arParams = array())
 {
     global $DB;
     $bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N' ? false : true;
     $lastId = !isset($arParams['LAST_ID']) || $arParams['LAST_ID'] == null ? null : IntVal($arParams['LAST_ID']);
     $order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC' ? 'ASC' : 'DESC';
     $loadDepartment = isset($arParams['LOAD_DEPARTMENT']) && $arParams['LOAD_DEPARTMENT'] == 'N' ? false : true;
     $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N' ? false : true;
     $bGroupByChat = isset($arParams['GROUP_BY_CHAT']) && $arParams['GROUP_BY_CHAT'] == 'Y' ? true : false;
     $bUserLoad = isset($arParams['USER_LOAD']) && $arParams['USER_LOAD'] == 'N' ? false : true;
     $arExistUserData = isset($arParams['EXIST_USER_DATA']) && is_array($arParams['EXIST_USER_DATA']) ? $arParams['EXIST_USER_DATA'] : array();
     $arMessages = array();
     $arUnreadMessage = array();
     $arUsersMessage = array();
     $arResult = array('message' => array(), 'unreadMessage' => array(), 'usersMessage' => array(), 'users' => array(), 'userInGroup' => array(), 'woUserInGroup' => array(), 'countMessage' => 0, 'result' => false);
     $bLoadMessage = $bSpeedCheck ? CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_MESSAGE) : false;
     $count = CIMMessenger::SpeedFileGet($this->user_id, IM_SPEED_MESSAGE);
     if (!$bLoadMessage || $bLoadMessage && $count > 0) {
         $ssqlLastId = "R1.LAST_ID";
         $ssqlStatus = " AND R1.STATUS < " . IM_STATUS_READ;
         if (!is_null($lastId) && intval($lastId) > 0 && !CIMMessenger::CheckXmppStatusOnline()) {
             $ssqlLastId = intval($lastId);
             $ssqlStatus = "";
         }
         if (!$bTimeZone) {
             CTimeZone::Disable();
         }
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tM.ID,\n\t\t\t\t\tM.CHAT_ID,\n\t\t\t\t\tM.MESSAGE,\n\t\t\t\t\t" . $DB->DateToCharFunction('M.DATE_CREATE') . " DATE_CREATE,\n\t\t\t\t\tM.AUTHOR_ID,\n\t\t\t\t\tR1.USER_ID R1_USER_ID,\n\t\t\t\t\tR1.STATUS R1_STATUS,\n\t\t\t\t\tR2.USER_ID R2_USER_ID\n\t\t\t\tFROM b_im_relation R1\n\t\t\t\tINNER JOIN b_im_relation R2 on R2.CHAT_ID = R1.CHAT_ID AND R2.USER_ID != R1.USER_ID\n\t\t\t\tINNER JOIN b_im_message M ON M.ID > " . $ssqlLastId . " AND M.CHAT_ID = R2.CHAT_ID AND IMPORT_ID IS NULL\n\t\t\t\tWHERE R1.USER_ID = " . $this->user_id . " AND R1.USER_ID != M.AUTHOR_ID AND R1.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "' " . $ssqlStatus . "\n\t\t\t\tORDER BY ID " . ($order == "DESC" ? "DESC" : "ASC") . "\n\t\t\t";
         if (!$bTimeZone) {
             CTimeZone::Enable();
         }
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $arLastMessage = array();
         $arMark = array();
         $CCTP = new CTextParser();
         $CCTP->MaxStringLen = 200;
         $CCTP->allow = array("HTML" => "N", "ANCHOR" => $this->bHideLink ? "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");
         if (!$this->bHideLink) {
             $CCTPM = new CTextParser();
             $CCTPM->MaxStringLen = 200;
             $CCTPM->allow = array("HTML" => "N", "ANCHOR" => "N", "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");
         }
         while ($arRes = $dbRes->Fetch()) {
             $arUsers[] = $arRes['R1_USER_ID'];
             $arUsers[] = $arRes['R2_USER_ID'];
             if ($this->user_id == $arRes['AUTHOR_ID']) {
                 $arRes['TO_USER_ID'] = $arRes['R2_USER_ID'];
                 $arRes['FROM_USER_ID'] = $arRes['R1_USER_ID'];
                 $convId = $arRes['TO_USER_ID'];
             } else {
                 $arRes['TO_USER_ID'] = $arRes['R1_USER_ID'];
                 $arRes['FROM_USER_ID'] = $arRes['R2_USER_ID'];
                 $convId = $arRes['FROM_USER_ID'];
             }
             $arMessages[$arRes['ID']] = array('id' => $arRes['ID'], 'senderId' => $arRes['FROM_USER_ID'], 'recipientId' => $arRes['TO_USER_ID'], 'date' => MakeTimeStamp($arRes['DATE_CREATE']), 'text' => $arRes['MESSAGE']);
             if ($bGroupByChat) {
                 $arMessages[$arRes['ID']]['conversation'] = $convId;
                 $arMessages[$arRes['ID']]['unread'] = $this->user_id != $arRes['AUTHOR_ID'] ? 'Y' : 'N';
             } else {
                 $arUsersMessage[$convId][] = $arRes['ID'];
                 if ($this->user_id != $arRes['AUTHOR_ID']) {
                     $arUnreadMessage[$convId][] = $arRes['ID'];
                 }
             }
             if ($arRes['R1_STATUS'] == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"])) {
                 $arMark[$arRes["CHAT_ID"]] = $arRes["ID"];
             }
             if (!isset($arLastMessage[$convId]) || $arLastMessage[$convId] < $arRes["ID"]) {
                 $arLastMessage[$convId] = $arRes["ID"];
             }
         }
         if ($bGroupByChat) {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$arLastMessage[$value['conversation']]]['counter']++;
                 if ($arLastMessage[$value['conversation']] != $value['id']) {
                     unset($arMessages[$key]);
                 } else {
                     $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                     if ($this->bHideLink) {
                         $arMessages[$key]['text_mobile'] = $arMessages[$key]['text'];
                     } else {
                         $arMessages[$key]['text_mobile'] = $CCTPM->convertText(htmlspecialcharsbx($value['text']));
                     }
                     $arUsersMessage[$value['conversation']][] = $value['id'];
                     if ($value['unread'] == 'Y') {
                         $arUnreadMessage[$value['conversation']][] = $value['id'];
                     }
                     unset($arMessages[$key]['conversation']);
                     unset($arMessages[$key]['unread']);
                 }
             }
         } else {
             foreach ($arMessages as $key => $value) {
                 $arMessages[$key]['text'] = $CCTP->convertText(htmlspecialcharsbx($value['text']));
                 if ($this->bHideLink) {
                     $arMessages[$key]['text_mobile'] = $arMessages[$key]['text'];
                 } else {
                     $arMessages[$key]['text_mobile'] = $CCTPM->convertText(htmlspecialcharsbx($value['text']));
                 }
             }
         }
         foreach ($arMark as $chatId => $lastSendId) {
             self::SetLastSendId($chatId, $this->user_id, $lastSendId);
         }
         $arResult['message'] = $arMessages;
         $arResult['unreadMessage'] = $arUnreadMessage;
         $arResult['usersMessage'] = $arUsersMessage;
         if ($bUserLoad && !empty($arUsers)) {
             $arUserData = CIMContactList::GetUserData(array('ID' => array_diff(array_unique($arUsers), $arExistUserData), 'DEPARTMENT' => $loadDepartment ? 'Y' : 'N'));
             $arResult['users'] = $arUserData['users'];
             $arResult['userInGroup'] = $arUserData['userInGroup'];
             $arResult['woUserInGroup'] = $arUserData['woUserInGroup'];
         } else {
             $arResult['users'] = array();
             $arResult['userInGroup'] = array();
             $arResult['userInGroup'] = array();
         }
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
         if (!$bGroupByChat) {
             CIMMessenger::SpeedFileCreate($this->user_id, $arResult['countMessage'], IM_SPEED_MESSAGE);
         }
         $arResult['result'] = true;
     } else {
         $arResult['countMessage'] = CIMMessenger::GetMessageCounter($this->user_id, $arResult);
     }
     return $arResult;
 }
Ejemplo n.º 4
0
	public function GetUnreadNotify($arParams = Array())
	{
		global $DB;

		$order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC'? 'ASC': 'DESC';
		$bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N'? false: true;
		$bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N'? false: true;
		$bGetOnlyFlash = isset($arParams['GET_ONLY_FLASH']) && $arParams['GET_ONLY_FLASH'] == 'Y'? true: false;

		$arNotify['result'] = false;
		$arNotify['notify'] = Array();
		$arNotify['unreadNotify'] = Array();
		$arNotify['loadNotify'] = false;
		$arNotify['countNotify'] = 0;
		$arNotify['maxNotify'] = 0;

		$bLoadNotify = $bSpeedCheck? !CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_NOTIFY): true;
		if ($bLoadNotify)
		{
			$strSql = "SELECT CHAT_ID, STATUS FROM b_im_relation WHERE USER_ID = ".$this->user_id." AND MESSAGE_TYPE = '".IM_MESSAGE_SYSTEM."'";
			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
			if ($arRes = $dbRes->Fetch())
			{
				$chatId = intval($arRes['CHAT_ID']);
				$chatStatus = $arRes['STATUS'];
			}
			else
				return $arNotify;

			if (!$bTimeZone)
				CTimeZone::Disable();
			$strSql ="
				SELECT
					M.ID,
					M.CHAT_ID,
					M.MESSAGE,
					M.MESSAGE_OUT,
					".$DB->DatetimeToTimestampFunction('M.DATE_CREATE')." DATE_CREATE,
					M.NOTIFY_TYPE,
					M.NOTIFY_MODULE,
					M.NOTIFY_EVENT,
					M.NOTIFY_TITLE,
					M.NOTIFY_BUTTONS,
					M.NOTIFY_TAG,
					M.NOTIFY_SUB_TAG,
					$this->user_id TO_USER_ID,
					M.AUTHOR_ID FROM_USER_ID
				FROM b_im_message M
				WHERE M.CHAT_ID = ".$chatId." AND M.NOTIFY_READ = 'N'
			";
			if (!$bTimeZone)
				CTimeZone::Enable();
			$strSql = $DB->TopSql($strSql, 500);
			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

			$arMark = Array();
			$arGetUsers = Array();
			while ($arRes = $dbRes->Fetch())
			{
				if ($this->bHideLink)
					$arRes['HIDE_LINK'] = 'Y';

				$arNotify['original_notify'][$arRes['ID']] = $arRes;
				$arNotify['notify'][$arRes['ID']] = $arRes;
				$arNotify['unreadNotify'][$arRes['ID']] = $arRes['ID'];

				if ($chatStatus == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"]))
					$arMark[$arRes["CHAT_ID"]] = $arRes["ID"];

				if ($arNotify['maxNotify'] < $arRes['ID'])
					$arNotify['maxNotify'] = $arRes['ID'];

				$arGetUsers[] = $arRes['FROM_USER_ID'];
			}
			foreach ($arMark as $chatId => $lastSendId)
				CIMNotify::SetLastSendId($chatId, $lastSendId);

			$arNotify['countNotify'] = $this->GetNotifyCounter($arNotify);
			CIMMessenger::SpeedFileCreate($this->user_id, $arNotify['countNotify'], IM_SPEED_NOTIFY);

			$arUsers = CIMContactList::GetUserData(Array('ID' => $arGetUsers, 'DEPARTMENT' => 'N', 'USE_CACHE' => 'Y', 'CACHE_TTL' => 86400));
			$arGetUsers = $arUsers['users'];

			if ($bGetOnlyFlash)
			{
				foreach ($arNotify['notify'] as $key => $value)
				{
					if (isset($_SESSION['IM_FLASHED_NOTIFY'][$key]))
					{
						unset($arNotify['notify'][$key]);
						unset($arNotify['original_notify'][$key]);
						$arNotify['loadNotify'] = true;
					}
					else
					{
						$value['FROM_USER_DATA'] = $arGetUsers;
						$arNotify['notify'][$key] = self::GetFormatNotify($value);
					}
				}
			}
			else
			{
				foreach ($arNotify['notify'] as $key => $value)
				{
					$value['FROM_USER_DATA'] = $arGetUsers;
					$arNotify['notify'][$key] = self::GetFormatNotify($value);
				}
			}

			$arNotify['result'] = true;
		}
		else
		{
			$arNotify['countNotify'] = $this->GetNotifyCounter();
			if ($arNotify['countNotify'] > 0)
				$arNotify['loadNotify'] = true;
		}

		return $arNotify;
	}
Ejemplo n.º 5
0
 public function GetUnreadNotify($arParams = array())
 {
     global $DB;
     $order = isset($arParams['ORDER']) && $arParams['ORDER'] == 'ASC' ? 'ASC' : 'DESC';
     $bSpeedCheck = isset($arParams['SPEED_CHECK']) && $arParams['SPEED_CHECK'] == 'N' ? false : true;
     $bTimeZone = isset($arParams['USE_TIME_ZONE']) && $arParams['USE_TIME_ZONE'] == 'N' ? false : true;
     $bGetOnlyFlash = isset($arParams['GET_ONLY_FLASH']) && $arParams['GET_ONLY_FLASH'] == 'Y' ? true : false;
     $arNotify['result'] = false;
     $arNotify['notify'] = array();
     $arNotify['unreadNotify'] = array();
     $arNotify['loadNotify'] = false;
     $arNotify['maxNotify'] = 0;
     $bLoadNotify = $bSpeedCheck ? !CIMMessenger::SpeedFileExists($this->user_id, IM_SPEED_NOTIFY) : true;
     if ($bLoadNotify) {
         if (!$bTimeZone) {
             CTimeZone::Disable();
         }
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tM.ID,\n\t\t\t\t\tM.CHAT_ID,\n\t\t\t\t\tM.MESSAGE,\n\t\t\t\t\tM.MESSAGE_OUT,\n\t\t\t\t\t" . $DB->DateToCharFunction('M.DATE_CREATE') . " DATE_CREATE,\n\t\t\t\t\tM.NOTIFY_TYPE,\n\t\t\t\t\tM.NOTIFY_MODULE,\n\t\t\t\t\tM.NOTIFY_EVENT,\n\t\t\t\t\tM.NOTIFY_TITLE,\n\t\t\t\t\tM.NOTIFY_BUTTONS,\n\t\t\t\t\tM.NOTIFY_TAG,\n\t\t\t\t\tM.NOTIFY_SUB_TAG,\n\t\t\t\t\tR.LAST_ID,\n\t\t\t\t\tR.STATUS,\n\t\t\t\t\tR.USER_ID TO_USER_ID,\n\t\t\t\t\tM.AUTHOR_ID FROM_USER_ID\n\t\t\t\tFROM b_im_relation R\n\t\t\t\tINNER JOIN b_im_message M ON M.NOTIFY_READ = 'N' AND M.CHAT_ID = R.CHAT_ID\n\t\t\t\tWHERE R.USER_ID = " . $this->user_id . " AND R.MESSAGE_TYPE = '" . IM_MESSAGE_SYSTEM . "'\n\t\t\t\tORDER BY DATE_CREATE " . ($order == "DESC" ? "DESC" : "ASC") . ", ID " . ($order == "DESC" ? "DESC" : "ASC") . "\n\t\t\t";
         if (!$bTimeZone) {
             CTimeZone::Enable();
         }
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $arMark = array();
         while ($arRes = $dbRes->Fetch()) {
             if ($this->bHideLink) {
                 $arRes['HIDE_LINK'] = 'Y';
             }
             $arNotify['original_notify'][$arRes['ID']] = $arRes;
             $arNotify['notify'][$arRes['ID']] = $bGetOnlyFlash ? $arRes : self::GetFormatNotify($arRes);
             $arNotify['unreadNotify'][$arRes['ID']] = $arRes['ID'];
             if ($arRes['STATUS'] == IM_STATUS_UNREAD && (!isset($arMark[$arRes["CHAT_ID"]]) || $arMark[$arRes["CHAT_ID"]] < $arRes["ID"])) {
                 $arMark[$arRes["CHAT_ID"]] = $arRes["ID"];
             }
             if ($arNotify['maxNotify'] < $arRes['ID']) {
                 $arNotify['maxNotify'] = $arRes['ID'];
             }
         }
         foreach ($arMark as $chatId => $lastSendId) {
             CIMNotify::SetLastSendId($chatId, $lastSendId);
         }
         $arNotify['countNotify'] = $this->GetNotifyCounter($arNotify);
         CIMMessenger::SpeedFileCreate($this->user_id, $arNotify['countNotify'], IM_SPEED_NOTIFY);
         if ($bGetOnlyFlash) {
             foreach ($arNotify['notify'] as $key => $value) {
                 if (isset($_SESSION['IM_FLASHED_NOTIFY']) && in_array($key, $_SESSION['IM_FLASHED_NOTIFY'])) {
                     unset($arNotify['notify'][$key]);
                     unset($arNotify['original_notify'][$key]);
                     $arNotify['loadNotify'] = true;
                 } else {
                     $arNotify['notify'][$key] = self::GetFormatNotify($value);
                 }
             }
         }
         $arNotify['result'] = true;
     } else {
         $arNotify['countNotify'] = $this->GetNotifyCounter();
         if ($arNotify['countNotify'] > 0) {
             $arNotify['loadNotify'] = true;
         }
     }
     return $arNotify;
 }