activities.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // We use activities fields at two different places:
  2. // 1. The board sidebar
  3. // 2. The card activity tab
  4. // We use this publication to paginate for these two publications.
  5. Meteor.publish('activities', (kind, id, limit, hideSystem) => {
  6. check(
  7. kind,
  8. Match.Where(x => {
  9. return ['board', 'card'].indexOf(x) !== -1;
  10. }),
  11. );
  12. check(id, String);
  13. check(limit, Number);
  14. check(hideSystem, Boolean);
  15. // Get linkedBoard
  16. let linkedElmtId = [id];
  17. if (kind == 'board') {
  18. Cards.find({
  19. "type": "cardType-linkedBoard",
  20. "boardId": id}
  21. ).forEach(card => {
  22. linkedElmtId.push(card.linkedId);
  23. });
  24. }
  25. //const selector = hideSystem
  26. // ? { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: id }] }
  27. // : { [`${kind}Id`]: id };
  28. const selector = hideSystem
  29. ? { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: { $in: linkedElmtId } }] }
  30. : { [`${kind}Id`]: { $in: linkedElmtId } };
  31. return Activities.find(selector, {
  32. limit,
  33. sort: { createdAt: -1 },
  34. });
  35. });