activities.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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, String);
  14. check(limit, Number);
  15. check(showActivities, Boolean);
  16. // Get linkedBoard
  17. let linkedElmtId = [id];
  18. if (kind == 'board') {
  19. ReactiveCache.getCards({
  20. "type": "cardType-linkedBoard",
  21. "boardId": id}
  22. ).forEach(card => {
  23. linkedElmtId.push(card.linkedId);
  24. });
  25. }
  26. const selector = showActivities
  27. ? { [`${kind}Id`]: { $in: linkedElmtId } }
  28. : { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: { $in: linkedElmtId } }] };
  29. const ret = ReactiveCache.getActivities(selector,
  30. {
  31. limit,
  32. sort: { createdAt: -1 },
  33. },
  34. true,
  35. );
  36. return ret;
  37. });