activities.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. // We use activities fields at two different places:
  3. // 1. The board sidebar
  4. // 2. The card activity tab
  5. // We use this publication to paginate for these two publications.
  6. Meteor.publish('activities', (kind, id, limit, showActivities) => {
  7. check(
  8. kind,
  9. Match.Where(x => {
  10. return ['board', 'card'].indexOf(x) !== -1;
  11. }),
  12. );
  13. check(id, Match.Maybe(String));
  14. check(limit, Number);
  15. check(showActivities, Boolean);
  16. // Return empty cursor if id is null or undefined
  17. if (!id) {
  18. return this.ready();
  19. }
  20. // Get linkedBoard
  21. let linkedElmtId = [id];
  22. if (kind == 'board') {
  23. ReactiveCache.getCards({
  24. "type": "cardType-linkedBoard",
  25. "boardId": id}
  26. ).forEach(card => {
  27. linkedElmtId.push(card.linkedId);
  28. });
  29. }
  30. const selector = showActivities
  31. ? { [`${kind}Id`]: { $in: linkedElmtId } }
  32. : { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: { $in: linkedElmtId } }] };
  33. const ret = ReactiveCache.getActivities(selector,
  34. {
  35. limit,
  36. sort: { createdAt: -1 },
  37. },
  38. true,
  39. );
  40. return ret;
  41. });