1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-09 08:56:10 +00:00

Fix number with spaces issue into peerlist

* Also factorize one function
This commit is contained in:
Loic Blot 2014-10-22 12:38:36 +00:00
parent f94d3ea277
commit 621383e996
3 changed files with 19 additions and 18 deletions

View File

@ -115,23 +115,23 @@ class OcSmsApp extends App {
if (is_array($phoneIds)) { if (is_array($phoneIds)) {
$countPhone = count($phoneIds); $countPhone = count($phoneIds);
for ($i=0; $i < $countPhone; $i++) { for ($i=0; $i < $countPhone; $i++) {
$phoneNb = preg_replace("#[ ]#", "", $phoneIds[$i]); $this->pushPhoneNumberToCache($phoneIds[$i], $r["FN"]);
self::$contacts[$phoneNb] = $r["FN"];
if (!isset(self::$contactsInverted[$r["FN"]])) {
self::$contactsInverted[$r["FN"]] = array();
}
array_push(self::$contactsInverted[$r["FN"]], $phoneNb);
} }
} }
else { else {
self::$contacts[$phoneIds] = $r["FN"]; $this->pushPhoneNumberToCache($phoneIds, $r["FN"]);
if (!isset(self::$contactsInverted[$r["FN"]])) {
self::$contactsInverted[$r["FN"]] = array();
}
array_push(self::$contactsInverted[$r["FN"]], $phoneIds);
} }
} }
} }
} }
private function pushPhoneNumberToCache($rawPhone, $contactName) {
$phoneNb = preg_replace("#[ ]#", "/", $rawPhone);
self::$contacts[$phoneNb] = $contactName;
if (!isset(self::$contactsInverted[$contactName])) {
self::$contactsInverted[$contactName] = array();
}
array_push(self::$contactsInverted[$contactName], $phoneNb);
}
} }

View File

@ -94,8 +94,9 @@ class SmsController extends Controller {
$countPhone = count($phoneList); $countPhone = count($phoneList);
for ($i=0; $i < $countPhone; $i++) { for ($i=0; $i < $countPhone; $i++) {
if (isset($contactsSrc[$phoneList[$i]])) { $fmtPN = preg_replace("#[ ]#","/", $phoneList[$i]);
$contacts[$phoneList[$i]] = $contactsSrc[$phoneList[$i]]; if (isset($contactsSrc[$fmtPN])) {
$contacts[$fmtPN] = $contactsSrc[$fmtPN];
} }
} }
// @ TODO: filter correctly // @ TODO: filter correctly

View File

@ -197,14 +197,14 @@ function fetchInitialPeerList(jsondata) {
var bufferedContacts = []; var bufferedContacts = [];
$.each(jsondata['phonelist'], function(id, val) { $.each(jsondata['phonelist'], function(id, val) {
var fn, peerLabel, idxVal;
var fn, peerLabel; idxVal = val.replace(/ /g,'/');
if (typeof jsondata['contacts'][val] == 'undefined') { if (typeof jsondata['contacts'][idxVal] == 'undefined') {
fn = ''; fn = '';
peerLabel = val; peerLabel = val;
} }
else { else {
fn = jsondata['contacts'][val]; fn = jsondata['contacts'][idxVal];
peerLabel = fn; peerLabel = fn;
} }
if ($.inArray(peerLabel, bufferedContacts) == -1) { if ($.inArray(peerLabel, bufferedContacts) == -1) {