notifications.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // We use these when displaying notifications in the notificationsDrawer
  2. // gets all activities associated with the current user
  3. Meteor.publish('notificationActivities', () => {
  4. return activities();
  5. });
  6. // gets all attachments associated with activities associated with the current user
  7. Meteor.publish('notificationAttachments', function() {
  8. return Attachments.find({
  9. _id: {
  10. $in: activities()
  11. .map(v => v.attachmentId)
  12. .filter(v => !!v),
  13. }.cursor,
  14. });
  15. });
  16. // gets all cards associated with activities associated with the current user
  17. Meteor.publish('notificationCards', function() {
  18. return Cards.find({
  19. _id: {
  20. $in: activities()
  21. .map(v => v.cardId)
  22. .filter(v => !!v),
  23. },
  24. });
  25. });
  26. // gets all checklistItems associated with activities associated with the current user
  27. Meteor.publish('notificationChecklistItems', function() {
  28. return ChecklistItems.find({
  29. _id: {
  30. $in: activities()
  31. .map(v => v.checklistItemId)
  32. .filter(v => !!v),
  33. },
  34. });
  35. });
  36. // gets all checklists associated with activities associated with the current user
  37. Meteor.publish('notificationChecklists', function() {
  38. return Checklists.find({
  39. _id: {
  40. $in: activities()
  41. .map(v => v.checklistId)
  42. .filter(v => !!v),
  43. },
  44. });
  45. });
  46. // gets all comments associated with activities associated with the current user
  47. Meteor.publish('notificationComments', function() {
  48. return CardComments.find({
  49. _id: {
  50. $in: activities()
  51. .map(v => v.commentId)
  52. .filter(v => !!v),
  53. },
  54. });
  55. });
  56. // gets all lists associated with activities associated with the current user
  57. Meteor.publish('notificationLists', function() {
  58. return Lists.find({
  59. _id: {
  60. $in: activities()
  61. .map(v => v.listId)
  62. .filter(v => !!v),
  63. },
  64. });
  65. });
  66. // gets all swimlanes associated with activities associated with the current user
  67. Meteor.publish('notificationSwimlanes', function() {
  68. return Swimlanes.find({
  69. _id: {
  70. $in: activities()
  71. .map(v => v.swimlaneId)
  72. .filter(v => !!v),
  73. },
  74. });
  75. });
  76. // gets all users associated with activities associated with the current user
  77. Meteor.publish('notificationUsers', function() {
  78. return Users.find({
  79. _id: {
  80. $in: activities()
  81. .map(v => v.userId)
  82. .filter(v => !!v),
  83. },
  84. });
  85. });
  86. function activities() {
  87. const notifications = Meteor.user().profile.notifications || [];
  88. return Activities.find({
  89. _id: { $in: notifications.map(v => v.activity) },
  90. });
  91. }