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

Really fix the thing into conversations

This commit is contained in:
Loic Blot 2014-10-22 16:02:13 +00:00
parent 74511c4c60
commit 20db5d6a7f
3 changed files with 34 additions and 16 deletions

View File

@ -88,18 +88,18 @@ class SmsController extends Controller {
* @NoCSRFRequired * @NoCSRFRequired
*/ */
public function retrieveAllPeers () { public function retrieveAllPeers () {
$phoneList = $this->smsMapper->getAllPeersPhoneNumbers($this->userId); $phoneList = $this->smsMapper->getLastMessageTimestampForAllPhonesNumbers($this->userId);
$contactsSrc = $this->app->getContacts(); $contactsSrc = $this->app->getContacts();
$contacts = array(); $contacts = array();
$countPhone = count($phoneList); $countPhone = count($phoneList);
for ($i=0; $i < $countPhone; $i++) { foreach ($phoneList as $number => $ts) {
$fmtPN = preg_replace("#[ ]#","/", $phoneList[$i]); $fmtPN = preg_replace("#[ ]#","/", $number);
if (isset($contactsSrc[$fmtPN])) { if (isset($contactsSrc[$fmtPN])) {
$contacts[$fmtPN] = $contactsSrc[$fmtPN]; $contacts[$fmtPN] = $contactsSrc[$fmtPN];
} }
} }
// @ TODO: filter correctly
return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts)); return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts));
} }
@ -129,22 +129,24 @@ class SmsController extends Controller {
// We merge each message list into global messagelist // We merge each message list into global messagelist
for ($i=0; $i < $ctPn; $i++) { for ($i=0; $i < $ctPn; $i++) {
$messages = $messages +
$this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $iContacts[$contactName][$i], $lastDate);
// Remove slashes // Remove slashes
$fmtPN = preg_replace("#[/]#"," ", $iContacts[$contactName][$i]); $fmtPN = preg_replace("#[/]#"," ", $iContacts[$contactName][$i]);
$messages = $messages +
$this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $fmtPN, $lastDate);
$phoneNumbers[] = $fmtPN; $phoneNumbers[] = $fmtPN;
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $iContacts[$contactName][$i]); $msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
} }
} }
else { else {
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $phoneNumber, $lastDate);
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $phoneNumber);
// remove slashes // remove slashes
$fmtPN = preg_replace("#[/]#"," ", $phoneNumber); $fmtPN = preg_replace("#[/]#"," ", $phoneNumber);
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $fmtPN, $lastDate);
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
$phoneNumbers[] = $fmtPN; $phoneNumbers[] = $fmtPN;
} }

View File

@ -111,6 +111,22 @@ class SmsMapper extends Mapper {
} }
} }
public function getLastMessageTimestampForAllPhonesNumbers ($userId) {
$query = \OCP\DB::prepare('SELECT sms_address,MAX(sms_date) as mx FROM ' .
'*PREFIX*ocsms_smsdatas WHERE user_id = ? AND sms_mailbox IN (?,?) ' .
'GROUP BY sms_address');
$result = $query->execute(array($userId, 0, 1));
$phoneList = array();
while ($row = $result->fetchRow()) {
$phoneNumber = preg_replace("#[ ]#", "/", $row["sms_address"]);
if (!in_array($phoneNumber, $phoneList)) {
$phoneList[$phoneNumber] = $row["mx"];
}
}
return $phoneList;
}
public function writeToDB ($userId, $smsList, $purgeAllSmsBeforeInsert = false) { public function writeToDB ($userId, $smsList, $purgeAllSmsBeforeInsert = false) {
\OCP\DB::beginTransaction(); \OCP\DB::beginTransaction();

View File

@ -198,17 +198,17 @@ function fetchInitialPeerList(jsondata) {
$.each(jsondata['phonelist'], function(id, val) { $.each(jsondata['phonelist'], function(id, val) {
var fn, peerLabel, idxVal; var fn, peerLabel, idxVal;
idxVal = val.replace(/ /g,'/'); idxVal = id.replace(/\//g,' ');
if (typeof jsondata['contacts'][idxVal] == 'undefined') { if (typeof jsondata['contacts'][id] == 'undefined') {
fn = ''; fn = '';
peerLabel = val; peerLabel = id;
} }
else { else {
fn = jsondata['contacts'][idxVal]; fn = jsondata['contacts'][id];
peerLabel = fn; peerLabel = fn;
} }
if ($.inArray(peerLabel, bufferedContacts) == -1) { if ($.inArray(peerLabel, bufferedContacts) == -1) {
peerListBuf += '<li><a href="#" mailbox-navigation="' + val + '">' + peerLabel + '</a></li>'; peerListBuf += '<li><a href="#" mailbox-navigation="' + idxVal + '">' + peerLabel + '</a></li>';
bufferedContacts.push(peerLabel); bufferedContacts.push(peerLabel);
} }
}); });