add userId to terms when passed from publication or template controller

This commit is contained in:
Sacha Greif 2015-09-04 09:34:45 +09:00
parent 993a5f65a8
commit 9a927d428a
4 changed files with 21 additions and 0 deletions

View file

@ -41,6 +41,9 @@ Template.posts_list_controller.onCreated(function () {
// get terms from data context
var terms = Template.currentData().terms; // ⚡ reactive ⚡
// add current userId to terms
terms.userId = Meteor.userId();
// get limit from local template variable
var postsLimit = instance.postsLimit.get(); // ⚡ reactive ⚡

View file

@ -3,6 +3,9 @@ Posts._ensureIndex({"status": 1, "postedAt": 1});
// Publish a list of posts
Meteor.publish('postsList', function(terms) {
terms.userId = this.userId; // add userId to terms
if(Users.can.viewById(this.userId)){
var parameters = Posts.parameters.get(terms),
posts = Posts.find(parameters.find, parameters.options);
@ -16,6 +19,9 @@ Meteor.publish('postsList', function(terms) {
// plus the commenters for each post
Meteor.publish('postsListUsers', function(terms) {
terms.userId = this.userId; // add userId to terms
if(Users.can.viewById(this.userId)){
var parameters = Posts.parameters.get(terms),
posts = Posts.find(parameters.find, parameters.options),

View file

@ -1,4 +1,7 @@
Meteor.publish('userSubscribedPosts', function(terms) {
terms.userId = this.userId; // add userId to terms
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);
return posts;

View file

@ -11,18 +11,27 @@ Meteor.publish('singleUser', function(idOrSlug) {
});
Meteor.publish('userPosts', function(terms) {
terms.userId = this.userId; // add userId to terms
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);
return posts;
});
Meteor.publish('userUpvotedPosts', function(terms) {
terms.userId = this.userId; // add userId to terms
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);
return posts;
});
Meteor.publish('userDownvotedPosts', function(terms) {
terms.userId = this.userId; // add userId to terms
var parameters = Posts.parameters.get(terms);
var posts = Posts.find(parameters.find, parameters.options);
return posts;