Comments.getSubParams -> Comments.parameters.get; add commentsParameters callback array

This commit is contained in:
Sacha Greif 2015-09-03 14:30:35 +09:00
parent ffada3baa0
commit 993a5f65a8
4 changed files with 26 additions and 16 deletions

View file

@ -71,7 +71,7 @@ Template.commentsListController.helpers({
var commentsReady = instance.subscriptionsReady(); // ⚡ reactive ⚡
var commentsLimit = terms.limit;
var parameters = Comments.getSubParams(terms);
var parameters = Comments.parameters.get(terms);
var commentsCursor = Comments.find(parameters.find, parameters.options);
var data = {

View file

@ -1,15 +1,15 @@
Comments.parameters = {};
/**
* Gives an object containing the appropriate find
* and options arguments for the subscriptions's Comments.find()
* @param {Object} terms
*/
Comments.getSubParams = function (terms) {
Comments.parameters.get = function (terms) {
// add this to ensure all post publications pass audit-arguments-check
check(terms, Match.Any);
var maxLimit = 200;
// console.log(terms)
// note: using jquery's extend() with "deep" parameter set to true instead of shallow _.extend()
@ -22,16 +22,26 @@ Comments.getSubParams = function (terms) {
if (typeof Comments.views[terms.view] !== 'undefined')
parameters = Telescope.utils.deepExtend(true, parameters, Comments.views[terms.view](terms));
// if a limit was provided with the terms, add it too (note: limit=0 means "no limit")
if (typeof terms.limit !== 'undefined')
_.extend(parameters.options, {limit: parseInt(terms.limit)});
// limit to "maxLimit" posts at most when limit is undefined, equal to 0, or superior to maxLimit
if(!parameters.options.limit || parameters.options.limit == 0 || parameters.options.limit > maxLimit) {
parameters.options.limit = maxLimit;
}
// iterate over commentsParameters callbacks
parameters = Telescope.callbacks.run("commentsParameters", parameters, terms);
// console.log(parameters);
return parameters;
};
};
// limit the number of items that can be requested at once
function limitComments (parameters, terms) {
var maxLimit = 1000;
// if a limit was provided with the terms, add it too (note: limit=0 means "no limit")
if (typeof terms.limit !== 'undefined') {
_.extend(parameters.options, {limit: parseInt(terms.limit)});
}
// limit to "maxLimit" items at most when limit is undefined, equal to 0, or superior to maxLimit
if(!parameters.options.limit || parameters.options.limit === 0 || parameters.options.limit > maxLimit) {
parameters.options.limit = maxLimit;
}
return parameters;
}
Telescope.callbacks.add("commentsParameters", limitComments);

View file

@ -5,7 +5,7 @@ Comments._ensureIndex({parentCommentId: 1});
Meteor.publish('commentsList', function(terms) {
if(Users.can.viewById(this.userId)){
var parameters = Comments.getSubParams(terms);
var parameters = Comments.parameters.get(terms);
var comments = Comments.find(parameters.find, parameters.options);
// if there are comments, find out which posts were commented on

View file

@ -45,7 +45,7 @@ function breakTies (parameters, terms) {
}
Telescope.callbacks.add("postsParameters", breakTies);
// limit the number of posts that can be requested at once
// limit the number of items that can be requested at once
function limitPosts (parameters, terms) {
var maxLimit = 200;
// if a limit was provided with the terms, add it too (note: limit=0 means "no limit")
@ -53,7 +53,7 @@ function limitPosts (parameters, terms) {
_.extend(parameters.options, {limit: parseInt(terms.limit)});
}
// limit to "maxLimit" posts at most when limit is undefined, equal to 0, or superior to maxLimit
// limit to "maxLimit" items at most when limit is undefined, equal to 0, or superior to maxLimit
if(!parameters.options.limit || parameters.options.limit === 0 || parameters.options.limit > maxLimit) {
parameters.options.limit = maxLimit;
}