From 8296cdca78e9ecba1e9e609a6496a84f709bc91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Tue, 3 Jan 2017 11:22:05 +0100 Subject: [PATCH] Set contact colours on uids (#152) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- controller/smscontroller.php | 8 ++++++-- js/public/app.js | 13 +++++++++++++ lib/contactcache.php | 14 ++++++++++++++ templates/main.php | 4 ++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/controller/smscontroller.php b/controller/smscontroller.php index 889b285..4eecc46 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -92,6 +92,7 @@ class SmsController extends Controller { $contactsSrc = $this->contactCache->getContacts(); $contacts = array(); $photos = $this->contactCache->getContactPhotos(); + $uids = $this->contactCache->getContactUids(); // Cache country because of loops $configuredCountry = $this->configMapper->getCountry(); @@ -115,7 +116,7 @@ class SmsController extends Controller { $photoversion = 2; } - return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "lastRead" => $lastRead, "photos" => $photos, "photo_version" => $photoversion)); + return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "lastRead" => $lastRead, "photos" => $photos, "uids" => $uids, "photo_version" => $photoversion)); } /** @@ -216,13 +217,16 @@ class SmsController extends Controller { $phoneList = $this->smsMapper->getNewMessagesCountForAllPhonesNumbers($this->userId, $lastDate); $contactsSrc = $this->contactCache->getContacts(); $photosSrc = $this->contactCache->getContactPhotos(); + $uidsSrc = $this->contactCache->getContactUids(); $contacts = array(); $photos = array(); + $uids = array(); foreach ($phoneList as $number => $ts) { $fmtPN = preg_replace("#[ ]#","", $number); if (isset($contactsSrc[$fmtPN])) { $contacts[$fmtPN] = $contactsSrc[$fmtPN]; + $uids[$fmtPN] = $uidsSrc[$fmtPN]; if (isset($photosSrc[$contacts[$fmtPN]])) { $photos[$contacts[$fmtPN]] = $photosSrc[$contacts[$fmtPN]]; @@ -230,7 +234,7 @@ class SmsController extends Controller { } } - return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "photos" => $photos)); + return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "photos" => $photos, "uids" => $uids)); } /** diff --git a/js/public/app.js b/js/public/app.js index 8afe3c1..4704df8 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -236,6 +236,12 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' contactObj.avatar = jsondata['photos'][peerLabel]; } + if (typeof jsondata['uids'][peerLabel] != 'undefined') { + contactObj.uid = jsondata['uids'][peerLabel]; + } else { + contactObj.uid = peerLabel; + } + $scope.modifyContact(contactObj); bufferedContacts.push(peerLabel); @@ -403,6 +409,13 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' if (typeof(jsondata['photos'][peerLabel]) != 'undefined') { contactObj['avatar'] = jsondata['photos'][peerLabel]; } + + if (typeof jsondata['uids'][peerLabel] != 'undefined') { + contactObj.uid = jsondata['uids'][peerLabel]; + } else { + contactObj.uid = peerLabel; + } + $scope.addContact(contactObj); bufferedContacts.push(peerLabel); } diff --git a/lib/contactcache.php b/lib/contactcache.php index da925e5..a52e7c2 100644 --- a/lib/contactcache.php +++ b/lib/contactcache.php @@ -23,6 +23,7 @@ class ContactCache { private $contacts; private $contactsInverted; private $contactPhotos; + private $contactUids; private $cfgMapper; private $contactsManager; @@ -30,6 +31,7 @@ class ContactCache { public function __construct (ConfigMapper $cfgMapper, IContactsManager $contactsManager) { $this->contacts = array(); $this->contactPhotos = array(); + $this->contactUids = array(); $this->contactsInverted = array(); $this->cfgMapper = $cfgMapper; @@ -60,6 +62,14 @@ class ContactCache { return $this->contactPhotos; } + public function getContactUids() { + // Only load contacts if they aren't in the buffer + if(count($this->contactUids) == 0) { + $this->loadContacts(); + } + return $this->contactUids; + } + /** * Partially importe this function from owncloud Chat app * https://github.com/owncloud/chat/blob/master/app/chat.php @@ -99,6 +109,10 @@ class ContactCache { $photoURL = preg_replace("#^VALUE=uri:#","",$r["PHOTO"], 1); $this->contactPhotos[$r["FN"]] = $photoURL; } + + if (isset ($r["UID"])) { + $this->contactUids[$r["FN"]] = $r["UID"]; + } } } } diff --git a/templates/main.php b/templates/main.php index d6aed8b..1610425 100644 --- a/templates/main.php +++ b/templates/main.php @@ -13,7 +13,7 @@ use \OCA\OcSms\Lib\CountryCodes; @@ -61,7 +61,7 @@ use \OCA\OcSms\Lib\CountryCodes;
+ ng-style="{'background-color': (selectedContact.uid | peerColor)}">