Skip to content

Instantly share code, notes, and snippets.

@andrewvmail
Created May 29, 2015 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvmail/c23990a7fe8bf24dd218 to your computer and use it in GitHub Desktop.
Save andrewvmail/c23990a7fe8bf24dd218 to your computer and use it in GitHub Desktop.
//Finding users based on location publications
Meteor.publish('postsList', function(terms) {
if(can.viewById(this.userId)){
var parameters = getPostsParameters(terms);
//posts = Posts.find(parameters.find, parameters.options);
//By default *the current? username, emails, and profile are published to the client.
parameters.find._id = { $ne: this.userId };
//if there is can geolocate search extend with geo
if(terms.loc) {
parameters.find = _.extend(parameters.find, {"profile.loc": { $geoWithin: { $centerSphere: [ [ Math.abs(terms.loc.lng), terms.loc.lat ] , 500 / 3963.2 ] } } } );
}
posts = Meteor.users.find(parameters.find, parameters.options);
//console.log(terms);
//console.log(posts);
//console.log(parameters);
console.log(parameters);
return posts;
}
return [];
});
subscriptions: function () {
// take the first segment of the path to get the view, unless it's '/' in which case the view default to 'top'
// note: most of the time this.params.slug will be empty
this._terms = {
view: this.view,
limit: this.params.limit || getSetting('postsPerPage', 10)
};
if(Meteor.isClient) {
this._terms.loc = Session.get("loc");
}
this.postsListSub = coreSubscriptions.subscribe('postsList', this._terms);
},
data: function () {
var parameters = getUsersParameters(this._terms);
parameters.find._id = { $ne: Meteor.userId() };
var postsCount = Meteor.users.find(parameters.find, parameters.options).count();
//console.log('parameters options ', parameters.options);
//console.log(parameters.find);
//parameters.find.createdAt = { $lte: Session.get('listPopulatedAt') };
var posts = Meteor.users.find(parameters.find, parameters.options);
//console.log(parameters.find, parameters.options);
//Incoming posts
//parameters.find.createdAt = { $gt: Session.get('listPopulatedAt') };
var postsIncoming = Meteor.users.find(parameters.find, parameters.options);
Session.set('postsLimit', this._terms.limit);
//console.log(postsCount, parameters.find);
//console.log(this._terms);
//console.log(posts);
//console.log('hasMorePosts', this._terms.limit, postsCount);
//console.log('postReady', this.postsListSub.ready());
return {
incoming: postsIncoming,
postsCursor: posts,
postsCount: postsCount,
postsReady: this.postsListSub.ready(),
hasMorePosts: this._terms.limit == postsCount,
loadMoreHandler: function () {
var count = parseInt(Session.get('postsLimit')) + parseInt(getSetting('postsPerPage', 10));
var categorySegment = Session.get('categorySlug') ? Session.get('categorySlug') + '/' : '';
// TODO: use Router.path here?
Router.go('/' + Session.get('view') + '/' + categorySegment + count);
}
};
},
getTitle: function () {
return i18n.t(this.view) + ' - ' + getSetting('title', "Language 2 Exchange");
},
getDescription: function () {
if (Router.current().route.getName() == 'posts_default') { // return site description on root path
return getSetting('description');
} else {
return i18n.t(_.findWhere(viewsMenu, {label: this.view}).description);
}
},
onAfterAction: function() {
Session.set('view', this.view);
},
onBeforeAction: function() {
if(Meteor.isClient) {
Session.set('loc', Geolocation.latLng());
}
this.next();
},
fastRender: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment