summaryrefslogtreecommitdiffstats
path: root/collections/activities.js
blob: 1e24cf7ce1a1b9fd6407e51050afe6be62e097ca (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
// Activities don't need a schema because they are always set from the a trusted
// environment - the server - and there is no risk that a user change the logic
// we use with this collection. Moreover using a schema for this collection
// would be difficult (different activities have different fields) and wouldn't
// bring any direct advantage.
//
// XXX The activities API is not so nice and need some functionalities. For
// instance if a user archive a card, and un-archive it a few seconds later we
// should remove both activities assuming it was an error the user decided to
// revert.
Activities = new Mongo.Collection('activities');

Activities.helpers({
  board: function() {
    return Boards.findOne(this.boardId);
  },
  user: function() {
    return Users.findOne(this.userId);
  },
  member: function() {
    return Users.findOne(this.memberId);
  },
  list: function() {
    return Lists.findOne(this.listId);
  },
  oldList: function() {
    return Lists.findOne(this.oldListId);
  },
  card: function() {
    return Cards.findOne(this.cardId);
  },
  comment: function() {
    return CardComments.findOne(this.commentId);
  },
  attachment: function() {
    return Attachments.findOne(this.attachmentId);
  }
});

Activities.before.insert(function(userId, doc) {
  doc.createdAt = new Date();
});

// For efficiency create an index on the date of creation.
if (Meteor.isServer) {
  Meteor.startup(function() {
    Activities._collection._ensureIndex({
      createdAt: -1
    });
  });
}