diff --git a/www/addons/messages/controllers/discussion.js b/www/addons/messages/controllers/discussion.js
index 9a5dc5ec782..3f73f258094 100644
--- a/www/addons/messages/controllers/discussion.js
+++ b/www/addons/messages/controllers/discussion.js
@@ -29,7 +29,6 @@ angular.module('mm.addons.messages')
$log = $log.getInstance('mmaMessagesDiscussionCtrl');
var userId = $stateParams.userId,
- userFullname = $stateParams.userFullname,
messagesBeingSent = 0,
polling,
fetching,
@@ -41,26 +40,27 @@ angular.module('mm.addons.messages')
$scope.messages = [];
$scope.userId = userId;
$scope.currentUserId = $mmSite.getUserId();
- $scope.profileLink = true;
- if (userFullname) {
- $scope.title = userFullname;
- } else if (userId) {
- // We don't have the fullname, try to get it.
- $mmUser.getProfile(userId).then(function(user) {
+ // Disable the profile button if we're already coming from a profile.
+ if (backView && backView.stateName === mmUserProfileState) {
+ $scope.profileLink = false;
+ }
+
+ if (userId) {
+ // Get the user profile to retrieve the user fullname and image.
+ $mmUser.getProfile(userId, undefined, true).then(function(user) {
if (!$scope.title) {
$scope.title = user.fullname;
}
+ if (typeof $scope.profileLink == 'undefined') {
+ $scope.profileLink = user.profileimageurl;
+ }
+ }).catch(function() {
+ // Couldn't retrieve the image, use a default icon.
+ $scope.profileLink = true;
});
}
- // Disable the profile button if we're coming from a profile. It is safer to prevent forbid the access
- // to the full profile (we do not know the course ID they came from) as some users cannot view the full
- // profile of other users.
- if (backView && backView.stateName === mmUserProfileState) {
- $scope.profileLink = false;
- }
-
$scope.isAppOffline = function() {
return !$mmApp.isOnline();
};
@@ -117,7 +117,7 @@ angular.module('mm.addons.messages')
// Fetch the messages for the first time.
$mmaMessages.getDiscussion(userId).then(function(messages) {
$scope.messages = $mmaMessages.sortMessages(messages);
- if (!userFullname && messages && messages.length > 0) {
+ if (!$scope.title && messages && messages.length > 0) {
// When we did not receive the fullname via argument. Also it is possible that
// we cannot resolve the name when no messages were yet exchanged.
if (messages[0].useridto != $scope.currentUserId) {
diff --git a/www/addons/messages/controllers/index.js b/www/addons/messages/controllers/index.js
index 427b7d2efe0..a2e92bc6e88 100644
--- a/www/addons/messages/controllers/index.js
+++ b/www/addons/messages/controllers/index.js
@@ -21,12 +21,25 @@ angular.module('mm.addons.messages')
* @ngdoc controller
* @name mmaMessagesIndexCtrl
*/
-.controller('mmaMessagesIndexCtrl', function($scope, $mmEvents, $ionicPlatform, $ionicTabsDelegate,
+.controller('mmaMessagesIndexCtrl', function($scope, $mmEvents, $ionicPlatform, $ionicTabsDelegate, $mmUser,
mmaMessagesDiscussionLoadedEvent, mmaMessagesDiscussionLeftEvent) {
// Listen for discussion loaded event to show user profile link in tablet view.
var obsLoaded = $mmEvents.on(mmaMessagesDiscussionLoadedEvent, function(userId) {
- $scope.profileLink = $ionicPlatform.isTablet() && $ionicTabsDelegate.selectedIndex() == 0;
- $scope.userId = userId;
+ if ($ionicPlatform.isTablet() && $ionicTabsDelegate.selectedIndex() === 0) {
+ // A discussion was loaded in tablet, get the user image and show the button to the profile.
+ $scope.userId = userId;
+ $mmUser.getProfile(userId, undefined, true).catch(function() {
+ // Couldn't retrieve the image, use a default icon.
+ return {
+ profileimageurl: true
+ };
+ }).then(function(user) {
+ // Verify that no other user was loaded while the async call was in progress.
+ if ($scope.userId == userId) {
+ $scope.profileLink = user.profileimageurl;
+ }
+ });
+ }
});
// Listen for discussion loaded event to show user profile link in tablet view.
diff --git a/www/addons/messages/main.js b/www/addons/messages/main.js
index bb476c79a6f..6f5e3eb5c9d 100644
--- a/www/addons/messages/main.js
+++ b/www/addons/messages/main.js
@@ -41,8 +41,7 @@ angular.module('mm.addons.messages', ['mm.core'])
.state('site.messages-discussion', {
url: '/messages-discussion',
params: {
- userId: null,
- userFullname: null
+ userId: null
},
views: {
'site': {
diff --git a/www/addons/messages/services/handlers.js b/www/addons/messages/services/handlers.js
index 98139ee4de4..42dcefe3cb8 100644
--- a/www/addons/messages/services/handlers.js
+++ b/www/addons/messages/services/handlers.js
@@ -226,8 +226,7 @@ angular.module('mm.addons.messages')
$event.preventDefault();
$event.stopPropagation();
$state.go('site.messages-discussion', {
- userId: user.id,
- userFullname: user.fullname
+ userId: user.id
});
};
};
diff --git a/www/addons/messages/templates/discussion.html b/www/addons/messages/templates/discussion.html
index c019ebec7fa..11c03889ff2 100644
--- a/www/addons/messages/templates/discussion.html
+++ b/www/addons/messages/templates/discussion.html
@@ -2,7 +2,10 @@
{{ title }}
-
+
+
+
+
diff --git a/www/addons/messages/templates/discussions.html b/www/addons/messages/templates/discussions.html
index 09b69e695c5..d1b42a59c06 100644
--- a/www/addons/messages/templates/discussions.html
+++ b/www/addons/messages/templates/discussions.html
@@ -3,7 +3,7 @@