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

Change protocol. We receive a mailbox ID, drafts are contained into this mailbox ID.

This commit is contained in:
Loïc Blot (@U-Exp) 2014-09-12 19:42:54 +02:00
parent 5cef955d23
commit 0132ca90db
4 changed files with 19 additions and 13 deletions

View File

@ -63,8 +63,14 @@
<name>sms_flags</name> <name>sms_flags</name>
<type>text</type> <type>text</type>
<notnull>true</notnull> <notnull>true</notnull>
<default>000</default> <default>00</default>
<length>3</length> <length>2</length>
</field>
<field>
<name>sms_mailbox</name>
<type>integer</type>
<notnull>true</notnull>
<length>1</length>
</field> </field>
</declaration> </declaration>
</table> </table>

View File

@ -5,6 +5,6 @@
<description>Owncloud SMS app</description> <description>Owncloud SMS app</description>
<licence>AGPL</licence> <licence>AGPL</licence>
<author>Loic Blot</author> <author>Loic Blot</author>
<version>0.1.4</version> <version>0.1.5</version>
<requiremin>7</requiremin> <requiremin>7</requiremin>
</info> </info>

View File

@ -60,20 +60,23 @@ class SmsController extends Controller {
foreach ($smsDatas as &$sms) { foreach ($smsDatas as &$sms) {
if (!array_key_exists("_id", $sms) || !array_key_exists("read", $sms) || if (!array_key_exists("_id", $sms) || !array_key_exists("read", $sms) ||
!array_key_exists("date", $sms) || !array_key_exists("seen", $sms) || !array_key_exists("date", $sms) || !array_key_exists("seen", $sms) ||
!array_key_exists("mbox", $sms) ||
!array_key_exists("body", $sms) || !array_key_exists("address", $sms)) { !array_key_exists("body", $sms) || !array_key_exists("address", $sms)) {
$this->errorMsg = "Error: bad SMS entry"; $this->errorMsg = "Error: bad SMS entry";
return false; return false;
} }
if (!array_key_exists("draft", $sms)) {
$sms["draft"] = "true";
}
if (!is_numeric($sms["_id"])) { if (!is_numeric($sms["_id"])) {
$this->errorMsg = sprintf("Error: Invalid SMS ID '%s'", $sms["_id"]); $this->errorMsg = sprintf("Error: Invalid SMS ID '%s'", $sms["_id"]);
return false; return false;
} }
if (!is_numeric($sms["mbox"]) && $sms["mbox"] != 0 && $sms["mbox"] != 1 &&
$sms["mbox"] != 2) {
$this->errorMsg = sprintf("Error: Invalid Mailbox ID '%s'", $sms["mbox"]);
return false;
}
if ($sms["read"] !== "true" && $sms["read"] !== "false") { if ($sms["read"] !== "true" && $sms["read"] !== "false") {
$this->errorMsg = sprintf("Error: Invalid SMS Read state '%s'", $sms["read"]); $this->errorMsg = sprintf("Error: Invalid SMS Read state '%s'", $sms["read"]);
return false; return false;
@ -98,6 +101,4 @@ class SmsController extends Controller {
} }
return true; return true;
} }
} }

View File

@ -23,15 +23,14 @@ class SmsMapper extends Mapper {
// @TODO // @TODO
public function saveAll($userId, $smsList) { public function saveAll($userId, $smsList) {
foreach ($smsList as $sms) { foreach ($smsList as $sms) {
$smsFlags = sprintf("%s%s%s", $smsFlags = sprintf("%s%s",
$sms["read"] === "true" ? "1" : "0", $sms["read"] === "true" ? "1" : "0",
$sms["seen"] === "true" ? "1" : "0", $sms["seen"] === "true" ? "1" : "0"
$sms["draft"] === "true" ? "1" : "0"
); );
$query = \OC_DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' . $query = \OC_DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' .
'(user_id, added, lastmodified, sms_flags, sms_date, sms_id,' . '(user_id, added, lastmodified, sms_flags, sms_date, sms_id,' .
'sms_address, sms_msg) VALUES ' . 'sms_address, sms_msg, sms_mailbox) VALUES ' .
'(?,?,?,?,?,?,?,?)'); '(?,?,?,?,?,?,?,?)');
$result = $query->execute(array( $result = $query->execute(array(
$userId, "NOW()", "NOW()", $smsFlags, $userId, "NOW()", "NOW()", $smsFlags,