Remove rootScope.presence and replaced with modelService.getUser/setUser.

This commit is contained in:
Kegan Dougal 2014-11-13 16:43:53 +00:00
parent afd2e214bc
commit 3916e23bbd
3 changed files with 23 additions and 13 deletions

View File

@ -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;
};

View File

@ -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;
}
};
}]);

View File

@ -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 {