Example #1
0
 public function SetReadMessage($chatId, $lastId = null)
 {
     global $DB;
     $chatId = intval($chatId);
     if ($chatId <= 0) {
         return false;
     }
     $sqlLastId = '';
     if (intval($lastId) > 0) {
         $sqlLastId = "AND M.ID <= " . intval($lastId);
     }
     $strSql = "\n\t\t\tSELECT COUNT(M.ID) CNT, MAX(M.ID) ID, M.CHAT_ID\n\t\t\tFROM b_im_message M\n\t\t\tINNER JOIN b_im_relation R1 ON M.ID > R1.LAST_ID " . $sqlLastId . " AND M.CHAT_ID = R1.CHAT_ID\n\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . "\n\t\t\tGROUP BY M.CHAT_ID\n\t\t";
     $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if ($arRes = $dbRes->Fetch()) {
         $bReadMessage = CIMMessage::SetLastId($chatId, $this->user_id, $arRes['ID']);
         if ($bReadMessage) {
             //CUserCounter::Decrement($this->user_id, 'im_chat_v2', '**', false, $arRes['CNT']);
             CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_GROUP);
             if (CModule::IncludeModule("pull")) {
                 CPushManager::DeleteFromQueueBySubTag($this->user_id, 'IM_MESS');
                 CPullStack::AddByUser($this->user_id, array('module_id' => 'im', 'command' => 'readMessageChat', 'params' => array('chatId' => $chatId, 'lastId' => $arRes['ID'], 'count' => $arRes['CNT'])));
                 CIMMessenger::SendBadges($this->user_id);
             }
             return true;
         }
     }
     return false;
 }
	public static function InitCounters($userId, $check = true)
	{
		return false;
		
		if (intval($userId) <= 0)
			return false;

		$send = false;
		if (!$check || !CUserOptions::GetOption('im', 'initCounterNotify2', false, $userId))
		{
			CIMNotify::SetUnreadCounter($userId);
			CUserOptions::SetOption('im', 'initCounterNotify2', true, $userId);
			$send = true;
		}
		if (!$check || !CUserOptions::GetOption('im', 'initCounterChat2', false, $userId))
		{
			CIMChat::SetUnreadCounter($userId);
			CUserOptions::SetOption('im', 'initCounterChat2', true, $userId);
			$send = true;
		}
		if (!$check || !CUserOptions::GetOption('im', 'initCounterMessage2', false, $userId))
		{
			CIMMessage::SetUnreadCounter($userId);
			CUserOptions::SetOption('im', 'initCounterMessage2', true, $userId);
			$send = true;
		}
		if ($send)
			CIMMessenger::SendBadges($userId);

		return true;
	}
