Esempio n. 1
0
 public function SetReadMessage($fromUserId, $lastId = null)
 {
     global $DB;
     $fromUserId = intval($fromUserId);
     if ($fromUserId <= 0) {
         return false;
     }
     $bReadMessage = false;
     if ($lastId == null) {
         $strSql = "\n\t\t\t\tSELECT MAX(M.ID) ID, M.CHAT_ID\n\t\t\t\tFROM b_im_relation RF\n\t\t\t\t\tINNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID\n\t\t\t\t\tINNER JOIN b_im_message M ON M.ID >= RT.LAST_ID AND M.CHAT_ID = RT.CHAT_ID\n\t\t\t\tWHERE RT.USER_ID = " . $this->user_id . "\n\t\t\t\t\tand RF.USER_ID = " . $fromUserId . "\n\t\t\t\t\tand RT.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "' and RT.STATUS < " . IM_STATUS_READ . "\n\t\t\t\tGROUP 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']);
         }
         $lastId = $arRes['ID'];
     } else {
         $strSql = "\n\t\t\t\tSELECT RF.CHAT_ID\n\t\t\t\tFROM b_im_relation RF INNER JOIN b_im_relation RT on RF.CHAT_ID = RT.CHAT_ID\n\t\t\t\tWHERE RT.USER_ID = " . $this->user_id . "\n\t\t\t\t\tand RF.USER_ID = " . $fromUserId . "\n\t\t\t\t\tand RT.MESSAGE_TYPE = '" . IM_MESSAGE_PRIVATE . "'";
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($arRes = $dbRes->Fetch()) {
             $bReadMessage = self::SetLastId(intval($arRes['CHAT_ID']), $this->user_id, intval($lastId));
         }
     }
     if ($bReadMessage) {
         CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_MESSAGE);
         if (CModule::IncludeModule("pull")) {
             CPushManager::DeleteFromQueue($this->user_id, 'IM_MESS_' . $fromUserId);
             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' => $lastId)));
         }
         return true;
     }
     return false;
 }
Esempio n. 2
0
 public function SetReadMessage($chatId, $lastId = null)
 {
     global $DB;
     $chatId = intval($chatId);
     if ($chatId <= 0) {
         return false;
     }
     $bReadMessage = false;
     if ($lastId == null) {
         $strSql = "\n\t\t\t\tSELECT MAX(M.ID) ID, M.CHAT_ID\n\t\t\t\tFROM b_im_message M\n\t\t\t\tINNER JOIN b_im_relation R1 ON M.ID >= R1.LAST_ID AND M.CHAT_ID = R1.CHAT_ID\n\t\t\t\tWHERE R1.CHAT_ID = " . $chatId . " AND R1.USER_ID = " . $this->user_id . "\n\t\t\t\tGROUP BY M.CHAT_ID\n\t\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']);
         }
         $lastId = $arRes['ID'];
     } else {
         $bReadMessage = CIMMessage::SetLastId($chatId, $this->user_id, intval($lastId));
     }
     if ($bReadMessage) {
         CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_GROUP);
         if (CModule::IncludeModule("pull")) {
             CPushManager::DeleteFromQueue($this->user_id, 'IM_GROUP_' . $chatId);
             CPullStack::AddByUser($this->user_id, array('module_id' => 'im', 'command' => 'readMessageChat', 'params' => array('chatId' => $chatId, 'lastId' => $lastId)));
         }
         return true;
     }
     return false;
 }