diff --git a/appinfo/database.xml b/appinfo/database.xml
index 5085676..4304bea 100644
--- a/appinfo/database.xml
+++ b/appinfo/database.xml
@@ -5,6 +5,30 @@
false
utf8
+
+ *dbprefix*ocsms_user_datas
+
+
+ user_id
+ text
+ true
+ 64
+
+
+ datakey
+ text
+ true
+ 64
+
+
+ datavalue
+ text
+ 64
+ true
+
+
+
+
*dbprefix*ocsms_smsdatas
diff --git a/appinfo/info.xml b/appinfo/info.xml
index e9d70a2..4c1ff67 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,6 +5,6 @@
Owncloud SMS app
AGPL
Loic Blot
- 1.2.0
+ 1.2.3
7
diff --git a/controller/smscontroller.php b/controller/smscontroller.php
index 11e4d2d..8cedb60 100644
--- a/controller/smscontroller.php
+++ b/controller/smscontroller.php
@@ -93,6 +93,7 @@ class SmsController extends Controller {
$contacts = array();
$countPhone = count($phoneList);
+ $maxTS = 0;
foreach ($phoneList as $number => $ts) {
$fmtPN = preg_replace("#[ ]#","/", $number);
if (isset($contactsSrc[$fmtPN])) {
@@ -100,9 +101,15 @@ class SmsController extends Controller {
$contacts[$fmtPN] = $contactsSrc[$fmtPN];
$contacts[$fmtPN2] = $contactsSrc[$fmtPN];
}
+
+ if ($ts > $maxTS) {
+ $maxTS = $ts;
+ }
}
- return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts));
+ $this->smsMapper->setLastReadDate($this->userId, $maxTS);
+
+ return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "lastRead" => $maxTS));
}
/**
diff --git a/db/smsmapper.php b/db/smsmapper.php
index c3535fe..d492c87 100644
--- a/db/smsmapper.php
+++ b/db/smsmapper.php
@@ -150,6 +150,20 @@ class SmsMapper extends Mapper {
}
return $phoneList;
}
+
+ public function setLastReadDate ($userId, $lastDate) {
+ \OCP\DB::beginTransaction();
+ $query = \OCP\DB::prepare('DELETE FROM *PREFIX*ocsms_user_datas ' .
+ 'WHERE user_id = ? AND datakey = ?');
+ $query->execute(array($userId, 'lastReadDate'));
+
+ $query = \OCP\DB::prepare('INSERT INTO *PREFIX*ocsms_user_datas' .
+ '(user_id, datakey, datavalue) VALUES ' .
+ '(?,?,?)');
+ $query->execute(array($userId, 'lastReadDate', $lastDate));
+ \OCP\DB::commit();
+ }
+
public function writeToDB ($userId, $smsList, $purgeAllSmsBeforeInsert = false) {
\OCP\DB::beginTransaction();
diff --git a/js/script.js b/js/script.js
index 06e363f..83c6f03 100644
--- a/js/script.js
+++ b/js/script.js
@@ -264,6 +264,8 @@ function fetchInitialPeerList(jsondata) {
}
});
+ lastMsgDate = jsondata["lastRead"];
+
// Only modify peerList if there is peers
if (peerListBuf != '') {
$('#app-mailbox-peers ul').html(peerListBuf);