From 3d71229767363122f781769ff3e418a515bf5b49 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Tue, 8 Mar 2016 22:51:00 +0100 Subject: [PATCH] v1.6.2: Fix owncloud 9 contact app which break our frontend --- appinfo/info.xml | 3 ++- controller/smscontroller.php | 9 ++++++++- js/public/app.js | 9 ++++++++- lib/contactcache.php | 11 ++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 1670d40..9d43bb9 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,8 +5,9 @@ A app to sync SMS with your ownCloud AGPL Loic Blot - 1.6.0 + 1.6.2 7 + 9 167289 diff --git a/controller/smscontroller.php b/controller/smscontroller.php index a1ce2a3..948a355 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -98,7 +98,14 @@ class SmsController extends Controller { } } $lastRead = $this->smsMapper->getLastReadDate($this->userId); - return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "lastRead" => $lastRead, "photos" => $photos)); + $ocversion = \OCP\Util::getVersion(); + $photoURL = preg_replace("#^VALUE=uri:#","",$r["PHOTO"], 1); + $photoversion = 1; + if (version_compare($ocversion[0].".".$ocversion[1].".".$ocversion[2], "9.0.0", ">=")) { + $photoversion = 2; + } + + return new JSONResponse(array("phonelist" => $phoneList, "contacts" => $contacts, "lastRead" => $lastRead, "photos" => $photos, "photo_version" => $photoversion)); } /** diff --git a/js/public/app.js b/js/public/app.js index 688c986..58660fc 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -46,6 +46,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' $scope.contacts = []; $scope.messages = []; $scope.totalMessageCount = 0; + $scope.photoVersion = 1; // Settings $scope.sendCountry = function () { $.post(OC.generateUrl('/apps/ocsms/set/country'),{'country': $('select[name=intl_phone]').val()}); @@ -299,8 +300,14 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' $scope.fetchInitialPeerList = function (jsondata) { // Use a buffer for better jQuery performance var peerListBuf = ""; + var photoPrefix = ""; var bufferedContacts = []; + $scope.photoVersion = jsondata["photo_version"]; + if ($scope.photoVersion >= 2) { + photoPrefix = "data:image/png;base64,"; + } + $.each(jsondata['phonelist'], function(id, val) { var fn, peerLabel, idxVal; idxVal = id.replace(/\//g,' '); @@ -314,7 +321,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' peerLabel = fn; } if (!inArray(peerLabel, bufferedContacts)) { - $scope.addContact({'label': peerLabel, 'nav': idxVal2, 'avatar': jsondata['photos'][peerLabel], 'unread' : 0}); + $scope.addContact({'label': peerLabel, 'nav': idxVal2, 'avatar': photoPrefix + jsondata['photos'][peerLabel], 'unread' : 0}); bufferedContacts.push(peerLabel); } }); diff --git a/lib/contactcache.php b/lib/contactcache.php index e1eba30..409a674 100644 --- a/lib/contactcache.php +++ b/lib/contactcache.php @@ -12,6 +12,8 @@ namespace OCA\OcSms\Lib; +use \OCP\Util; + class ContactCache { /** * @var array used to cache the parsed contacts for every request @@ -89,8 +91,15 @@ class ContactCache { if (isset ($r["PHOTO"])) { // Remove useless prefix + // @TODO detect owncloud version + $ocversion = \OCP\Util::getVersion(); $photoURL = preg_replace("#^VALUE=uri:#","",$r["PHOTO"], 1); - $this->contactPhotos[$r["FN"]] = $photoURL; + if (version_compare($ocversion[0].".".$ocversion[1].".".$ocversion[2], "9.0.0", ">=")) { + $this->contactPhotos[$r["FN"]] = base64_encode($photoURL); + } + else { + $this->contactPhotos[$r["FN"]] = $photoURL; + } } } }