notifications.js 626 B

12345678910111213141516171819202122232425262728
  1. Template.notifications.helpers({
  2. notifications: function () {
  3. return Notifications.find({
  4. userId: Meteor.userId(),
  5. read: false
  6. });
  7. },
  8. notificationCount: function () {
  9. return Notifications.find({
  10. userId: Meteor.userId(),
  11. read: false
  12. }).count();
  13. }
  14. });
  15. Template.notificationItem.helpers({
  16. notificationPostPath: function () {
  17. return Router.routes.postPage.path({ _id: this.postId });
  18. }
  19. });
  20. Template.notificationItem.events({
  21. 'click a': function () {
  22. // Here, "this" is a Notification document..
  23. Notifications.update(this._id, { $set : { read: true }});
  24. }
  25. });