summaryrefslogtreecommitdiffstats
path: root/server/publications/notifications.js
blob: bc55a37c704e48f4f62917f6cb2f8e84ebc33533 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// We use these when displaying notifications in the notificationsDrawer

// gets all activities associated with the current user
Meteor.publish('notificationActivities', () => {
  return activities();
});

// gets all attachments associated with activities associated with the current user
Meteor.publish('notificationAttachments', function() {
  return Attachments.find({
    _id: {
      $in: activities()
        .map(v => v.attachmentId)
        .filter(v => !!v),
    },
  });
});

// gets all cards associated with activities associated with the current user
Meteor.publish('notificationCards', function() {
  return Cards.find({
    _id: {
      $in: activities()
        .map(v => v.cardId)
        .filter(v => !!v),
    },
  });
});

// gets all checklistItems associated with activities associated with the current user
Meteor.publish('notificationChecklistItems', function() {
  return ChecklistItems.find({
    _id: {
      $in: activities()
        .map(v => v.checklistItemId)
        .filter(v => !!v),
    },
  });
});

// gets all checklists associated with activities associated with the current user
Meteor.publish('notificationChecklists', function() {
  return Checklists.find({
    _id: {
      $in: activities()
        .map(v => v.checklistId)
        .filter(v => !!v),
    },
  });
});

// gets all comments associated with activities associated with the current user
Meteor.publish('notificationComments', function() {
  return CardComments.find({
    _id: {
      $in: activities()
        .map(v => v.commentId)
        .filter(v => !!v),
    },
  });
});

// gets all lists associated with activities associated with the current user
Meteor.publish('notificationLists', function() {
  return Lists.find({
    _id: {
      $in: activities()
        .map(v => v.listId)
        .filter(v => !!v),
    },
  });
});

// gets all swimlanes associated with activities associated with the current user
Meteor.publish('notificationSwimlanes', function() {
  return Swimlanes.find({
    _id: {
      $in: activities()
        .map(v => v.swimlaneId)
        .filter(v => !!v),
    },
  });
});

// gets all users associated with activities associated with the current user
Meteor.publish('notificationUsers', function() {
  return Users.find({
    _id: {
      $in: activities()
        .map(v => v.userId)
        .filter(v => !!v),
    },
  });
});

function activities() {
  const notifications = Meteor.user().profile.notifications || [];
  return Activities.find({
    _id: { $in: notifications.map(v => v.activity) },
  });
}