From 30bc89ba933a7566d43ac13de0017bc2c2f301d1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 16 Oct 2015 14:45:49 +0200 Subject: [PATCH] U4-7092 can't show avatar because in China all users can't access to some sites. - Fixes where and how the avatar gets loaded, we first check if it exist or that we can connect to the internet and then load it, removes the avatar loading from the user service.. not sure why it was even there. --- .../src/common/services/user.service.js | 4 +-- .../src/controllers/main.controller.js | 31 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js index 7ad3f0e289..3fb291619d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js @@ -1,5 +1,5 @@ angular.module('umbraco.services') - .factory('userService', function ($rootScope, eventsService, $q, $location, $log, securityRetryQueue, authResource, dialogService, $timeout, angularHelper) { + .factory('userService', function ($rootScope, eventsService, $q, $location, $log, securityRetryQueue, authResource, dialogService, $timeout, angularHelper, $http) { var currentUser = null; var lastUserId = null; @@ -250,7 +250,7 @@ angular.module('umbraco.services') } setCurrentUser(data); - currentUser.avatar = 'https://www.gravatar.com/avatar/' + data.emailHash + '?s=40&d=404'; + deferred.resolve(currentUser); }); diff --git a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js index 08185a156a..a60816c260 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js @@ -84,20 +84,25 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ tmhDynamicLocale.set($scope.user.locale); } - if($scope.user.emailHash){ - $timeout(function () { - //yes this is wrong.. - $("#avatar-img").fadeTo(1000, 0, function () { - $timeout(function () { - //this can be null if they time out - if ($scope.user && $scope.user.emailHash) { - $scope.avatar = "https://www.gravatar.com/avatar/" + $scope.user.emailHash + ".jpg?s=64&d=mm"; - } + if ($scope.user.emailHash) { + + //let's attempt to load the avatar, it might not exist or we might not have + // internet access so we'll detect it first + $http.get("https://www.gravatar.com/avatar/" + $scope.user.emailHash + ".jpg?s=64&d=404") + .then( + function successCallback(response) { + $("#avatar-img").fadeTo(1000, 0, function () { + $scope.$apply(function () { + //this can be null if they time out + if ($scope.user && $scope.user.emailHash) { + $scope.avatar = "https://www.gravatar.com/avatar/" + $scope.user.emailHash + ".jpg?s=64&d=mm"; + } + }); + $("#avatar-img").fadeTo(1000, 1); + }); + }, function errorCallback(response) { + //cannot load it from the server so we cannot do anything }); - $("#avatar-img").fadeTo(1000, 1); - }); - - }, 3000); } }));