1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 07:56:23 +00:00

Prepare an APIv2 call to improve sync performance on phone (battery)

This commit is contained in:
Loic Blot 2014-11-30 18:05:20 +00:00
parent 5f0263f71e
commit f89a23c205
2 changed files with 27 additions and 1 deletions

View File

@ -80,6 +80,20 @@ class SmsController extends Controller {
return new JSONResponse(array("smslist" => $smsList));
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* This function is used by API v2
* Phone will get this ID to push recent messages
* This call will be used combined with retrieveAllIds
* but will be used more times
*/
public function retrieveLastTimestamp () {
$ts = $this->smsMapper->getLastTimestamp($this->userId);
return new JSONResponse(array("timestamp" => $ts));
}
/**
* @NoAdminRequired
* @NoCSRFRequired

View File

@ -72,6 +72,18 @@ class SmsMapper extends Mapper {
return $smsList;
}
public function getLastTimestamp ($userId) {
$query = \OCP\DB::prepare('SELECT max(sms_date) as mx FROM ' .
'*PREFIX*ocsms_smsdatas WHERE user_id = ?');
$result = $query->execute(array($userId));
if ($row = $result->fetchRow()) {
return $row["mx"];
}
return 0;
}
public function getAllPeersPhoneNumbers ($userId) {
$query = \OCP\DB::prepare('SELECT sms_address FROM ' .
'*PREFIX*ocsms_smsdatas WHERE user_id = ? AND sms_mailbox IN (?,?)');
@ -144,7 +156,7 @@ class SmsMapper extends Mapper {
'*PREFIX*ocsms_smsdatas WHERE user_id = ? AND sms_address = ? ' .
'AND sms_mailbox IN (?,?)');
foreach( $phlst as $pn => $val) {
foreach($phlst as $pn => $val) {
$result = $query->execute(array($userId, $pn, 0, 1));
if ($row = $result->fetchRow())
$cnt += $row["ct"];