Remove rootScope.presence and replaced with modelService.getUser/setUser.
This commit is contained in:
parent
afd2e214bc
commit
3916e23bbd
|
@ -43,15 +43,10 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||||
// of the app, given we never try to reap memory yet)
|
// of the app, given we never try to reap memory yet)
|
||||||
var eventMap = {};
|
var eventMap = {};
|
||||||
|
|
||||||
// TODO: Remove this and replace with modelService.User objects.
|
|
||||||
$rootScope.presence = {};
|
|
||||||
|
|
||||||
var initialSyncDeferred;
|
var initialSyncDeferred;
|
||||||
|
|
||||||
var reset = function() {
|
var reset = function() {
|
||||||
initialSyncDeferred = $q.defer();
|
initialSyncDeferred = $q.defer();
|
||||||
|
|
||||||
$rootScope.presence = {};
|
|
||||||
|
|
||||||
eventMap = {};
|
eventMap = {};
|
||||||
};
|
};
|
||||||
|
@ -268,7 +263,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||||
};
|
};
|
||||||
|
|
||||||
var handlePresence = function(event, isLiveEvent) {
|
var handlePresence = function(event, isLiveEvent) {
|
||||||
$rootScope.presence[event.content.user_id] = event;
|
modelService.setUser(event);
|
||||||
$rootScope.$broadcast(PRESENCE_EVENT, event, isLiveEvent);
|
$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 getUserDisplayName = function(room_id, user_id, wrap) {
|
||||||
var displayName;
|
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
|
// Get the user display name from the member list of the room
|
||||||
var member = modelService.getMember(room_id, user_id);
|
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
|
// 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
|
// Note: This data may not be available
|
||||||
if (undefined === displayName && user_id in $rootScope.presence) {
|
if (undefined === displayName) {
|
||||||
displayName = $rootScope.presence[user_id].content.displayname;
|
var usr = modelService.getUser(user_id);
|
||||||
|
if (usr) {
|
||||||
|
displayName = usr.event.content.displayname;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (undefined === 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;
|
return displayName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,10 @@ angular.module('modelService', [])
|
||||||
// roomid: <Room>
|
// roomid: <Room>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var users = {
|
||||||
|
// user_id: <User>
|
||||||
|
};
|
||||||
|
|
||||||
console.log("Models inited.");
|
console.log("Models inited.");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -194,6 +198,16 @@ angular.module('modelService', [])
|
||||||
//console.log("looking for roomId for " + alias + "; found: " + roomId);
|
//console.log("looking for roomId for " + alias + "; found: " + roomId);
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -310,8 +310,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
|
||||||
}
|
}
|
||||||
$scope.members[target_user_id] = chunk;
|
$scope.members[target_user_id] = chunk;
|
||||||
|
|
||||||
if (target_user_id in $rootScope.presence) {
|
var usr = modelService.getUser(target_user_id);
|
||||||
updatePresence($rootScope.presence[target_user_id]);
|
if (usr) {
|
||||||
|
updatePresence(usr.event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue