summary refs log tree commit diff
path: root/webclient/components
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-24 11:04:27 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-24 11:04:27 +0200
commitef5b39c4102af782c7d154d6d53fd8619b645295 (patch)
tree978e0edf5a2da6c62759ee3da1450cffba62cce7 /webclient/components
parentclose buttons on recents (SYWEB-68) (diff)
downloadsynapse-ef5b39c4102af782c7d154d6d53fd8619b645295.tar.xz
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.
Diffstat (limited to 'webclient/components')
-rw-r--r--webclient/components/matrix/event-handler-service.js28
-rw-r--r--webclient/components/matrix/matrix-filter.js58
2 files changed, 36 insertions, 50 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index ae753b3e04..770ac938ca 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -544,6 +544,34 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) {
             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) {
             if (!visible) {
                 return;
diff --git a/webclient/components/matrix/matrix-filter.js b/webclient/components/matrix/matrix-filter.js
index 50911d2415..96642a8720 100644
--- a/webclient/components/matrix/matrix-filter.js
+++ b/webclient/components/matrix/matrix-filter.js
@@ -19,7 +19,7 @@
 angular.module('matrixFilter', [])
 
 // 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) {
         var roomName;
 
@@ -47,16 +47,8 @@ angular.module('matrixFilter', [])
                     for (var i in room.members) {
                         var member = room.members[i];
                         if (member.state_key !== user_id) {
-
-                            if (member.state_key in $rootScope.presence) {
-                                // 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;
-                            }
+                            roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
+                            break;
                         }
                     }
                 }
@@ -102,14 +94,8 @@ angular.module('matrixFilter', [])
 */                        
                     }
                     
-                    // Try to resolve his displayname in presence global data
-                    // XXX: should we be looking in the room state instead, given it should be accurate nowadays?
-                    if (otherUserId in $rootScope.presence) {
-                        roomName = $rootScope.presence[otherUserId].content.displayname || otherUserId;
-                    }
-                    else {
-                        roomName = otherUserId;
-                    }
+                    // Get the user display name
+                    roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId);
                 }
             }
         }
@@ -136,37 +122,9 @@ angular.module('matrixFilter', [])
     };
 }])
 
-// Compute the user display name in a room according to the data already downloaded
-.filter('mUserDisplayName', ['$rootScope', function($rootScope) {
+// Return the user display name
+.filter('mUserDisplayName', ['eventHandlerService', function(eventHandlerService) {
     return function(user_id, room_id) {
-        var displayName;
-    
-        // 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;
+        return eventHandlerService.getUserDisplayName(room_id, user_id);
     };
 }]);