mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 07:56:23 +00:00
Really fix the thing into conversations
This commit is contained in:
parent
74511c4c60
commit
20db5d6a7f
@ -88,18 +88,18 @@ class SmsController extends Controller {
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function retrieveAllPeers () {
|
||||
$phoneList = $this->smsMapper->getAllPeersPhoneNumbers($this->userId);
|
||||
$phoneList = $this->smsMapper->getLastMessageTimestampForAllPhonesNumbers($this->userId);
|
||||
$contactsSrc = $this->app->getContacts();
|
||||
$contacts = array();
|
||||
|
||||
$countPhone = count($phoneList);
|
||||
for ($i=0; $i < $countPhone; $i++) {
|
||||
$fmtPN = preg_replace("#[ ]#","/", $phoneList[$i]);
|
||||
foreach ($phoneList as $number => $ts) {
|
||||
$fmtPN = preg_replace("#[ ]#","/", $number);
|
||||
if (isset($contactsSrc[$fmtPN])) {
|
||||
$contacts[$fmtPN] = $contactsSrc[$fmtPN];
|
||||
}
|
||||
}
|
||||
// @ TODO: filter correctly
|
||||
|
||||
return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts));
|
||||
}
|
||||
|
||||
@ -129,22 +129,24 @@ class SmsController extends Controller {
|
||||
|
||||
// We merge each message list into global messagelist
|
||||
for ($i=0; $i < $ctPn; $i++) {
|
||||
$messages = $messages +
|
||||
$this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $iContacts[$contactName][$i], $lastDate);
|
||||
|
||||
// Remove slashes
|
||||
$fmtPN = preg_replace("#[/]#"," ", $iContacts[$contactName][$i]);
|
||||
|
||||
$messages = $messages +
|
||||
$this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $fmtPN, $lastDate);
|
||||
|
||||
$phoneNumbers[] = $fmtPN;
|
||||
|
||||
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $iContacts[$contactName][$i]);
|
||||
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $phoneNumber, $lastDate);
|
||||
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $phoneNumber);
|
||||
|
||||
// remove slashes
|
||||
$fmtPN = preg_replace("#[/]#"," ", $phoneNumber);
|
||||
|
||||
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $fmtPN, $lastDate);
|
||||
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
|
||||
|
||||
$phoneNumbers[] = $fmtPN;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
\OCP\DB::beginTransaction();
|
||||
|
||||
|
10
js/script.js
10
js/script.js
@ -198,17 +198,17 @@ function fetchInitialPeerList(jsondata) {
|
||||
|
||||
$.each(jsondata['phonelist'], function(id, val) {
|
||||
var fn, peerLabel, idxVal;
|
||||
idxVal = val.replace(/ /g,'/');
|
||||
if (typeof jsondata['contacts'][idxVal] == 'undefined') {
|
||||
idxVal = id.replace(/\//g,' ');
|
||||
if (typeof jsondata['contacts'][id] == 'undefined') {
|
||||
fn = '';
|
||||
peerLabel = val;
|
||||
peerLabel = id;
|
||||
}
|
||||
else {
|
||||
fn = jsondata['contacts'][idxVal];
|
||||
fn = jsondata['contacts'][id];
|
||||
peerLabel = fn;
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user