diff --git a/appinfo/ocsmsapp.php b/appinfo/ocsmsapp.php index 4b45fb8..4dab8e6 100644 --- a/appinfo/ocsmsapp.php +++ b/appinfo/ocsmsapp.php @@ -115,23 +115,23 @@ class OcSmsApp extends App { if (is_array($phoneIds)) { $countPhone = count($phoneIds); for ($i=0; $i < $countPhone; $i++) { - $phoneNb = preg_replace("#[ ]#", "", $phoneIds[$i]); - - self::$contacts[$phoneNb] = $r["FN"]; - if (!isset(self::$contactsInverted[$r["FN"]])) { - self::$contactsInverted[$r["FN"]] = array(); - } - array_push(self::$contactsInverted[$r["FN"]], $phoneNb); + $this->pushPhoneNumberToCache($phoneIds[$i], $r["FN"]); } } else { - self::$contacts[$phoneIds] = $r["FN"]; - if (!isset(self::$contactsInverted[$r["FN"]])) { - self::$contactsInverted[$r["FN"]] = array(); - } - array_push(self::$contactsInverted[$r["FN"]], $phoneIds); + $this->pushPhoneNumberToCache($phoneIds, $r["FN"]); } } } } + + 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); + } } diff --git a/controller/smscontroller.php b/controller/smscontroller.php index 13accb1..9a34449 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -94,8 +94,9 @@ class SmsController extends Controller { $countPhone = count($phoneList); for ($i=0; $i < $countPhone; $i++) { - if (isset($contactsSrc[$phoneList[$i]])) { - $contacts[$phoneList[$i]] = $contactsSrc[$phoneList[$i]]; + $fmtPN = preg_replace("#[ ]#","/", $phoneList[$i]); + if (isset($contactsSrc[$fmtPN])) { + $contacts[$fmtPN] = $contactsSrc[$fmtPN]; } } // @ TODO: filter correctly diff --git a/js/script.js b/js/script.js index 4be6d93..25c769b 100644 --- a/js/script.js +++ b/js/script.js @@ -197,14 +197,14 @@ function fetchInitialPeerList(jsondata) { var bufferedContacts = []; $.each(jsondata['phonelist'], function(id, val) { - - var fn, peerLabel; - if (typeof jsondata['contacts'][val] == 'undefined') { + var fn, peerLabel, idxVal; + idxVal = val.replace(/ /g,'/'); + if (typeof jsondata['contacts'][idxVal] == 'undefined') { fn = ''; peerLabel = val; } else { - fn = jsondata['contacts'][val]; + fn = jsondata['contacts'][idxVal]; peerLabel = fn; } if ($.inArray(peerLabel, bufferedContacts) == -1) {