activities.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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, hideSystem) => {
  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(hideSystem, 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 = hideSystem
  27. // ? { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: id }] }
  28. // : { [`${kind}Id`]: id };
  29. const selector = hideSystem
  30. ? { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: { $in: linkedElmtId } }] }
  31. : { [`${kind}Id`]: { $in: linkedElmtId } };
  32. const ret = ReactiveCache.getActivities(selector,
  33. {
  34. limit,
  35. sort: { createdAt: -1 },
  36. },
  37. true,
  38. );
  39. return ret;
  40. });