mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-07-23 01:45:43 +00:00
prepare a function to get all messages for a conversation
This commit is contained in:
parent
7e72af1ccb
commit
cc13e01fe9
@ -5,6 +5,6 @@
|
||||
<description>Owncloud SMS app</description>
|
||||
<licence>AGPL</licence>
|
||||
<author>Loic Blot</author>
|
||||
<version>0.1.8</version>
|
||||
<version>0.2.0</version>
|
||||
<requiremin>7</requiremin>
|
||||
</info>
|
||||
|
@ -19,4 +19,5 @@ $application->registerRoutes($this, array('routes' => array(
|
||||
array('name' => 'sms#replace', 'url' => '/replace', 'verb' => 'POST'),
|
||||
array('name' => 'sms#retrieve_all_ids', 'url' => '/get/smsidlist', 'verb' => 'GET'),
|
||||
array('name' => 'sms#retrieve_all_peers', 'url' => '/get/peerlist', 'verb' => 'GET'),
|
||||
array('name' => 'sms#get_conversation', 'url' => '/get/conversation', 'verb' => 'GET'),
|
||||
)));
|
||||
|
@ -72,6 +72,16 @@ class SmsController extends Controller {
|
||||
return new JSONResponse(array("phonelist" => $phoneList));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function getConversation ($phoneNumber) {
|
||||
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $phoneNumber);
|
||||
// @ TODO: filter correctly
|
||||
return new JSONResponse(array("conversation" => $messages));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
|
@ -21,6 +21,12 @@ class SmsMapper extends Mapper {
|
||||
* on which mailbox it works
|
||||
*/
|
||||
private static $mailboxNames = array(0 => "inbox", 1 => "sent", 2 => "drafts");
|
||||
private static $messageTypes = array(
|
||||
0 => "all", 1 => "inbox",
|
||||
2 => "sent", 3 => "drafts",
|
||||
4 => "outbox", 5 => "failed",
|
||||
6 => "queued"
|
||||
);
|
||||
|
||||
public function __construct (IDb $db) {
|
||||
parent::__construct($db, 'ocsms_smsdatas');
|
||||
@ -59,6 +65,19 @@ class SmsMapper extends Mapper {
|
||||
return $phoneList;
|
||||
}
|
||||
|
||||
public function getAllMessagesForPhoneNumber ($userId, $phoneNumber) {
|
||||
$query = \OC_DB::prepare('SELECT sms_date, sms_msg, sms_type FROM ' .
|
||||
'*PREFIX*ocsms_smsdatas WHERE user_id = ? AND sms_mailbox IN (?,?)');
|
||||
$result = $query->execute(array($userId, 0, 1));
|
||||
|
||||
$messageList = array();
|
||||
while($row = $result->fetchRow()) {
|
||||
array_push($messageList[$row["sms_date"]], $row);
|
||||
}
|
||||
sort($messageList);
|
||||
return $messageList;
|
||||
}
|
||||
|
||||
public function writeToDB ($userId, $smsList, $purgeAllSmsBeforeInsert = false) {
|
||||
\OCP\DB::beginTransaction();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user