Skip to content

Instantly share code, notes, and snippets.

@jmoyers
Created May 8, 2011 00:18
Show Gist options
  • Save jmoyers/960987 to your computer and use it in GitHub Desktop.
Save jmoyers/960987 to your computer and use it in GitHub Desktop.
var sensitive = [
{
email: [email protected],
secret: 'somesecret',
username: name,
last_message: 'hey'
},
{
email: [email protected],
secret: 'somesecret2',
username: name1,
last_message: 'hey2'
}
];
var filtered = _.map(sensitive, function(s){
// Transform, leave out sensitive data
return {
username: s.username,
last_message: s.last_message
}
});
// Filter sockets using underscore.js collections
_(sockets).select(function(socket){
return socket.user.role == 'Member';
}).each(function(socket){
socket.send(filtered);
});
_(sockets).select(function(socket){
return socket.user.role == 'Admin';
}).each(function(socket){
socket.send(sensitive);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment