mirror of
https://github.com/element-hq/synapse
synced 2024-08-20 01:30:20 +00:00
Fix bug which prevented room name invites appearing correctly.
This commit is contained in:
parent
9b1ca64a75
commit
92e2ff4985
3 changed files with 46 additions and 85 deletions
|
@ -408,7 +408,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Unable to handle event type " + event.type);
|
console.log("Unable to handle event type " + event.type);
|
||||||
console.log(JSON.stringify(event, undefined, 4));
|
// console.log(JSON.stringify(event, undefined, 4));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -475,7 +475,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
|
||||||
room.state = [];
|
room.state = [];
|
||||||
}
|
}
|
||||||
room.state.push(fakeEvent);
|
room.state.push(fakeEvent);
|
||||||
console.log("RECV /initialSync invite >> "+JSON.stringify(fakeEvent));
|
console.log("RECV /initialSync invite >> "+room.room_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================================
|
// =========================================
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
angular.module('matrixFilter', [])
|
angular.module('matrixFilter', [])
|
||||||
|
|
||||||
// Compute the room name according to information we have
|
// Compute the room name according to information we have
|
||||||
|
// TODO: It would be nice if this was stateless and had no dependencies. That would
|
||||||
|
// make the business logic here a lot easier to see.
|
||||||
.filter('mRoomName', ['$rootScope', 'matrixService', 'eventHandlerService', 'modelService',
|
.filter('mRoomName', ['$rootScope', 'matrixService', 'eventHandlerService', 'modelService',
|
||||||
function($rootScope, matrixService, eventHandlerService, modelService) {
|
function($rootScope, matrixService, eventHandlerService, modelService) {
|
||||||
return function(room_id) {
|
return function(room_id) {
|
||||||
|
@ -29,93 +31,60 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
|
||||||
var alias = matrixService.getRoomIdToAliasMapping(room_id);
|
var alias = matrixService.getRoomIdToAliasMapping(room_id);
|
||||||
var room = modelService.getRoom(room_id).current_room_state;
|
var room = modelService.getRoom(room_id).current_room_state;
|
||||||
|
|
||||||
if (room) {
|
var room_name_event = room.state("m.room.name");
|
||||||
// Get name from room state date
|
|
||||||
var room_name_event = room.state("m.room.name");
|
|
||||||
|
|
||||||
// Determine if it is a public room
|
// Determine if it is a public room
|
||||||
var isPublicRoom = false;
|
var isPublicRoom = false;
|
||||||
if (room.state("m.room.join_rules") && room.state("m.room.join_rules").content) {
|
if (room.state("m.room.join_rules") && room.state("m.room.join_rules").content) {
|
||||||
isPublicRoom = ("public" === room.state("m.room.join_rules").content.join_rule);
|
isPublicRoom = ("public" === room.state("m.room.join_rules").content.join_rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (room_name_event) {
|
if (room_name_event) {
|
||||||
roomName = room_name_event.content.name;
|
roomName = room_name_event.content.name;
|
||||||
}
|
}
|
||||||
else if (alias) {
|
else if (alias) {
|
||||||
roomName = alias;
|
roomName = alias;
|
||||||
}
|
}
|
||||||
else if (room.members.length > 0 && !isPublicRoom) { // Do not rename public room
|
else if (Object.keys(room.members).length > 0 && !isPublicRoom) { // Do not rename public room
|
||||||
|
var user_id = matrixService.config().user_id;
|
||||||
|
|
||||||
var user_id = matrixService.config().user_id;
|
// this is a "one to one" room and should have the name of the other user.
|
||||||
// Else, build the name from its users
|
if (Object.keys(room.members).length === 2) {
|
||||||
// Limit the room renaming to 1:1 room
|
for (var i in room.members) {
|
||||||
if (2 === Object.keys(room.members).length) {
|
if (!room.members.hasOwnProperty(i)) continue;
|
||||||
for (var i in room.members) {
|
|
||||||
if (!room.members.hasOwnProperty(i)) continue;
|
|
||||||
|
|
||||||
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);
|
roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Object.keys(room.members).length <= 1) {
|
}
|
||||||
|
else if (Object.keys(room.members).length === 1) {
|
||||||
var otherUserId;
|
// this could be just us (self-chat) or could be the other person
|
||||||
|
// in a room if they have invited us to the room. Find out which.
|
||||||
if (Object.keys(room.members)[0]) {
|
var otherUserId = Object.keys(room.members)[0];
|
||||||
otherUserId = Object.keys(room.members)[0];
|
if (otherUserId === user_id) {
|
||||||
// this could be an invite event (from event stream)
|
// it's us, we may have been invited to this room or it could
|
||||||
if (otherUserId === user_id &&
|
// be a self chat.
|
||||||
room.members[user_id].content.membership === "invite") {
|
if (room.members[otherUserId].content.membership === "invite") {
|
||||||
// this is us being invited to this room, so the
|
// someone invited us, use the right ID.
|
||||||
// *user_id* is the other user ID and not the state
|
roomName = eventHandlerService.getUserDisplayName(room_id, room.members[otherUserId].user_id);
|
||||||
// key.
|
|
||||||
otherUserId = room.members[user_id].user_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// it's got to be an invite, or failing that a self-chat;
|
roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId);
|
||||||
otherUserId = room.inviter || user_id;
|
|
||||||
/*
|
|
||||||
// XXX: This should all be unnecessary now thanks to using the /rooms/<room>/roomid API
|
|
||||||
|
|
||||||
// The other member may be in the invite list, get all invited users
|
|
||||||
var invitedUserIDs = [];
|
|
||||||
|
|
||||||
// XXX: *SURELY* we shouldn't have to trawl through the whole messages list to
|
|
||||||
// find invite - surely the other user should be in room.members with state invited? :/ --Matthew
|
|
||||||
for (var i in room.messages) {
|
|
||||||
var message = room.messages[i];
|
|
||||||
if ("m.room.member" === message.type && "invite" === message.content.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(member_id)) {
|
|
||||||
invitedUserIDs.push(member_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// For now, only 1:1 room needs to be renamed. It means only 1 invited user
|
|
||||||
if (1 === invitedUserIDs.length) {
|
|
||||||
otherUserId = invitedUserIDs[0];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Get the user display name
|
else { // it isn't us, so use their name if we know it.
|
||||||
roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId);
|
roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (Object.keys(room.members).length === 0) {
|
||||||
|
// this shouldn't be possible
|
||||||
|
console.error("0 members in room >> " + room_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Always show the alias in the room displayed name
|
// Always show the alias in the room displayed name
|
||||||
if (roomName && alias && alias !== roomName) {
|
if (roomName && alias && alias !== roomName) {
|
||||||
|
@ -125,14 +94,6 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
|
||||||
if (undefined === roomName) {
|
if (undefined === roomName) {
|
||||||
// By default, use the room ID
|
// By default, use the room ID
|
||||||
roomName = room_id;
|
roomName = room_id;
|
||||||
|
|
||||||
// XXX: this is *INCREDIBLY* heavy logging for a function that calls every single
|
|
||||||
// time any kind of digest runs which refreshes a room name...
|
|
||||||
// commenting it out for now.
|
|
||||||
|
|
||||||
// Log some information that lead to this leak
|
|
||||||
// console.log("Room ID leak for " + room_id);
|
|
||||||
// console.log("room object: " + JSON.stringify(room, undefined, 4));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return roomName;
|
return roomName;
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3" class="recentsRoomSummary">
|
<td colspan="3" class="recentsRoomSummary">
|
||||||
|
|
||||||
<div ng-show="room.recent.me.membership === 'invite'">
|
<div ng-show="room.recent.me.content.membership === 'invite'">
|
||||||
{{ room.recent.inviter | mUserDisplayName: room.room_id }} invited you
|
{{ room.recent.inviter | mUserDisplayName: room.room_id }} invited you
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue