State data now provides up-to-date users displaynames. So use it first.

Continue to use presence data as fallback solution which is required when users do not join the room yet.
Created eventHandlerService.getUserDisplayName() as a single point to compute display name.
This commit is contained in:
Emmanuel ROHEE 2014-09-24 11:04:27 +02:00
parent 7b8e24a588
commit ef5b39c410
2 changed files with 36 additions and 50 deletions

View file

@ -544,6 +544,34 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) {
return member;
},
/**
* Return the display name of an user acccording to data already downloaded
* @param {String} room_id the room id
* @param {String} user_id the id of the user
* @returns {String} the user displayname or user_id if not available
*/
getUserDisplayName: function(room_id, user_id) {
var displayName;
// Get the user display name from the member list of the room
var member = this.getMember(room_id, user_id);
if (member) {
displayName = member.content.displayname;
}
// The user may not have joined the room yet. So try to resolve display name from presence data
// Note: This data may not be available
if (undefined === displayName && user_id in $rootScope.presence) {
displayName = $rootScope.presence[user_id].content.displayname;
}
if (undefined === displayName) {
// By default, use the user ID
displayName = user_id;
}
return displayName;
},
setRoomVisibility: function(room_id, visible) {
if (!visible) {
return;