diff --git a/appinfo/database.xml b/appinfo/database.xml
index bf15bbb..abfc59c 100644
--- a/appinfo/database.xml
+++ b/appinfo/database.xml
@@ -104,6 +104,38 @@
+
+ *dbprefix*ocsms_sendmessage_queue
+
+
+ id
+ integer
+ 0
+ true
+ 1
+ 10
+ true
+
+
+ user_id
+ text
+ true
+ 64
+
+
+ sms_address
+ text
+ true
+ 64
+
+
+ sms_msg
+ text
+ true
+ 2048
+
+
+
*dbprefix*ocsms_config
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 260502f..ec0ca62 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -31,11 +31,11 @@ $application->registerRoutes($this, array('routes' => array(
array('name' => 'api#push', 'url' => '/push', 'verb' => 'POST'), // Android API
array('name' => 'api#replace', 'url' => '/replace', 'verb' => 'POST'), // Android API
array('name' => 'api#retrieve_all_ids', 'url' => '/get/smsidlist', 'verb' => 'GET'), // Android APIv1
- array('name' => 'api#retrieve_all_ids_with_status', 'url' => '/get/smsidstate', 'verb' => 'GET'), // Android APIv1
array('name' => 'api#retrieve_last_timestamp', 'url' => '/get/lastmsgtime', 'verb' => 'GET'), // Android APIv1
// API v2
- array('name' => 'api#get_all_stored_phone_numbers', 'url' => '/api/v2/get/phones/numberlist', 'verb' => 'GET'), // Android APIv2
+ array('name' => 'api#get_all_stored_phone_numbers', 'url' => '/api/v2/phones/list', 'verb' => 'GET'), // Android APIv2
array('name' => 'api#fetch_messages', 'url' => '/api/v2/messages/{start}/{limit}', 'verb' => 'GET'), // Android APIv2
array('name' => 'api#fetch_messages_for_number', 'url' => '/api/v2/messages/{phonenumber}/{start}/{limit}', 'verb' => 'GET'), // Android APIv2
+ array('name' => 'api#fetch_messages_to_send', 'url' => '/api/v2/messages/sendqueue', 'verb' => 'GET'), // Android APIv2
)));
diff --git a/controller/apicontroller.php b/controller/apicontroller.php
index 1f3ae59..3b13ee3 100644
--- a/controller/apicontroller.php
+++ b/controller/apicontroller.php
@@ -71,26 +71,6 @@ class ApiController extends Controller {
return new JSONResponse(array("timestamp" => $ts));
}
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- */
- public function retrieveAllIdsWithStatus () {
- $smsList = $this->smsMapper->getAllIdsWithStatus($this->userId);
- return new JSONResponse(array("smslist" => $smsList));
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- *
- * API v2
- */
- public function getAllStoredPhoneNumbers () {
- $phoneList = $this->smsMapper->getAllPhoneNumbers($this->userId);
- return new JSONResponse(array("phoneList" => $phoneList));
- }
-
/**
* @NoAdminRequired
* @NoCSRFRequired
@@ -116,41 +96,6 @@ class ApiController extends Controller {
return new JSONResponse(array("status" => true, "msg" => "OK"));
}
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- *
- * APIv2
- */
- public function fetchMessages($start, $limit) {
- if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) {
- return new JSONResponse(array("msg" => "Invalid request"), \OCP\AppFramework\Http::STATUS_BAD_REQUEST);
- }
-
- // Limit messages per fetch to prevent phone garbage collecting due to too many datas
- if ($limit > 500) {
- return new JSONResponse(array("msg" => "Too many messages requested"), 413);
- }
-
- $messages = $this->smsMapper->getMessages($this->userId, $start, $limit);
- return new JSONResponse(array("messages" => $messages));
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- *
- * APIv2
- */
- public function fetchMessagesForNumber($phoneNumber, $start, $limit) {
- if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) {
- return new JSONResponse(array("msg" => "Invalid request"), \OCP\AppFramework\Http::STATUS_BAD_REQUEST);
- }
-
- // @TODO because multiple phone numbers can be same number with different formatting
- return new JSONResponse(array("messages" => array()));
- }
-
private function checkPushStructure ($smsCount, $smsDatas) {
if ($smsCount != count($smsDatas)) {
$this->errorMsg = "Error: sms count invalid";
@@ -201,4 +146,61 @@ class ApiController extends Controller {
}
return true;
}
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * API v2
+ */
+ public function getAllStoredPhoneNumbers () {
+ $phoneList = $this->smsMapper->getAllPhoneNumbers($this->userId);
+ return new JSONResponse(array("phoneList" => $phoneList));
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * APIv2
+ */
+ public function fetchMessages($start, $limit) {
+ if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) {
+ return new JSONResponse(array("msg" => "Invalid request"), \OCP\AppFramework\Http::STATUS_BAD_REQUEST);
+ }
+
+ // Limit messages per fetch to prevent phone garbage collecting due to too many datas
+ if ($limit > 500) {
+ return new JSONResponse(array("msg" => "Too many messages requested"), 413);
+ }
+
+ $messages = $this->smsMapper->getMessages($this->userId, $start, $limit);
+ return new JSONResponse(array("messages" => $messages));
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * APIv2
+ */
+ public function fetchMessagesForNumber($phoneNumber, $start, $limit) {
+ if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) {
+ return new JSONResponse(array("msg" => "Invalid request"), \OCP\AppFramework\Http::STATUS_BAD_REQUEST);
+ }
+
+ // @TODO because multiple phone numbers can be same number with different formatting
+ return new JSONResponse(array("messages" => array()));
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * APIv2
+ */
+ public function fetchMessagesToSend() {
+ // @TODO
+ return new JSONResponse(array("messages" => array()));
+ }
}
diff --git a/db/smsmapper.php b/db/smsmapper.php
index 145f7d5..7854c67 100644
--- a/db/smsmapper.php
+++ b/db/smsmapper.php
@@ -58,29 +58,6 @@ 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()) {
- // This case may not arrive, but we test if the DB is consistent
- if (!in_array($row["sms_mailbox"], SmsMapper::$mailboxNames)) {
- continue;
- }
- $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 getLastTimestamp ($userId) {
$query = \OCP\DB::prepare('SELECT max(sms_date) as mx FROM ' .
'*PREFIX*ocsms_smsdatas WHERE user_id = ?');