fixes #2197
This commit is contained in:
2
app/helpers/forum_topic_visits_helper.rb
Normal file
2
app/helpers/forum_topic_visits_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ForumTopicVisitsHelper
|
||||
end
|
||||
@@ -105,16 +105,8 @@ class ForumTopic < ActiveRecord::Base
|
||||
super + [:text_index]
|
||||
end
|
||||
|
||||
def read_by?(user, read_forum_topic_ids)
|
||||
if read_forum_topic_ids.any? {|topic_id, timestamp| id.to_s == topic_id && updated_at.to_i > timestamp.to_i}
|
||||
return false
|
||||
end
|
||||
if read_forum_topic_ids.any? {|topic_id, timestamp| id.to_s == topic_id && updated_at.to_i <= timestamp.to_i}
|
||||
return true
|
||||
end
|
||||
return false if user.last_forum_read_at.nil?
|
||||
return true if updated_at < user.last_forum_read_at
|
||||
return false
|
||||
def check!(user)
|
||||
ForumTopicVisit.check!(user, self)
|
||||
end
|
||||
|
||||
def mark_as_read(read_forum_topic_ids)
|
||||
|
||||
30
app/models/forum_topic_visit.rb
Normal file
30
app/models/forum_topic_visit.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class ForumTopicVisit < ActiveRecord::Base
|
||||
def self.check!(user, topic)
|
||||
match = where(:user_id => user.id, :forum_topic_id => topic.id).first
|
||||
result = false
|
||||
if match
|
||||
if match.last_read_at < topic.updated_at
|
||||
result = true
|
||||
end
|
||||
match.update_attribute(:last_read_at, topic.updated_at)
|
||||
else
|
||||
create(:user_id => user.id, :forum_topic_id => topic.id, :last_read_at => topic.updated_at)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def self.check_list!(user, topics)
|
||||
matches = where(:user_id => user.id, :forum_topic_id => topics.map(&:id)).to_a.inject({}) do |hash, x|
|
||||
hash[x.forum_topic_id] = x
|
||||
hash
|
||||
end
|
||||
topics.each do |topic|
|
||||
if matches[topic.id]
|
||||
matches[topic.id].update_attribute(:last_read_at, topic.updated_at)
|
||||
else
|
||||
create(:user_id => user.id,, :forum_topic_id => topic.id, :last_read_at => topic.updated_at)
|
||||
end
|
||||
end
|
||||
matches
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user