mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00

This commit touch a lot of lines of code with the goal to be more rigorous about JavaScript code conventions defined in the `.jshintrc`. Some modification: * Add a list of used global symbols in the corresponding section of `.jshintrc` * Use local variables instead of global in a lot of places where the keyword `var` was mistakenly forgotten * Add missing semi-colons after instructions * Add new lines at the end of files * Remove trailing whitespaces * Use newer name of some Meteor APIs, eg `addFiles` instead of `add_files` * Add missing `break` statements in `switch` blocks * Use `===` instead of `==` and `!==` instead of `!=` * Remove unused variables This commit should also fix a few bugs due to this lack of rigor. One example of that was the test `typeof navElements === "array"` that was never true because in JavaScript, `typeof [] === "object"`, we replaced this test by the `_.isArray` method provided by underscore. It might also fix some potential collision related to global variables. There is still plenty of work until Telescope code base passes jsHint validation, but at least this commit is a step in the right direction.
113 lines
2.9 KiB
JavaScript
113 lines
2.9 KiB
JavaScript
////////////////////////////////////
|
|
// Publications and Subscriptions //
|
|
////////////////////////////////////
|
|
|
|
/**
|
|
* Users pub/sub configs and methods
|
|
* @namespace Users.pubsub
|
|
*/
|
|
Users.pubsub = {};
|
|
|
|
/**
|
|
* Default user object fields in publication
|
|
* @type {Object}
|
|
*/
|
|
Users.pubsub.publicProperties = { // true means exposed
|
|
_id: true,
|
|
createdAt: true,
|
|
username: true,
|
|
'services.twitter.profile_image_url': true,
|
|
'services.twitter.profile_image_url_https': true,
|
|
'services.facebook.id': true,
|
|
'services.twitter.screenName': true,
|
|
'services.github.screenName': true, // Github is not really used, but there are some mentions to it in the code
|
|
'telescope.commentCount': true,
|
|
'telescope.email_hash': true,
|
|
'telescope.isInvited': true,
|
|
'telescope.karma': true,
|
|
'telescope.postCount': true,
|
|
'telescope.slug': true,
|
|
'telescope.username': true,
|
|
'telescope.notifications': true,
|
|
'telescope.bio': true,
|
|
'telescope.github': true,
|
|
'telescope.site': true,
|
|
'telescope.twitter': true,
|
|
'telescope.downvotedComments': true,
|
|
'telescope.downvotedPosts': true,
|
|
'telescope.upvotedComments': true,
|
|
'telescope.upvotedPosts': true
|
|
};
|
|
|
|
/**
|
|
* Options for your own user account (for security reasons, block certain properties)
|
|
* @type {Object}
|
|
*/
|
|
Users.pubsub.hiddenProperties = {
|
|
'services.password.bcrypt': false
|
|
};
|
|
|
|
/**
|
|
* Minimum required properties to display avatars
|
|
* @type {Object}
|
|
*/
|
|
Users.pubsub.avatarProperties = {
|
|
_id: true,
|
|
'telescope.email_hash': true,
|
|
'telescope.slug': true,
|
|
username: true,
|
|
'profile.username': true,
|
|
'profile.github': true,
|
|
'profile.twitter': true,
|
|
'services.twitter.profile_image_url': true,
|
|
'services.twitter.profile_image_url_https': true,
|
|
'services.facebook.id': true,
|
|
'services.twitter.screenName': true,
|
|
'services.github.screenName': true, // Github is not really used, but there are some mentions to it in the code
|
|
};
|
|
|
|
|
|
/**
|
|
* Build Users subscription with filter, sort, and limit args.
|
|
* @param {String} filterBy
|
|
* @param {String} sortBy
|
|
* @param {Number} limit
|
|
*/
|
|
Users.pubsub.getSubParams = function(filterBy, sortBy, limit) {
|
|
var find = {},
|
|
sort = {createdAt: -1};
|
|
|
|
switch(filterBy){
|
|
case 'invited':
|
|
// consider admins as invited
|
|
find = { $or: [{ isInvited: true }, { isAdmin: true }]};
|
|
break;
|
|
case 'uninvited':
|
|
find = { $and: [{ isInvited: false }, { isAdmin: false }]};
|
|
break;
|
|
case 'admin':
|
|
find = { isAdmin: true };
|
|
break;
|
|
}
|
|
|
|
switch(sortBy){
|
|
case 'username':
|
|
sort = { username: 1 };
|
|
break;
|
|
case 'karma':
|
|
sort = { karma: -1 };
|
|
break;
|
|
case 'postCount':
|
|
sort = { postCount: -1 };
|
|
break;
|
|
case 'commentCount':
|
|
sort = { commentCount: -1 };
|
|
break;
|
|
case 'invitedCount':
|
|
sort = { invitedCount: -1 };
|
|
}
|
|
return {
|
|
find: find,
|
|
options: { sort: sort, limit: limit }
|
|
};
|
|
};
|