1
0
mirror of https://github.com/nextcloud/ocsms.git synced 2026-08-11 16:32:55 +00:00

Set last read date per conversation

The next step will be to get unread messages per conversation when loading interface at first time, not globally
This commit is contained in:
Loic Blot
2014-10-23 16:23:11 +00:00
parent 8f4dfd217f
commit 690421713d
2 changed files with 25 additions and 10 deletions
+10 -7
View File
@@ -93,7 +93,6 @@ class SmsController extends Controller {
$contacts = array();
$countPhone = count($phoneList);
$maxTS = 0;
foreach ($phoneList as $number => $ts) {
$fmtPN = preg_replace("#[ ]#","/", $number);
if (isset($contactsSrc[$fmtPN])) {
@@ -101,15 +100,11 @@ class SmsController extends Controller {
$contacts[$fmtPN] = $contactsSrc[$fmtPN];
$contacts[$fmtPN2] = $contactsSrc[$fmtPN];
}
if ($ts > $maxTS) {
$maxTS = $ts;
}
}
$this->smsMapper->setLastReadDate($this->userId, $maxTS);
$lastRead = $this->smsMapper->getLastReadDate($this->userId);
return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "lastRead" => $maxTS));
return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "lastRead" => $lastRead));
}
/**
@@ -171,6 +166,14 @@ class SmsController extends Controller {
// Order by id (date)
ksort($messages);
// Set the last read message for the conversation (all phone numbers)
if (count($messages) > 0) {
$maxDate = max(array_keys($messages));
for ($i=0;$i<count($phoneNumbers);$i++) {
$this->smsMapper->setLastReadDate($this->userId, $phoneNumbers[$i], $maxDate);
}
}
// @ TODO: filter correctly
return new JSONResponse(array("conversation" => $messages, "contactName" => $contactName,