notifications.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. const ret = activities();
  6. return ret;
  7. });
  8. // gets all attachments associated with activities associated with the current user
  9. Meteor.publish('notificationAttachments', function() {
  10. const ret = ReactiveCache.getAttachments(
  11. {
  12. _id: {
  13. $in: activities()
  14. .map(v => v.attachmentId)
  15. .filter(v => !!v),
  16. },
  17. },
  18. {},
  19. true,
  20. ).cursor;
  21. return ret;
  22. });
  23. // gets all cards associated with activities associated with the current user
  24. Meteor.publish('notificationCards', function() {
  25. const ret = ReactiveCache.getCards(
  26. {
  27. _id: {
  28. $in: activities()
  29. .map(v => v.cardId)
  30. .filter(v => !!v),
  31. },
  32. },
  33. {},
  34. true,
  35. );
  36. return ret;
  37. });
  38. // gets all checklistItems associated with activities associated with the current user
  39. Meteor.publish('notificationChecklistItems', function() {
  40. const ret = ReactiveCache.getChecklistItems(
  41. {
  42. _id: {
  43. $in: activities()
  44. .map(v => v.checklistItemId)
  45. .filter(v => !!v),
  46. },
  47. },
  48. {},
  49. true,
  50. );
  51. return ret;
  52. });
  53. // gets all checklists associated with activities associated with the current user
  54. Meteor.publish('notificationChecklists', function() {
  55. const ret = ReactiveCache.getChecklists(
  56. {
  57. _id: {
  58. $in: activities()
  59. .map(v => v.checklistId)
  60. .filter(v => !!v),
  61. },
  62. },
  63. {},
  64. true,
  65. );
  66. return ret;
  67. });
  68. // gets all comments associated with activities associated with the current user
  69. Meteor.publish('notificationComments', function() {
  70. const ret = ReactiveCache.getCardComments(
  71. {
  72. _id: {
  73. $in: activities()
  74. .map(v => v.commentId)
  75. .filter(v => !!v),
  76. },
  77. },
  78. {},
  79. true,
  80. );
  81. return ret;
  82. });
  83. // gets all lists associated with activities associated with the current user
  84. Meteor.publish('notificationLists', function() {
  85. const ret = ReactiveCache.getLists(
  86. {
  87. _id: {
  88. $in: activities()
  89. .map(v => v.listId)
  90. .filter(v => !!v),
  91. },
  92. },
  93. {},
  94. true,
  95. );
  96. return ret;
  97. });
  98. // gets all swimlanes associated with activities associated with the current user
  99. Meteor.publish('notificationSwimlanes', function() {
  100. const ret = ReactiveCache.getSwimlanes(
  101. {
  102. _id: {
  103. $in: activities()
  104. .map(v => v.swimlaneId)
  105. .filter(v => !!v),
  106. },
  107. },
  108. {},
  109. true,
  110. );
  111. return ret;
  112. });
  113. // gets all users associated with activities associated with the current user
  114. Meteor.publish('notificationUsers', function() {
  115. const ret = ReactiveCache.getUsers(
  116. {
  117. _id: {
  118. $in: activities()
  119. .map(v => v.userId)
  120. .filter(v => !!v),
  121. },
  122. },
  123. {},
  124. true,
  125. );
  126. return ret;
  127. });
  128. function activities() {
  129. const activityIds = ReactiveCache.getCurrentUser()?.profile?.notifications?.map(v => v.activity) || [];
  130. let ret = [];
  131. if (activityIds.length > 0) {
  132. ret = ReactiveCache.getActivities(
  133. {
  134. _id: { $in: activityIds },
  135. },
  136. {},
  137. true,
  138. );
  139. }
  140. return ret;
  141. }