Count the messages from the last received message - refs #7338

1.9.x
Angel Fernando Quiroz Campos 10 years ago
parent c8f940be4a
commit 4a5c020e64
  1. 30
      main/inc/lib/message.lib.php
  2. 9
      webservices/classes/MessagesWebService.class.php
  3. 4
      webservices/rest.php

@ -1508,4 +1508,34 @@ class MessageManager
$html .= $table->return_table();
return $html;
}
/**
* Get the count of the last received messages for a user
* @param int $userId The user id
* @param int $lastId The id of the last seen message
* @return int The count of new messages
*/
public static function countMessagesFromLastReceivedMessage($userId, $lastId)
{
$messagesTable = Database::get_main_table(TABLE_MESSAGE);
$conditions = array(
'where' => array(
'user_receiver_id = ?' => $userId,
'AND msg_status = ?' => MESSAGE_STATUS_UNREAD,
'AND id > ?' => $lastId
)
);
$result = Database::select('COUNT(1) AS qty', $messagesTable, $conditions);
if (!empty($result)) {
$row = current($result);
return $row['qty'];
}
return 0;
}
}

@ -110,9 +110,14 @@ class MessagesWebService extends WebService
* @param string $username The username
* @return int The count fo new messages
*/
public function countNewMessages($username)
public function countNewMessages($username, $lastId = 0)
{
return 0;
$lastId = intval($lastId);
$userInfo = api_get_user_info_from_username($username);
$userId = intval($userInfo['user_id']);
return MessageManager::countMessagesFromLastReceivedMessage($userId, $lastId);
}
/**

@ -40,7 +40,9 @@ switch ($action) {
$webService = new MessagesWebService();
$webService->setApiKey($apiKey);
$count = $webService->countNewMessages($username);
$lastId = isset($_POST['last']) ? $_POST['last'] : 0;
$count = $webService->countNewMessages($username, $lastId);
$json = array(
'count' => $count

Loading…
Cancel
Save