move initial upvote of submitted story to Story model
This commit is contained in:
parent
83f3604bea
commit
99c551cbfe
|
@ -17,9 +17,6 @@ class StoriesController < ApplicationController
|
|||
|
||||
if @story.valid? && !(@story.already_posted_story && !@story.seen_previous)
|
||||
if @story.save
|
||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id,
|
||||
nil, @user.id, nil)
|
||||
|
||||
Countinual.count!("#{Rails.application.shortname}.stories.submitted",
|
||||
"+1")
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@ class Comment < ActiveRecord::Base
|
|||
self.assign_initial_confidence
|
||||
self.assign_thread_id
|
||||
end
|
||||
after_create :assign_votes, :mark_submitter, :deliver_reply_notifications,
|
||||
:deliver_mention_notifications, :log_to_countinual
|
||||
after_create :record_initial_upvote, :mark_submitter,
|
||||
:deliver_reply_notifications, :deliver_mention_notifications,
|
||||
:log_to_countinual
|
||||
after_destroy :unassign_votes
|
||||
|
||||
DOWNVOTABLE_DAYS = 7
|
||||
|
@ -140,13 +141,6 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def assign_votes
|
||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, self.story_id,
|
||||
self.id, self.user.id, nil, false)
|
||||
|
||||
self.story.update_comments_count!
|
||||
end
|
||||
|
||||
# http://evanmiller.org/how-not-to-sort-by-average-rating.html
|
||||
# https://github.com/reddit/reddit/blob/master/r2/r2/lib/db/_sorts.pyx
|
||||
def calculated_confidence
|
||||
|
@ -333,6 +327,13 @@ class Comment < ActiveRecord::Base
|
|||
comment
|
||||
end
|
||||
|
||||
def record_initial_upvote
|
||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, self.story_id,
|
||||
self.id, self.user_id, nil, false)
|
||||
|
||||
self.story.update_comments_count!
|
||||
end
|
||||
|
||||
def score
|
||||
self.upvotes - self.downvotes
|
||||
end
|
||||
|
|
|
@ -22,10 +22,10 @@ class Story < ActiveRecord::Base
|
|||
:seen_previous
|
||||
attr_accessor :editor_user_id, :moderation_reason
|
||||
|
||||
before_validation :assign_short_id,
|
||||
before_validation :assign_short_id_and_upvote,
|
||||
:on => :create
|
||||
before_save :log_moderation
|
||||
after_create :mark_submitter
|
||||
after_create :mark_submitter, :record_initial_upvote
|
||||
|
||||
validate do
|
||||
if self.url.present?
|
||||
|
@ -113,8 +113,9 @@ class Story < ActiveRecord::Base
|
|||
h
|
||||
end
|
||||
|
||||
def assign_short_id
|
||||
def assign_short_id_and_upvote
|
||||
self.short_id = ShortId.new(self.class).generate
|
||||
self.upvotes = 1
|
||||
end
|
||||
|
||||
def calculated_hotness
|
||||
|
@ -304,6 +305,11 @@ class Story < ActiveRecord::Base
|
|||
update_column :hotness, calculated_hotness
|
||||
end
|
||||
|
||||
def record_initial_upvote
|
||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, self.id, nil,
|
||||
self.user_id, nil, false)
|
||||
end
|
||||
|
||||
def short_id_url
|
||||
Rails.application.routes.url_helpers.root_url + "s/#{self.short_id}"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue