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.

This commit is contained in:
Shannon
2015-10-16 14:45:49 +02:00
parent 841c8d69fc
commit 30bc89ba93
2 changed files with 20 additions and 15 deletions

View File

@@ -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);
});

View File

@@ -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);
}
}));