summary refs log tree commit diff
path: root/syweb
diff options
context:
space:
mode:
Diffstat (limited to 'syweb')
-rw-r--r--syweb/webclient/components/matrix/event-handler-service.js17
-rw-r--r--syweb/webclient/components/matrix/model-service.js14
-rw-r--r--syweb/webclient/room/room-controller.js5
3 files changed, 23 insertions, 13 deletions
diff --git a/syweb/webclient/components/matrix/event-handler-service.js b/syweb/webclient/components/matrix/event-handler-service.js
index e97350005e..d291fa4160 100644
--- a/syweb/webclient/components/matrix/event-handler-service.js
+++ b/syweb/webclient/components/matrix/event-handler-service.js
@@ -43,15 +43,10 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
     // of the app, given we never try to reap memory yet)
     var eventMap = {};
 
-    // TODO: Remove this and replace with modelService.User objects.
-    $rootScope.presence = {};
-
     var initialSyncDeferred;
 
     var reset = function() {
         initialSyncDeferred = $q.defer();
-        
-        $rootScope.presence = {};
 
         eventMap = {};
     };
@@ -268,7 +263,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
     };
     
     var handlePresence = function(event, isLiveEvent) {
-        $rootScope.presence[event.content.user_id] = event;
+        modelService.setUser(event);
         $rootScope.$broadcast(PRESENCE_EVENT, event, isLiveEvent);
     };
     
@@ -332,7 +327,6 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
      */
     var getUserDisplayName = function(room_id, user_id, wrap) {
         var displayName;
-        // XXX: this is getting called *way* too often - at least once per every room member per every digest...
 
         // Get the user display name from the member list of the room
         var member = modelService.getMember(room_id, user_id);
@@ -360,8 +354,11 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
 
         // 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) {
+            var usr = modelService.getUser(user_id);
+            if (usr) {
+                displayName = usr.event.content.displayname;
+            }
         }
 
         if (undefined === displayName) {
@@ -374,8 +371,6 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
             }
         }
         
-        //console.log("getUserDisplayName(" + room_id + ", " + user_id + ", " + wrap +") = " + displayName);
-        
         return displayName;
     };
 
diff --git a/syweb/webclient/components/matrix/model-service.js b/syweb/webclient/components/matrix/model-service.js
index 6e6f741596..da71dac436 100644
--- a/syweb/webclient/components/matrix/model-service.js
+++ b/syweb/webclient/components/matrix/model-service.js
@@ -153,6 +153,10 @@ angular.module('modelService', [])
         // roomid: <Room>
     };
     
+    var users = {
+        // user_id: <User>
+    };
+    
     console.log("Models inited.");
     
     return {
@@ -194,6 +198,16 @@ angular.module('modelService', [])
             //console.log("looking for roomId for " + alias + "; found: " + roomId);
             return roomId;
         },
+        
+        getUser: function(user_id) {
+            return users[user_id];
+        },
+        
+        setUser: function(event) {
+            var usr = new User();
+            usr.event = event;
+            users[event.content.user_id] = usr;
+        }
     
     };
 }]);
diff --git a/syweb/webclient/room/room-controller.js b/syweb/webclient/room/room-controller.js
index 9c1f67750e..67372a804f 100644
--- a/syweb/webclient/room/room-controller.js
+++ b/syweb/webclient/room/room-controller.js
@@ -310,8 +310,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
             }
             $scope.members[target_user_id] = chunk;   
 
-            if (target_user_id in $rootScope.presence) {
-                updatePresence($rootScope.presence[target_user_id]);
+            var usr = modelService.getUser(target_user_id);
+            if (usr) {
+                updatePresence(usr.event);
             }
         }
         else {