summary refs log tree commit diff
path: root/webclient/components
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-19 09:07:16 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-19 09:07:16 +0200
commitcf1e167034f6899328cd2c21252d4f055f1a4c83 (patch)
tree96fa444bb3c98e8ef8713953df358f09f7c69c5c /webclient/components
parentfix SYWEB-41 (hopefully) (diff)
downloadsynapse-cf1e167034f6899328cd2c21252d4f055f1a4c83.tar.xz
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
Diffstat (limited to 'webclient/components')
-rw-r--r--webclient/components/matrix/matrix-filter.js60
1 files changed, 38 insertions, 22 deletions
diff --git a/webclient/components/matrix/matrix-filter.js b/webclient/components/matrix/matrix-filter.js
index 8b168cdedb..6233fc45f8 100644
--- a/webclient/components/matrix/matrix-filter.js
+++ b/webclient/components/matrix/matrix-filter.js
@@ -38,13 +38,15 @@ angular.module('matrixFilter', [])
                 roomName = alias;
             }
             else if (room.members) {
+
+                var user_id = matrixService.config().user_id;
+
                 // Else, build the name from its users
-                // FIXME: Is it still required?
                 // Limit the room renaming to 1:1 room
                 if (2 === Object.keys(room.members).length) {
                     for (var i in room.members) {
                         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 the user is available in presence, use the displayname there
@@ -61,30 +63,44 @@ angular.module('matrixFilter', [])
                     }
                 }
                 else if (1 === Object.keys(room.members).length) {
-                    // The other member may be in the invite list, get all invited users
-                    var invitedUserIDs = [];
-                    for (var i in room.messages) {
-                        var message = room.messages[i];
-                        if ("m.room.member" === message.type && "invite" === message.membership) {
-                            // 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) {
-                        var userID = invitedUserIDs[0];
+                    var otherUserId;
 
-                        // Try to resolve his displayname in presence global data
-                        if (userID in $rootScope.presence) {
-                            roomName = $rootScope.presence[userID].content.displayname;
+                    if (Object.keys(room.members)[0] !== user_id) {
+                        otherUserId = Object.keys(room.members)[0];
+                    }
+                    else {
+                        // The other member may be in the invite list, get all invited users
+                        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);
+                                    }
+                                }
+                            } 
                         }
-                        else {
-                            roomName = userID;
+
+                        // For now, only 1:1 room needs to be renamed. It means only 1 invited user
+                        if (1 === invitedUserIDs.length) {
+                            otherUserId = invitedUserIDs[0];
                         }
                     }
+
+                    // Try to resolve his displayname in presence global data
+                    if (otherUserId in $rootScope.presence) {
+                        roomName = $rootScope.presence[otherUserId].content.displayname;
+                    }
+                    else {
+                        roomName = otherUserId;
+                    }
                 }
             }
         }