Skip to content

Instantly share code, notes, and snippets.

@GVRV
Created November 10, 2013 09:34
Show Gist options
  • Save GVRV/7396016 to your computer and use it in GitHub Desktop.
Save GVRV/7396016 to your computer and use it in GitHub Desktop.
Meteor.startup(function () {
Deps.autorun(function () {
var selected = Session.get("selected");
if (selected) {
var hiive = Hiives.findOne(selected);
if (hiive) {
Meteor.subscribe("messages", hiive._id);
Meteor.subscribe("activeUsers", hiive._id);
}
}
});
});
Template.attendance.activeUsers = function () {
return activeUsers.find(); //activeUsers is undefined! Even though Session.get("selected") changed from null to something.
};
Meteor.publish('activeUsers', function(hiiveId) {
Meteor.call('canAccessHiive', hiiveId);
check(hiiveId, String);
// Setup some filter to find the users your logged in user
// cares about. It's unlikely that you want to publish the
// presences of _all_ the users in the system.
var filter = {
'state.hiive': hiiveId
};
console.log(Meteor.presences.find(filter, {fields: {state: true, userId: true}}));
// ProTip: unless you need it, don't send lastSeen down as it'll make your
// templates constantly re-render (and use bandwidth)
return Meteor.presences.find(filter, {fields: {state: true, userId: true}});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment