mirror of
https://github.com/nextcloud/ocsms.git
synced 2026-08-11 16:32:55 +00:00
APIv2 improvements
* prepare a table for messaging sending queue * drop retrieveAllIdsWithStatus and related API call (unused and dropped from Android app devel version) * reorganise api controller
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user