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

Set contact colours on uids (#152)

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ 2017-01-03 11:22:05 +01:00 committed by Ner'zhul
parent 3a669de201
commit 8296cdca78
4 changed files with 35 additions and 4 deletions

View File

@ -92,6 +92,7 @@ class SmsController extends Controller {
$contactsSrc = $this->contactCache->getContacts(); $contactsSrc = $this->contactCache->getContacts();
$contacts = array(); $contacts = array();
$photos = $this->contactCache->getContactPhotos(); $photos = $this->contactCache->getContactPhotos();
$uids = $this->contactCache->getContactUids();
// Cache country because of loops // Cache country because of loops
$configuredCountry = $this->configMapper->getCountry(); $configuredCountry = $this->configMapper->getCountry();
@ -115,7 +116,7 @@ class SmsController extends Controller {
$photoversion = 2; $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); $phoneList = $this->smsMapper->getNewMessagesCountForAllPhonesNumbers($this->userId, $lastDate);
$contactsSrc = $this->contactCache->getContacts(); $contactsSrc = $this->contactCache->getContacts();
$photosSrc = $this->contactCache->getContactPhotos(); $photosSrc = $this->contactCache->getContactPhotos();
$uidsSrc = $this->contactCache->getContactUids();
$contacts = array(); $contacts = array();
$photos = array(); $photos = array();
$uids = array();
foreach ($phoneList as $number => $ts) { foreach ($phoneList as $number => $ts) {
$fmtPN = preg_replace("#[ ]#","", $number); $fmtPN = preg_replace("#[ ]#","", $number);
if (isset($contactsSrc[$fmtPN])) { if (isset($contactsSrc[$fmtPN])) {
$contacts[$fmtPN] = $contactsSrc[$fmtPN]; $contacts[$fmtPN] = $contactsSrc[$fmtPN];
$uids[$fmtPN] = $uidsSrc[$fmtPN];
if (isset($photosSrc[$contacts[$fmtPN]])) { if (isset($photosSrc[$contacts[$fmtPN]])) {
$photos[$contacts[$fmtPN]] = $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));
} }
/** /**

View File

@ -236,6 +236,12 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
contactObj.avatar = jsondata['photos'][peerLabel]; contactObj.avatar = jsondata['photos'][peerLabel];
} }
if (typeof jsondata['uids'][peerLabel] != 'undefined') {
contactObj.uid = jsondata['uids'][peerLabel];
} else {
contactObj.uid = peerLabel;
}
$scope.modifyContact(contactObj); $scope.modifyContact(contactObj);
bufferedContacts.push(peerLabel); bufferedContacts.push(peerLabel);
@ -403,6 +409,13 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
if (typeof(jsondata['photos'][peerLabel]) != 'undefined') { if (typeof(jsondata['photos'][peerLabel]) != 'undefined') {
contactObj['avatar'] = jsondata['photos'][peerLabel]; contactObj['avatar'] = jsondata['photos'][peerLabel];
} }
if (typeof jsondata['uids'][peerLabel] != 'undefined') {
contactObj.uid = jsondata['uids'][peerLabel];
} else {
contactObj.uid = peerLabel;
}
$scope.addContact(contactObj); $scope.addContact(contactObj);
bufferedContacts.push(peerLabel); bufferedContacts.push(peerLabel);
} }

View File

@ -23,6 +23,7 @@ class ContactCache {
private $contacts; private $contacts;
private $contactsInverted; private $contactsInverted;
private $contactPhotos; private $contactPhotos;
private $contactUids;
private $cfgMapper; private $cfgMapper;
private $contactsManager; private $contactsManager;
@ -30,6 +31,7 @@ class ContactCache {
public function __construct (ConfigMapper $cfgMapper, IContactsManager $contactsManager) { public function __construct (ConfigMapper $cfgMapper, IContactsManager $contactsManager) {
$this->contacts = array(); $this->contacts = array();
$this->contactPhotos = array(); $this->contactPhotos = array();
$this->contactUids = array();
$this->contactsInverted = array(); $this->contactsInverted = array();
$this->cfgMapper = $cfgMapper; $this->cfgMapper = $cfgMapper;
@ -60,6 +62,14 @@ class ContactCache {
return $this->contactPhotos; 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 * Partially importe this function from owncloud Chat app
* https://github.com/owncloud/chat/blob/master/app/chat.php * https://github.com/owncloud/chat/blob/master/app/chat.php
@ -99,6 +109,10 @@ class ContactCache {
$photoURL = preg_replace("#^VALUE=uri:#","",$r["PHOTO"], 1); $photoURL = preg_replace("#^VALUE=uri:#","",$r["PHOTO"], 1);
$this->contactPhotos[$r["FN"]] = $photoURL; $this->contactPhotos[$r["FN"]] = $photoURL;
} }
if (isset ($r["UID"])) {
$this->contactUids[$r["FN"]] = $r["UID"];
}
} }
} }
} }

View File

@ -13,7 +13,7 @@ use \OCA\OcSms\Lib\CountryCodes;
<ul class="contact-list" ng-show="!isContactsLoading"> <ul class="contact-list" ng-show="!isContactsLoading">
<li ng-repeat="contact in contacts | orderBy:setting_contactOrder:setting_contactOrderReverse" peer-label="{{ contact.label }}" ng-click="loadConversation(contact);" href="#"> <li ng-repeat="contact in contacts | orderBy:setting_contactOrder:setting_contactOrderReverse" peer-label="{{ contact.label }}" ng-click="loadConversation(contact);" href="#">
<img class="ocsms-plavatar" ng-src="{{ contact.avatar }}" ng-show="contact.avatar !== undefined" /> <img class="ocsms-plavatar" ng-src="{{ contact.avatar }}" ng-show="contact.avatar !== undefined" />
<div class="ocsms-plavatar" ng-show="contact.avatar === undefined" ng-style="{'background-color': (contact.label | peerColor)}">{{ contact.label | firstCharacter }}</div> <div class="ocsms-plavatar" ng-show="contact.avatar === undefined" ng-style="{'background-color': (contact.uid | peerColor)}">{{ contact.label | firstCharacter }}</div>
<a class="ocsms-plname" style="{{ contact.unread > 0 ? 'font-weight:bold;' : ''}}" mailbox-label="{{ contact.label }}" mailbox-navigation="{{ contact.nav }}">{{ contact.label }}{{ contact.unread > 0 ? ' (' + contact.unread + ') ' : '' }}</a> <a class="ocsms-plname" style="{{ contact.unread > 0 ? 'font-weight:bold;' : ''}}" mailbox-label="{{ contact.label }}" mailbox-navigation="{{ contact.nav }}">{{ contact.label }}{{ contact.unread > 0 ? ' (' + contact.unread + ') ' : '' }}</a>
</li> </li>
</ul> </ul>
@ -61,7 +61,7 @@ use \OCA\OcSms\Lib\CountryCodes;
<div id="app-content-loader" class="icon-loading" ng-show="isConvLoading"> <div id="app-content-loader" class="icon-loading" ng-show="isConvLoading">
</div> </div>
<div id="app-content-header" ng-show="!isConvLoading && selectedContact.label !== undefined && selectedContact.label !== ''" <div id="app-content-header" ng-show="!isConvLoading && selectedContact.label !== undefined && selectedContact.label !== ''"
ng-style="{'background-color': (selectedContact.label | peerColor)}"> ng-style="{'background-color': (selectedContact.uid | peerColor)}">
<div id="ocsms-contact-avatar"> <div id="ocsms-contact-avatar">
<img class="ocsms-plavatar-big" ng-src="{{ selectedContact.avatar }}" <img class="ocsms-plavatar-big" ng-src="{{ selectedContact.avatar }}"
ng-show="selectedContact.avatar !== undefined" /> ng-show="selectedContact.avatar !== undefined" />