2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_profile')].helpers({
|
2013-10-09 20:50:26 +09:00
|
|
|
avatarUrl: function() {
|
|
|
|
return getAvatarUrl(this);
|
|
|
|
},
|
|
|
|
canEditProfile: function() {
|
|
|
|
var currentUser = Meteor.user();
|
|
|
|
return currentUser && (this._id == currentUser._id || isAdmin(currentUser))
|
2013-10-23 19:43:42 +09:00
|
|
|
},
|
|
|
|
createdAtFormatted: function() {
|
|
|
|
return this.createdAt;
|
|
|
|
},
|
|
|
|
canInvite: function() {
|
|
|
|
// if the user is logged in, the target user hasn't been invited yet, invites are enabled, and user is not viewing their own profile
|
|
|
|
return Meteor.user() && Meteor.user()._id != this._id && !isInvited(this) && invitesEnabled() && canInvite(Meteor.user());
|
|
|
|
},
|
2013-11-14 10:49:37 +09:00
|
|
|
inviteCount: function() {
|
|
|
|
return Meteor.user().inviteCount;
|
2013-11-07 09:57:57 +09:00
|
|
|
},
|
2013-11-08 11:42:00 +09:00
|
|
|
getTwitterName: function () {
|
2013-11-07 09:57:57 +09:00
|
|
|
return getTwitterName(this);
|
|
|
|
},
|
2013-11-08 11:42:00 +09:00
|
|
|
getGitHubName: function () {
|
2013-11-07 09:57:57 +09:00
|
|
|
return getGitHubName(this);
|
2014-08-11 10:14:53 +09:00
|
|
|
},
|
2014-08-23 11:28:05 +09:00
|
|
|
posts: function () {
|
|
|
|
return Posts.find({userId: this._id});
|
|
|
|
},
|
|
|
|
upvotedPosts: function () {
|
2014-08-11 10:14:53 +09:00
|
|
|
// extend upvotes with each upvoted post
|
2014-08-23 11:53:37 +09:00
|
|
|
if(!!this.votes.upvotedPosts){
|
|
|
|
var extendedVotes = this.votes.upvotedPosts.map(function (item) {
|
2014-08-22 17:06:22 +09:00
|
|
|
var post = Posts.findOne(item.itemId);
|
|
|
|
return _.extend(item, post);
|
|
|
|
});
|
|
|
|
return extendedVotes
|
|
|
|
}
|
|
|
|
},
|
2014-08-23 11:28:05 +09:00
|
|
|
downvotedPosts: function () {
|
|
|
|
// extend upvotes with each upvoted post
|
2014-08-23 11:53:37 +09:00
|
|
|
if(!!this.votes.downvotedPosts){
|
|
|
|
var extendedVotes = this.votes.downvotedPosts.map(function (item) {
|
2014-08-23 11:28:05 +09:00
|
|
|
var post = Posts.findOne(item.itemId);
|
|
|
|
return _.extend(item, post);
|
|
|
|
});
|
|
|
|
return extendedVotes
|
|
|
|
}
|
|
|
|
},
|
2014-08-22 17:06:22 +09:00
|
|
|
comments: function () {
|
2014-08-23 11:53:37 +09:00
|
|
|
var comments = Comments.find({userId: this._id})
|
|
|
|
if(!!comments){
|
2014-08-22 17:06:22 +09:00
|
|
|
// extend comments with each commented post
|
|
|
|
var extendedComments = comments.map(function (comment) {
|
|
|
|
var post = Posts.findOne(comment.postId);
|
|
|
|
comment.postTitle = post.title;
|
|
|
|
return comment;
|
|
|
|
});
|
|
|
|
return extendedComments
|
|
|
|
}
|
2013-10-09 20:50:26 +09:00
|
|
|
}
|
2013-10-26 10:37:32 +09:00
|
|
|
});
|
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_profile')].events({
|
2013-10-26 10:37:32 +09:00
|
|
|
'click .invite-link': function(e, instance){
|
|
|
|
Meteor.call('inviteUser', instance.data.user._id);
|
2013-11-14 10:49:37 +09:00
|
|
|
throwError('Thanks, user has been invited.')
|
2013-10-26 10:37:32 +09:00
|
|
|
}
|
2013-10-09 20:50:26 +09:00
|
|
|
});
|