2017-03-23 16:27:59 +09:00
|
|
|
import Users from 'meteor/vulcan:users';
|
2016-06-23 12:17:39 +09:00
|
|
|
import Posts from './collection.js'
|
2016-06-15 11:07:10 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary Base parameters that will be common to all other view unless specific properties are overwritten
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addDefaultView(terms => ({
|
2016-02-17 19:39:43 +09:00
|
|
|
selector: {
|
2016-07-06 16:07:36 +02:00
|
|
|
status: Posts.config.STATUS_APPROVED,
|
2016-07-14 15:54:59 +09:00
|
|
|
isFuture: {$ne: true} // match both false and undefined
|
|
|
|
}
|
2017-03-05 10:33:34 +00:00
|
|
|
}));
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary Top view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("top", terms => ({
|
|
|
|
options: {
|
|
|
|
sort: {sticky: -1, score: -1}
|
|
|
|
}
|
|
|
|
}));
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary New view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("new", terms => ({
|
|
|
|
options: {
|
|
|
|
sort: {sticky: -1, postedAt: -1}
|
|
|
|
}
|
|
|
|
}));
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary Best view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("best", terms => ({
|
|
|
|
options: {
|
|
|
|
sort: {sticky: -1, baseScore: -1}
|
|
|
|
}
|
|
|
|
}));
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary Pending view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("pending", terms => ({
|
|
|
|
selector: {
|
|
|
|
status: Posts.config.STATUS_PENDING
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
sort: {createdAt: -1}
|
|
|
|
}
|
|
|
|
}));
|
2015-09-06 11:37:48 +09:00
|
|
|
|
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary Rejected view
|
2015-09-06 11:37:48 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("rejected", terms => ({
|
|
|
|
selector: {
|
|
|
|
status: Posts.config.STATUS_REJECTED
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
sort: {createdAt: -1}
|
|
|
|
}
|
|
|
|
}));
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary Scheduled view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("scheduled", terms => ({
|
|
|
|
selector: {
|
|
|
|
status: Posts.config.STATUS_APPROVED,
|
|
|
|
isFuture: true
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
sort: {postedAt: -1}
|
|
|
|
}
|
|
|
|
}));
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary User posts view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("userPosts", terms => ({
|
|
|
|
selector: {
|
|
|
|
userId: terms.userId,
|
|
|
|
status: Posts.config.STATUS_APPROVED,
|
|
|
|
isFuture: {$ne: true}
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
limit: 5,
|
|
|
|
sort: {
|
|
|
|
postedAt: -1
|
2016-07-14 15:54:59 +09:00
|
|
|
}
|
2017-03-05 10:33:34 +00:00
|
|
|
}
|
|
|
|
}));
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary User upvoted posts view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("userUpvotedPosts", (terms, apolloClient) => {
|
2017-02-04 11:46:40 +09:00
|
|
|
var user = apolloClient ? Users.findOneInStore(apolloClient.store, terms.userId) : Users.findOne(terms.userId);
|
|
|
|
|
2017-01-18 10:18:33 +09:00
|
|
|
var postsIds = _.pluck(user.upvotedPosts, "itemId");
|
2015-04-27 10:35:06 +09:00
|
|
|
return {
|
2016-02-17 19:39:43 +09:00
|
|
|
selector: {_id: {$in: postsIds}, userId: {$ne: terms.userId}}, // exclude own posts
|
2015-04-27 10:35:06 +09:00
|
|
|
options: {limit: 5, sort: {postedAt: -1}}
|
|
|
|
};
|
2015-05-06 17:38:19 +09:00
|
|
|
});
|
2015-04-27 10:35:06 +09:00
|
|
|
|
2015-05-10 13:37:42 +09:00
|
|
|
/**
|
2016-04-09 09:41:20 +09:00
|
|
|
* @summary User downvoted posts view
|
2015-05-10 13:37:42 +09:00
|
|
|
*/
|
2017-03-05 10:33:34 +00:00
|
|
|
Posts.addView("userDownvotedPosts", (terms, apolloClient) => {
|
2017-02-04 11:46:40 +09:00
|
|
|
var user = apolloClient ? Users.findOneInStore(apolloClient.store, terms.userId) : Users.findOne(terms.userId);
|
|
|
|
|
2017-01-18 10:18:33 +09:00
|
|
|
var postsIds = _.pluck(user.downvotedPosts, "itemId");
|
2015-04-27 10:35:06 +09:00
|
|
|
// TODO: sort based on votedAt timestamp and not postedAt, if possible
|
|
|
|
return {
|
2016-02-17 19:39:43 +09:00
|
|
|
selector: {_id: {$in: postsIds}},
|
2015-04-27 10:35:06 +09:00
|
|
|
options: {limit: 5, sort: {postedAt: -1}}
|
|
|
|
};
|
2015-09-17 14:51:14 +09:00
|
|
|
});
|