Fixed SYWEB-16: When sending an invite over federation, the remote user sees the name of the resulting invite room as *their* name rather than the inviters

pull/10/head
Emmanuel ROHEE 2014-09-19 09:07:16 +02:00
parent 2ab7e23790
commit cf1e167034
1 changed files with 39 additions and 23 deletions

View File

@ -38,13 +38,15 @@ angular.module('matrixFilter', [])
roomName = alias; roomName = alias;
} }
else if (room.members) { else if (room.members) {
var user_id = matrixService.config().user_id;
// Else, build the name from its users // Else, build the name from its users
// FIXME: Is it still required?
// Limit the room renaming to 1:1 room // Limit the room renaming to 1:1 room
if (2 === Object.keys(room.members).length) { if (2 === Object.keys(room.members).length) {
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 !== matrixService.config().user_id) { if (member.state_key !== user_id) {
if (member.state_key in $rootScope.presence) { if (member.state_key in $rootScope.presence) {
// If the user is available in presence, use the displayname there // If the user is available in presence, use the displayname there
@ -61,29 +63,43 @@ angular.module('matrixFilter', [])
} }
} }
else if (1 === Object.keys(room.members).length) { else if (1 === Object.keys(room.members).length) {
// The other member may be in the invite list, get all invited users var otherUserId;
var invitedUserIDs = [];
for (var i in room.messages) { if (Object.keys(room.members)[0] !== user_id) {
var message = room.messages[i]; otherUserId = Object.keys(room.members)[0];
if ("m.room.member" === message.type && "invite" === message.membership) { }
// Make sure there is no duplicate user else {
if (-1 === invitedUserIDs.indexOf(message.state_key)) { // The other member may be in the invite list, get all invited users
invitedUserIDs.push(message.state_key); var invitedUserIDs = [];
} for (var i in room.messages) {
} var message = room.messages[i];
if ("m.room.member" === message.type && "invite" === message.membership) {
// Filter out the current user
var member_id = message.state_key;
if (member_id === user_id) {
member_id = message.user_id;
}
if (member_id !== user_id) {
// Make sure there is no duplicate user
if (-1 === invitedUserIDs.indexOf(message.state_key)) {
invitedUserIDs.push(message.state_key);
}
}
}
}
// For now, only 1:1 room needs to be renamed. It means only 1 invited user
if (1 === invitedUserIDs.length) {
otherUserId = invitedUserIDs[0];
}
} }
// For now, only 1:1 room needs to be renamed. It means only 1 invited user // Try to resolve his displayname in presence global data
if (1 === invitedUserIDs.length) { if (otherUserId in $rootScope.presence) {
var userID = invitedUserIDs[0]; roomName = $rootScope.presence[otherUserId].content.displayname;
}
// Try to resolve his displayname in presence global data else {
if (userID in $rootScope.presence) { roomName = otherUserId;
roomName = $rootScope.presence[userID].content.displayname;
}
else {
roomName = userID;
}
} }
} }
} }