Example #3
0
 public static function DeleteBySubTag($notifySubTag, $authorId = false)
 {
     global $DB;
     if (strlen($notifySubTag) <= 0) {
         return false;
     }
     $sqlUser = "";
     $sqlUser2 = "";
     if ($authorId !== false) {
         $sqlUser = "******" . intval($authorId);
         $sqlUser2 = " AND AUTHOR_ID = " . intval($authorId);
     }
     $dbRes = $DB->Query("SELECT R.USER_ID, R.STATUS FROM b_im_relation R, b_im_message M WHERE M.CHAT_ID = R.CHAT_ID AND M.NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $arUsers = array();
     while ($row = $dbRes->Fetch()) {
         $count = $row['STATUS'] < IM_STATUS_READ ? 1 : 0;
         if (isset($arUsers[$row['USER_ID']])) {
             $arUsers[$row['USER_ID']] += $count;
         } else {
             $arUsers[$row['USER_ID']] = $count;
         }
     }
     $arUsersSend = array();
     foreach ($arUsers as $userId => $count) {
         CIMMessenger::SpeedFileDelete($userId, IM_SPEED_NOTIFY);
         if ($count > 0) {
             $arUsersSend[] = $userId;
             //CUserCounter::Decrement($userId, 'im_notify_v2', '**', false);
         }
     }
     $strSql = "DELETE FROM b_im_message WHERE NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser2;
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     CIMMessenger::SendBadges($arUsersSend);
     return true;
 }
	public function SetReadMessage($fromUserId, $lastId = null)
	{
		global $DB;

		$fromUserId = intval($fromUserId);
		if ($fromUserId <= 0)
			return false;

		$sqlLastId = '';
		if (intval($lastId) > 0)
			$sqlLastId = "AND M.ID <= ".intval($lastId);

		$strSql = "
			SELECT COUNT(M.ID) CNT, MAX(M.ID) ID, M.CHAT_ID
			FROM b_im_relation RF
				INNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID
				INNER JOIN b_im_message M ON M.ID > RT.LAST_ID ".$sqlLastId." AND M.CHAT_ID = RT.CHAT_ID
			WHERE RT.USER_ID = ".$this->user_id."
				and RF.USER_ID = ".$fromUserId."
				and RT.MESSAGE_TYPE = '".IM_MESSAGE_PRIVATE."' and RT.STATUS < ".IM_STATUS_READ."
			GROUP BY M.CHAT_ID";
		$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
		if ($arRes = $dbRes->Fetch())
		{
			$bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, $arRes['ID']);
			if ($bReadMessage)
			{
				//CUserCounter::Decrement($this->user_id, 'im_message_v2', '**', false, $arRes['CNT']);
				CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_MESSAGE);
				if (CModule::IncludeModule("pull"))
				{
					CPushManager::DeleteFromQueueBySubTag($this->user_id, 'IM_MESS');
					CPullStack::AddByUser($this->user_id, Array(
						'module_id' => 'im',
						'command' => 'readMessage',
						'params' => Array(
							'chatId' => intval($arRes['CHAT_ID']),
							'senderId' => $this->user_id,
							'id' => $fromUserId,
							'userId' => $fromUserId,
							'lastId' => $arRes['ID'],
							'count' => $arRes['CNT']
						),
					));
					CPullStack::AddByUser($fromUserId, Array(
						'module_id' => 'im',
						'command' => 'readMessageApponent',
						'params' => Array(
							'chatId' => intval($arRes['CHAT_ID']),
							'userId' => $this->user_id,
							'lastId' => $arRes['ID'],
							'date' => time(),
							'count' => $arRes['CNT']
						),
					));
					CIMMessenger::SendBadges($this->user_id);
				}
				return true;
			}
		}

		return false;
	}
Example #5
0
 public static function DeleteBySubTag($notifySubTag, $authorId = false)
 {
     global $DB;
     if (strlen($notifySubTag) <= 0) {
         return false;
     }
     $sqlUser = "";
     $sqlUser2 = "";
     if ($authorId !== false) {
         $sqlUser = "******" . intval($authorId);
         $sqlUser2 = " AND AUTHOR_ID = " . intval($authorId);
     }
     $dbRes = $DB->Query("SELECT M.ID, M.NOTIFY_TYPE, R.USER_ID, R.STATUS FROM b_im_relation R, b_im_message M WHERE M.CHAT_ID = R.CHAT_ID AND M.NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $arUsers = array();
     $messages = array();
     while ($row = $dbRes->Fetch()) {
         $messages[$row['ID']] = $row['NOTIFY_TYPE'];
         $count = $row['STATUS'] < IM_STATUS_READ ? 1 : 0;
         if (isset($arUsers[$row['USER_ID']])) {
             $arUsers[$row['USER_ID']] += $count;
         } else {
             $arUsers[$row['USER_ID']] = $count;
         }
     }
     $pullActive = false;
     if (CModule::IncludeModule("pull")) {
         $pullActive = true;
     }
     $arUsersSend = array();
     foreach ($arUsers as $userId => $count) {
         CIMMessenger::SpeedFileDelete($userId, IM_SPEED_NOTIFY);
         if ($count > 0) {
             $arUsersSend[] = $userId;
             //CUserCounter::Decrement($userId, 'im_notify_v2', '**', false);
         }
         if ($pullActive) {
             CPushManager::DeleteFromQueueBySubTag($userId, $notifySubTag);
         }
     }
     if ($pullActive) {
         CPullStack::AddByUsers(array_keys($arUsers), array('module_id' => 'im', 'command' => 'massDeleteMessage', 'params' => array('MESSAGE' => $messages)));
     }
     if (count($messages) > 0) {
         $messageParameters = IM\MessageParamTable::getList(array('select' => array('ID'), 'filter' => array('=MESSAGE_ID' => array_keys($messages))));
         while ($ar = $messageParameters->fetch()) {
             IM\MessageParamTable::delete($ar['ID']);
         }
         $strSql = "DELETE FROM b_im_message WHERE NOTIFY_SUB_TAG = '" . $DB->ForSQL($notifySubTag) . "'" . $sqlUser2;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     CIMMessenger::SendBadges($arUsersSend);
     return true;
 }