mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 07:56:23 +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:
parent
8f4dfd217f
commit
690421713d
@ -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,
|
||||
|
@ -151,16 +151,28 @@ class SmsMapper extends Mapper {
|
||||
return $phoneList;
|
||||
}
|
||||
|
||||
public function setLastReadDate ($userId, $lastDate) {
|
||||
public function getLastReadDate ($userId) {
|
||||
$sql = 'SELECT MAX(datavalue) as mx FROM ' .
|
||||
'*PREFIX*ocsms_user_datas WHERE user_id = ?';
|
||||
|
||||
$query = \OCP\DB::prepare($sql);
|
||||
$result = $query->execute(array($userId));
|
||||
|
||||
if ($row = $result->fetchRow()) {
|
||||
return $row["mx"];
|
||||
}
|
||||
}
|
||||
|
||||
public function setLastReadDate ($userId, $phoneNumber, $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->execute(array($userId, 'lastReadDate-' . $phoneNumber));
|
||||
|
||||
$query = \OCP\DB::prepare('INSERT INTO *PREFIX*ocsms_user_datas' .
|
||||
'(user_id, datakey, datavalue) VALUES ' .
|
||||
'(?,?,?)');
|
||||
$query->execute(array($userId, 'lastReadDate', $lastDate));
|
||||
$query->execute(array($userId, 'lastReadDate-' . $phoneNumber, $lastDate));
|
||||
\OCP\DB::commit();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user