2012-10-04 11:45:12 +10:00
|
|
|
Meteor.methods({
|
|
|
|
post: function(post){
|
2012-10-04 11:53:15 +10:00
|
|
|
var user = Meteor.user();
|
2012-10-06 13:15:55 +09:00
|
|
|
|
2012-10-05 13:59:40 +09:00
|
|
|
if (!user || !canPost(user))
|
2012-10-10 08:32:49 +09:00
|
|
|
throw new Meteor.Error(123, 'You need to login or be invited to post new stories.');
|
|
|
|
|
2012-10-11 13:21:10 +09:00
|
|
|
if(!post.headline)
|
|
|
|
throw new Meteor.Error(456, 'Please fill in a headline');
|
2012-10-05 13:59:40 +09:00
|
|
|
|
2012-10-06 13:15:55 +09:00
|
|
|
if(!this.isSimulation)
|
|
|
|
limitRate(user, Posts, 30);
|
|
|
|
|
2012-10-04 11:45:12 +10:00
|
|
|
post = _.extend(post, {
|
2012-10-04 11:53:15 +10:00
|
|
|
userId: user._id,
|
2012-10-10 10:48:14 +09:00
|
|
|
author: getDisplayName(user),
|
2012-10-04 11:45:12 +10:00
|
|
|
submitted: new Date().getTime(),
|
|
|
|
votes: 0,
|
|
|
|
comments: 0,
|
|
|
|
baseScore: 0,
|
|
|
|
score: 0
|
|
|
|
});
|
|
|
|
|
2012-10-04 15:26:59 +09:00
|
|
|
var postId=Posts.insert(post);
|
|
|
|
|
|
|
|
Meteor.call('upvotePost', postId);
|
|
|
|
|
|
|
|
return postId;
|
2012-10-04 11:45:12 +10:00
|
|
|
}
|
|
|
|
});
|