|
|
@@ -12,10 +12,15 @@ class Story < ActiveRecord::Base |
|
|
# after this many minutes old, a story cannot be edited
|
|
|
MAX_EDIT_MINS = 30
|
|
|
|
|
|
attr_accessor :vote, :already_posted_story, :fetched_content, :previewing
|
|
|
# days a story is considered recent
|
|
|
RECENT_DAYS = 30
|
|
|
|
|
|
attr_accessor :vote, :already_posted_story, :fetched_content, :previewing,
|
|
|
:seen_previous
|
|
|
attr_accessor :editor_user_id, :moderation_reason
|
|
|
|
|
|
attr_accessible :title, :description, :tags_a, :moderation_reason
|
|
|
attr_accessible :title, :description, :tags_a, :moderation_reason,
|
|
|
:seen_previous
|
|
|
|
|
|
before_validation :assign_short_id,
|
|
|
:on => :create
|
|
|
@@ -27,9 +32,12 @@ class Story < ActiveRecord::Base |
|
|
# URI.parse is not very lenient, so we can't use it
|
|
|
|
|
|
if self.url.match(/\Ahttps?:\/\/([^\.]+\.)+[a-z]+(\/|\z)/)
|
|
|
if self.new_record? && (s = Story.find_recent_similar_by_url(self.url))
|
|
|
errors.add(:url, "has already been submitted recently")
|
|
|
if self.new_record? && (s = Story.find_similar_by_url(self.url))
|
|
|
self.already_posted_story = s
|
|
|
if s.is_recent?
|
|
|
errors.add(:url, "has already been submitted within the past " <<
|
|
|
"#{RECENT_DAYS} days")
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
errors.add(:url, "is not valid")
|
|
|
@@ -41,7 +49,7 @@ class Story < ActiveRecord::Base |
|
|
check_tags
|
|
|
end
|
|
|
|
|
|
def self.find_recent_similar_by_url(url)
|
|
|
def self.find_similar_by_url(url)
|
|
|
urls = [ url.to_s ]
|
|
|
urls2 = [ url.to_s ]
|
|
|
|
|
|
@@ -66,14 +74,13 @@ def self.find_recent_similar_by_url(url) |
|
|
end
|
|
|
urls = urls2.clone
|
|
|
|
|
|
conds = [ "created_at >= ? AND (", (Time.now - 30.days) ]
|
|
|
conds = [ "" ]
|
|
|
urls.uniq.each_with_index do |u,x|
|
|
|
conds[0] << (x == 0 ? "" : " OR ") << "url = ?"
|
|
|
conds.push u
|
|
|
end
|
|
|
conds[0] << ")"
|
|
|
|
|
|
if s = Story.where(*conds).first
|
|
|
if s = Story.where(*conds).order("id DESC").first
|
|
|
return s
|
|
|
end
|
|
|
|
|
|
@@ -376,6 +383,10 @@ def is_gone? |
|
|
is_expired?
|
|
|
end
|
|
|
|
|
|
def is_recent?
|
|
|
self.created_at >= RECENT_DAYS.days.ago
|
|
|
end
|
|
|
|
|
|
def recalculate_hotness!
|
|
|
update_column :hotness, calculated_hotness
|
|
|
end
|
|
|
|
0 comments on commit
f1f6b3c