2013-04-14 14:51:37 +09:00
|
|
|
// Session variables
|
2012-12-11 10:47:11 +09:00
|
|
|
Session.set('initialLoad', true);
|
2013-04-06 15:17:09 +09:00
|
|
|
Session.set('currentDate', new Date());
|
2013-04-06 16:36:47 +09:00
|
|
|
Session.set('categorySlug', null);
|
2013-06-18 10:46:29 +09:00
|
|
|
Session.set('singlePostReady', false);
|
2012-12-11 10:47:11 +09:00
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Settings
|
2012-10-10 07:28:44 +09:00
|
|
|
Meteor.subscribe('settings', function(){
|
2012-10-10 07:57:34 +09:00
|
|
|
// runs once on site load
|
2012-12-11 10:47:11 +09:00
|
|
|
analyticsInit();
|
2012-11-21 14:31:58 +09:00
|
|
|
Session.set('settingsLoaded',true);
|
2012-10-10 07:28:44 +09:00
|
|
|
});
|
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Categories
|
2013-02-18 13:38:15 +09:00
|
|
|
Meteor.subscribe('categories');
|
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Users
|
2012-11-17 13:24:19 +09:00
|
|
|
Meteor.subscribe('currentUser');
|
|
|
|
Meteor.subscribe('allUsers');
|
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Notifications - only load if user is logged in
|
2013-02-22 15:41:15 +09:00
|
|
|
if(Meteor.userId() != null){
|
2012-10-10 07:57:34 +09:00
|
|
|
Meteor.subscribe('notifications');
|
2012-10-10 07:28:44 +09:00
|
|
|
}
|
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Posts
|
2012-10-18 13:07:10 +11:00
|
|
|
// We have a few subscriptions here, for the various ways we load posts
|
|
|
|
//
|
|
|
|
// The advantage is that
|
|
|
|
// a) we can change pages a lot quicker
|
|
|
|
// XXX: and we can animate between them (todo)
|
|
|
|
// b) we know when an individual page is ready
|
2012-10-10 07:28:44 +09:00
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Single Post
|
2013-10-06 09:33:00 +09:00
|
|
|
// Meteor.autorun(function() {
|
|
|
|
// Meteor.subscribe('singlePost', Session.get('selectedPostId'), function(){
|
|
|
|
// Session.set('singlePostReady', true);
|
|
|
|
// });
|
|
|
|
// });
|
2013-02-18 13:38:15 +09:00
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Digest
|
2013-10-06 09:33:00 +09:00
|
|
|
// Meteor.autorun(function() {
|
|
|
|
// digestHandle = Meteor.subscribe('postDigest', Session.get('currentDate'));
|
|
|
|
// });
|
2013-04-05 16:06:50 +09:00
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Posts Lists
|
2012-10-24 11:04:42 +09:00
|
|
|
STATUS_PENDING=1;
|
|
|
|
STATUS_APPROVED=2;
|
|
|
|
STATUS_REJECTED=3;
|
2012-11-25 19:10:10 +11:00
|
|
|
|
2013-04-06 15:42:33 +09:00
|
|
|
// put it all together with pagination
|
2013-04-06 15:17:09 +09:00
|
|
|
postListSubscription = function(find, options, per_page) {
|
2013-03-23 16:58:28 +11:00
|
|
|
var handle = Meteor.subscribeWithPagination('paginatedPosts', find, options, per_page);
|
2012-12-13 17:06:13 +11:00
|
|
|
handle.fetch = function() {
|
2013-04-14 13:00:23 +10:00
|
|
|
var ourFind = _.isFunction(find) ? find() : find;
|
|
|
|
return limitDocuments(Posts.find(ourFind, options), handle.loaded());
|
2012-12-13 17:06:13 +11:00
|
|
|
}
|
|
|
|
return handle;
|
2012-10-09 12:02:37 +09:00
|
|
|
}
|
|
|
|
|
2013-04-07 17:40:32 +09:00
|
|
|
// note: the "name" property is for internal debugging purposes only
|
2013-04-06 17:32:05 +09:00
|
|
|
selectTop = function() {
|
2013-04-06 18:39:01 +11:00
|
|
|
return selectPosts({name: 'top', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
|
2012-12-13 18:12:08 +11:00
|
|
|
}
|
2013-04-14 14:51:37 +09:00
|
|
|
topPostsHandle = postListSubscription(selectTop, sortPosts('score'), 10);
|
|
|
|
|
2013-04-06 17:32:05 +09:00
|
|
|
selectNew = function() {
|
2013-04-06 18:39:01 +11:00
|
|
|
return selectPosts({name: 'new', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
|
2012-12-13 18:12:08 +11:00
|
|
|
}
|
2013-04-14 14:51:37 +09:00
|
|
|
newPostsHandle = postListSubscription(selectNew, sortPosts('submitted'), 10);
|
|
|
|
|
2013-04-06 17:32:05 +09:00
|
|
|
selectBest = function() {
|
2013-04-06 18:39:01 +11:00
|
|
|
return selectPosts({name: 'best', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
|
2013-04-06 15:42:33 +09:00
|
|
|
}
|
2013-04-14 14:51:37 +09:00
|
|
|
bestPostsHandle = postListSubscription(selectBest, sortPosts('baseScore'), 10);
|
|
|
|
|
2013-04-06 17:32:05 +09:00
|
|
|
selectPending = function() {
|
2013-04-06 18:39:01 +11:00
|
|
|
return selectPosts({name: 'pending', status: STATUS_PENDING, slug: Session.get('categorySlug')});
|
2012-12-13 18:12:08 +11:00
|
|
|
}
|
2013-04-06 18:39:01 +11:00
|
|
|
pendingPostsHandle = postListSubscription(selectPending, sortPosts('createdAt'), 10);
|
2012-10-01 12:23:35 +09:00
|
|
|
|
2013-04-14 14:51:37 +09:00
|
|
|
// Comments
|
2012-10-10 11:03:09 +09:00
|
|
|
// Collection depends on selectedPostId and selectedCommentId session variable
|
2012-10-08 16:49:01 +09:00
|
|
|
|
2013-10-09 20:11:58 +09:00
|
|
|
// Session.set('selectedPostId', null);
|
2013-06-18 10:46:29 +09:00
|
|
|
|
2013-10-09 20:11:58 +09:00
|
|
|
// Meteor.autosubscribe(function() {
|
|
|
|
// var query = { $or : [ { post : Session.get('selectedPostId') } , { _id : Session.get('selectedCommentId') } ] };
|
|
|
|
// Meteor.subscribe('comments', query, function() {
|
|
|
|
// Session.set('singleCommentReady', true);
|
|
|
|
// });
|
|
|
|
// });
|