From a933c53fb8ebd7287d2dd98e0e08d26f23de7eb5 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 9 Oct 2014 10:02:22 +0000 Subject: [PATCH] Add two new API calls: getApiVersion and getAllIdsWithStatus --- appinfo/routes.php | 2 ++ controller/smscontroller.php | 17 +++++++++++++++++ db/smsmapper.php | 21 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 6147ff1..953ea24 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -18,6 +18,8 @@ $application->registerRoutes($this, array('routes' => array( array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'), array('name' => 'sms#replace', 'url' => '/replace', 'verb' => 'POST'), array('name' => 'sms#retrieve_all_ids', 'url' => '/get/smsidlist', 'verb' => 'GET'), + array('name' => 'sms#retrieve_all_ids_with_status', 'url' => '/get/smsidstate', 'verb' => 'GET'), array('name' => 'sms#retrieve_all_peers', 'url' => '/get/peerlist', 'verb' => 'GET'), array('name' => 'sms#get_conversation', 'url' => '/get/conversation', 'verb' => 'GET'), + array('name' => 'sms#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), ))); diff --git a/controller/smscontroller.php b/controller/smscontroller.php index 96012c0..9378d6b 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -57,6 +57,14 @@ class SmsController extends Controller { return new TemplateResponse($this->appName, 'main', $params); } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getApiVersion () { + return new JSONResponse(array("version" => 1)); + } + /** * @NoAdminRequired * @NoCSRFRequired @@ -66,6 +74,15 @@ class SmsController extends Controller { return new JSONResponse(array("smslist" => $smsList)); } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function retrieveAllIdsWithStatus () { + $smsList = $this->smsMapper->getAllIdsWithStatus($this->userId); + return new JSONResponse(array("smslist" => $smsList)); + } + /** * @NoAdminRequired * @NoCSRFRequired diff --git a/db/smsmapper.php b/db/smsmapper.php index 48ec313..eb87c0e 100644 --- a/db/smsmapper.php +++ b/db/smsmapper.php @@ -34,7 +34,7 @@ class SmsMapper extends Mapper { public function getAllIds ($userId) { $query = \OCP\DB::prepare('SELECT sms_id, sms_mailbox FROM ' . - '*PREFIX*ocsms_smsdatas WHERE user_id = ?'); + '*PREFIX*ocsms_smsdatas WHERE user_id = ?'); $result = $query->execute(array($userId)); $smsList = array(); @@ -51,6 +51,25 @@ class SmsMapper extends Mapper { return $smsList; } + public function getAllIdsWithStatus ($userId) { + $query = \OCP\DB::prepare('SELECT sms_id, sms_type, sms_mailbox FROM ' . + '*PREFIX*ocsms_smsdatas WHERE user_id = ?'); + $result = $query->execute(array($userId)); + + $smsList = array(); + while($row = $result->fetchRow()) { + $mbox = SmsMapper::$mailboxNames[$row["sms_mailbox"]]; + if (!isset($smsList[$mbox])) { + $smsList[$mbox] = array(); + } + + if (!isset($smsList[$mbox][$row["sms_id"]])) { + $smsList[$mbox][$row["sms_id"]] = $row["sms_type"]; + } + } + return $smsList; + } + public function getAllPeersPhoneNumbers ($userId) { $query = \OCP\DB::prepare('SELECT sms_address FROM ' . '*PREFIX*ocsms_smsdatas WHERE user_id = ? AND sms_mailbox IN (?,?)');