mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-01-11 12:29:29 -05:00
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:
parent
7b8e24a588
commit
ef5b39c410
@ -544,6 +544,34 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) {
|
|||||||
return member;
|
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) {
|
setRoomVisibility: function(room_id, visible) {
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
return;
|
return;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
angular.module('matrixFilter', [])
|
angular.module('matrixFilter', [])
|
||||||
|
|
||||||
// Compute the room name according to information we have
|
// Compute the room name according to information we have
|
||||||
.filter('mRoomName', ['$rootScope', 'matrixService', function($rootScope, matrixService) {
|
.filter('mRoomName', ['$rootScope', 'matrixService', 'eventHandlerService', function($rootScope, matrixService, eventHandlerService) {
|
||||||
return function(room_id) {
|
return function(room_id) {
|
||||||
var roomName;
|
var roomName;
|
||||||
|
|
||||||
@ -47,16 +47,8 @@ angular.module('matrixFilter', [])
|
|||||||
for (var i in room.members) {
|
for (var i in room.members) {
|
||||||
var member = room.members[i];
|
var member = room.members[i];
|
||||||
if (member.state_key !== user_id) {
|
if (member.state_key !== user_id) {
|
||||||
|
roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
|
||||||
if (member.state_key in $rootScope.presence) {
|
break;
|
||||||
// If the user is listed in presence, use the displayname there
|
|
||||||
// as it is the most uptodate
|
|
||||||
// XXX: is this true nowadays?
|
|
||||||
roomName = $rootScope.presence[member.state_key].content.displayname || member.state_key;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
roomName = member.content.displayname || member.state_key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,14 +94,8 @@ angular.module('matrixFilter', [])
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to resolve his displayname in presence global data
|
// Get the user display name
|
||||||
// XXX: should we be looking in the room state instead, given it should be accurate nowadays?
|
roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId);
|
||||||
if (otherUserId in $rootScope.presence) {
|
|
||||||
roomName = $rootScope.presence[otherUserId].content.displayname || otherUserId;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
roomName = otherUserId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,37 +122,9 @@ angular.module('matrixFilter', [])
|
|||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
// Compute the user display name in a room according to the data already downloaded
|
// Return the user display name
|
||||||
.filter('mUserDisplayName', ['$rootScope', function($rootScope) {
|
.filter('mUserDisplayName', ['eventHandlerService', function(eventHandlerService) {
|
||||||
return function(user_id, room_id) {
|
return function(user_id, room_id) {
|
||||||
var displayName;
|
return eventHandlerService.getUserDisplayName(room_id, user_id);
|
||||||
|
|
||||||
// Try to find the user name among presence data
|
|
||||||
// Warning: that means we have received before a presence event for this
|
|
||||||
// user which cannot be guaranted.
|
|
||||||
// However, if we get the info by this way, we are sure this is the latest user display name
|
|
||||||
// See FIXME comment below
|
|
||||||
if (user_id in $rootScope.presence) {
|
|
||||||
displayName = $rootScope.presence[user_id].content.displayname;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Would like to use the display name as defined in room members of the room.
|
|
||||||
// But this information is the display name of the user when he has joined the room.
|
|
||||||
// It does not take into account user display name update
|
|
||||||
if (room_id) {
|
|
||||||
var room = $rootScope.events.rooms[room_id];
|
|
||||||
if (room && (user_id in room.members)) {
|
|
||||||
var member = room.members[user_id];
|
|
||||||
if (member.content.displayname) {
|
|
||||||
displayName = member.content.displayname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (undefined === displayName) {
|
|
||||||
// By default, use the user ID
|
|
||||||
displayName = user_id;
|
|
||||||
}
|
|
||||||
return displayName;
|
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
Loading…
Reference in New Issue
Block a user