コード例 #1
0
ファイル: im_message.php プロジェクト: Satariall/izurit
 public static function SetLastId($chatId, $userId, $lastId = null)
 {
     $chatId = intval($chatId);
     $userId = intval($userId);
     $lastId = intval($lastId);
     if ($chatId <= 0 || $userId <= 0) {
         return false;
     }
     $relationList = IM\RelationTable::getList(array("select" => array("ID", "LAST_ID", "LAST_SEND_ID"), "filter" => array("=CHAT_ID" => $chatId, "=USER_ID" => $userId)));
     while ($relation = $relationList->fetch()) {
         $update = array("STATUS" => IM_STATUS_READ);
         if ($lastId > 0) {
             $update = array();
             if ($relation["LAST_ID"] < $lastId) {
                 $update["LAST_ID"] = $lastId;
             }
             if ($relation["LAST_SEND_ID"] < $lastId) {
                 $update["LAST_SEND_ID"] = $lastId;
             }
             if (!IM\MessageTable::getCount(array(">ID" => $lastId, "=CHAT_ID" => $chatId))) {
                 $update["STATUS"] = IM_STATUS_READ;
             }
         }
         if ($update) {
             $update["LAST_READ"] = new Bitrix\Main\Type\DateTime();
             IM\RelationTable::update($relation["ID"], $update);
         }
     }
     return true;
 }