summary refs log tree commit diff
path: root/webclient
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-11-03 13:48:08 +0000
committerKegan Dougal <kegan@matrix.org>2014-11-03 13:48:08 +0000
commit92e2ff49853922a5e81ac67ccf1a95f2278d5415 (patch)
treee6126f057efc19ad61ec2f3fba5d1ac4b6df05b3 /webclient
parentFix bug which prevented the number of users being visible on the recents view. (diff)
downloadsynapse-92e2ff49853922a5e81ac67ccf1a95f2278d5415.tar.xz
Fix bug which prevented room name invites appearing correctly.
Diffstat (limited to 'webclient')
-rw-r--r--webclient/components/matrix/event-handler-service.js4
-rw-r--r--webclient/components/matrix/matrix-filter.js127
-rw-r--r--webclient/recents/recents.html2
3 files changed, 47 insertions, 86 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index 953ce839ea..a872e3f435 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -408,7 +408,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
                             }
                         }
                         console.log("Unable to handle event type " + event.type);
-                        console.log(JSON.stringify(event, undefined, 4));
+                        // console.log(JSON.stringify(event, undefined, 4));
                         break;
                 }
             }
@@ -475,7 +475,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
                         room.state = [];
                     }
                     room.state.push(fakeEvent);
-                    console.log("RECV /initialSync invite >> "+JSON.stringify(fakeEvent));
+                    console.log("RECV /initialSync invite >> "+room.room_id);
                 }
                 
                 // ========================================= 
diff --git a/webclient/components/matrix/matrix-filter.js b/webclient/components/matrix/matrix-filter.js
index e4b42a2edb..4d264e93f3 100644
--- a/webclient/components/matrix/matrix-filter.js
+++ b/webclient/components/matrix/matrix-filter.js
@@ -19,6 +19,8 @@
 angular.module('matrixFilter', [])
 
 // 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', 
 function($rootScope, matrixService, eventHandlerService, modelService) {
     return function(room_id) {
@@ -29,93 +31,60 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
         var alias = matrixService.getRoomIdToAliasMapping(room_id);
         var room = modelService.getRoom(room_id).current_room_state;
         
-        if (room) {
-            // Get name from room state date
-            var room_name_event = room.state("m.room.name");
+        var room_name_event = room.state("m.room.name");
 
-            // Determine if it is a public room
-            var isPublicRoom = false;
-            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);
-            }
+        // Determine if it is a public room
+        var isPublicRoom = false;
+        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);
+        }
 
-            if (room_name_event) {
-                roomName = room_name_event.content.name;
-            }
-            else if (alias) {
-                roomName = alias;
-            }
-            else if (room.members.length > 0 && !isPublicRoom) {    // Do not rename public room
+        if (room_name_event) {
+            roomName = room_name_event.content.name;
+        }
+        else if (alias) {
+            roomName = alias;
+        }
+        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;
-                // Else, build the name from its users
-                // Limit the room renaming to 1:1 room
-                if (2 === Object.keys(room.members).length) {
-                    for (var i in room.members) {
-                        if (!room.members.hasOwnProperty(i)) continue;
-
-                        var member = room.members[i];
-                        if (member.state_key !== user_id) {
-                            roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
-                            break;
-                        }
+            // this is a "one to one" room and should have the name of the other user.
+            if (Object.keys(room.members).length === 2) {
+                for (var i in room.members) {
+                    if (!room.members.hasOwnProperty(i)) continue;
+
+                    var member = room.members[i];
+                    if (member.state_key !== user_id) {
+                        roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
+                        break;
                     }
                 }
-                else if (Object.keys(room.members).length <= 1) {
-                    
-                    var otherUserId;
-
-                    if (Object.keys(room.members)[0]) {
-                        otherUserId = Object.keys(room.members)[0];
-                        // this could be an invite event (from event stream)
-                        if (otherUserId === user_id && 
-                                room.members[user_id].content.membership === "invite") {
-                            // this is us being invited to this room, so the
-                            // *user_id* is the other user ID and not the state
-                            // key.
-                            otherUserId = room.members[user_id].user_id;
-                        }
+            }
+            else if (Object.keys(room.members).length === 1) {
+                // 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.
+                var otherUserId = Object.keys(room.members)[0];
+                if (otherUserId === user_id) {
+                    // it's us, we may have been invited to this room or it could
+                    // be a self chat.
+                    if (room.members[otherUserId].content.membership === "invite") {
+                        // someone invited us, use the right ID.
+                        roomName = eventHandlerService.getUserDisplayName(room_id, room.members[otherUserId].user_id);
                     }
                     else {
-                        // it's got to be an invite, or failing that a self-chat;
-                        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];
-                        }
-*/                        
+                        roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId);
                     }
-                    
-                    // Get the user display name
+                }
+                else { // it isn't us, so use their name if we know it.
                     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
         if (roomName && alias && alias !== roomName) {
@@ -125,14 +94,6 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
         if (undefined === roomName) {
             // By default, use the 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;
diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html
index a11e6be532..7297e23703 100644
--- a/webclient/recents/recents.html
+++ b/webclient/recents/recents.html
@@ -27,7 +27,7 @@
             <tr>
                 <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
                     </div>