notifications.js 2.6 KB

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