mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
decorate upvoted and down votes posts with vote timestamp
This commit is contained in:
parent
6339657503
commit
1444039065
3 changed files with 18 additions and 5 deletions
|
@ -29,7 +29,14 @@ Template[getTemplate('userDownvotedPosts')].created = function () {
|
|||
|
||||
Template[getTemplate('userDownvotedPosts')].helpers({
|
||||
posts: function () {
|
||||
return Template.instance().posts.get();
|
||||
var user = this;
|
||||
var posts = Template.instance().posts.get().fetch();
|
||||
posts = _.map(posts, function (post) {
|
||||
var vote = _.findWhere(user.votes.downvotedPosts, {itemId: post._id});
|
||||
post.votedAt = vote.votedAt;
|
||||
return post;
|
||||
});
|
||||
return posts;
|
||||
},
|
||||
hasMorePosts: function () {
|
||||
return Template.instance().posts.get().count() >= Template.instance().terms.get().limit;
|
||||
|
|
|
@ -29,9 +29,14 @@ Template[getTemplate('userUpvotedPosts')].created = function () {
|
|||
|
||||
Template[getTemplate('userUpvotedPosts')].helpers({
|
||||
posts: function () {
|
||||
// todo: sort posts based on upvote timestamp, not on postedAt timestamp
|
||||
// todo: extend with votedAt timestamp
|
||||
return Template.instance().posts.get();
|
||||
var user = this;
|
||||
var posts = Template.instance().posts.get().fetch();
|
||||
posts = _.map(posts, function (post) {
|
||||
var vote = _.findWhere(user.votes.upvotedPosts, {itemId: post._id});
|
||||
post.votedAt = vote.votedAt;
|
||||
return post;
|
||||
});
|
||||
return posts;
|
||||
},
|
||||
hasMorePosts: function () {
|
||||
return Template.instance().posts.get().count() >= Template.instance().terms.get().limit;
|
||||
|
|
|
@ -150,8 +150,9 @@ viewParameters.userUpvotedPosts = function (terms) {
|
|||
viewParameters.userDownvotedPosts = function (terms) {
|
||||
var user = Meteor.users.findOne(terms.userId);
|
||||
var postsIds = _.pluck(user.votes.downvotedPosts, "itemId");
|
||||
// TODO: sort based on votedAt timestamp and not postedAt, if possible
|
||||
return {
|
||||
find: {_id: {$in: postsIds}, userId: {$ne: terms.userId}}, // exclude own posts
|
||||
find: {_id: {$in: postsIds}},
|
||||
options: {limit: 5, sort: {postedAt: -1}}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue