module.exports = {

  find: function(req, res) {
    Activity.query(function(qb) {
      qb.where('reader_id', req.session.userId);
      qb.limit(req.param('limit') || 10);
      qb.orderBy('created_at', 'desc');
    }).fetchAll({withRelated: [
      {actor: function(qb) {
        qb.column('id', 'name', 'avatar_url');
      }},
      {comment: function(qb) {
        qb.column('id', 'comment_text', 'date_commented');
      }},
      {'comment.thanks': function(qb) {
        qb.where('thanked_by_id', req.session.userId);
      }},
      {post: function(qb) {
        qb.column('id', 'name', 'creator_id', 'type', 'description');
      }},
      {'post.communities': function(qb) {
        qb.column('id', 'slug');
      }}
    ]})
    .then(function(activities) {
      res.ok(activities);
    })
    .catch(res.serverError.bind(res));
  },

  update: function(req, res) {
    if (req.param('action') == 'markAllRead') {
      Activity.query().where({reader_id: req.session.userId}).update({unread: false})
      .then(function() {
        res.ok({});
      })
      .catch(res.serverError.bind(res));
      return;
    }

    Activity.find(req.param('activityId')).then(function(activity) {
      activity.attributes = _.pick(req.allParams(), 'unread');
      return activity.save();
    })
    .then(function() {
      res.ok({});
    })
    .catch(res.serverError.bind(res));
  }

}
@@ -203,24 +203,362 @@
 ', 'desc');%0A
+%0A      qb.whereRaw('(comment.active = true or comment.id is null)')%0A      .leftJoin('comment', function() %7B%0A        this.on('comment.id', '=', 'activity.comment_id')%0A      %7D);%0A%0A      qb.whereRaw('(post.active = true or post.id is null)')%0A      .leftJoin('post', function() %7B%0A        this.on('post.id', '=', 'activity.post_id')%0A      %7D);%0A%0A
     %7D).fetch

exclude activity for inactive posts/comments