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

Added table to store last read date. This permit to set unread messages on first refresh of contact list. We need to handle it at first load too

Note: this is an experimental thing. We need to set this cursor for every conversation to get better precision
This commit is contained in:
Loic Blot 2014-10-23 15:36:55 +00:00
parent 9b64b9ecee
commit 8f4dfd217f
5 changed files with 49 additions and 2 deletions

View File

@ -5,6 +5,30 @@
<overwrite>false</overwrite>
<charset>utf8</charset>
<table>
<name>*dbprefix*ocsms_user_datas</name>
<declaration>
<field>
<name>user_id</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>datakey</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>datavalue</name>
<type>text</type>
<length>64</length>
<notnull>true</notnull>
</field>
</declaration>
</table>
<table>
<name>*dbprefix*ocsms_smsdatas</name>
<declaration>

View File

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

View File

@ -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));
}
/**

View File

@ -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();

View File

@ -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);