@@ -2,6 +2,7 @@ class ForumTopicsController < ApplicationController
|
|||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
before_filter :member_only, :except => [:index, :show]
|
before_filter :member_only, :except => [:index, :show]
|
||||||
before_filter :normalize_search, :only => :index
|
before_filter :normalize_search, :only => :index
|
||||||
|
after_filter :update_last_forum_read_at, :only => [:show]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@forum_topic = ForumTopic.new
|
@forum_topic = ForumTopic.new
|
||||||
@@ -18,7 +19,6 @@ class ForumTopicsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
@query = ForumTopic.active.search(params[:search])
|
@query = ForumTopic.active.search(params[:search])
|
||||||
@forum_topics = @query.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
@forum_topics = @query.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||||
@read_forum_topic_ids = read_forum_topic_ids
|
|
||||||
respond_with(@forum_topics) do |format|
|
respond_with(@forum_topics) do |format|
|
||||||
format.xml do
|
format.xml do
|
||||||
render :xml => @forum_topics.to_xml(:root => "forum-topics")
|
render :xml => @forum_topics.to_xml(:root => "forum-topics")
|
||||||
@@ -31,7 +31,6 @@ class ForumTopicsController < ApplicationController
|
|||||||
@forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page])
|
@forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page])
|
||||||
@forum_posts.all
|
@forum_posts.all
|
||||||
respond_with(@forum_topic)
|
respond_with(@forum_topic)
|
||||||
session[:read_forum_topics] = @forum_topic.mark_as_read(read_forum_topic_ids)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -68,6 +67,14 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def update_last_forum_read_at
|
||||||
|
return if CurrentUser.is_anonymous?
|
||||||
|
|
||||||
|
if CurrentUser.last_forum_read_at.nil? || CurrentUser.last_forum_read_at < @forum_topic.updated_at
|
||||||
|
CurrentUser.update_column(:last_forum_read_at, @forum_topic.updated_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def normalize_search
|
def normalize_search
|
||||||
if params[:title_matches]
|
if params[:title_matches]
|
||||||
params[:search] ||= {}
|
params[:search] ||= {}
|
||||||
@@ -80,14 +87,6 @@ private
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_forum_topics
|
|
||||||
session[:read_forum_topics].to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def read_forum_topic_ids
|
|
||||||
read_forum_topics.scan(/\S+/)
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_privilege(forum_topic)
|
def check_privilege(forum_topic)
|
||||||
if !forum_topic.editable_by?(CurrentUser.user)
|
if !forum_topic.editable_by?(CurrentUser.user)
|
||||||
raise User::PrivilegeError
|
raise User::PrivilegeError
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class SessionCreator
|
|||||||
def authenticate
|
def authenticate
|
||||||
if User.authenticate(name, password)
|
if User.authenticate(name, password)
|
||||||
user = User.find_by_name(name)
|
user = User.find_by_name(name)
|
||||||
user.update_column(:last_forum_read_at, user.last_logged_in_at)
|
|
||||||
user.update_column(:last_logged_in_at, Time.now)
|
user.update_column(:last_logged_in_at, Time.now)
|
||||||
|
|
||||||
if remember.present?
|
if remember.present?
|
||||||
@@ -29,17 +28,9 @@ class SessionCreator
|
|||||||
end
|
end
|
||||||
|
|
||||||
session[:user_id] = user.id
|
session[:user_id] = user.id
|
||||||
prune_read_forum_topics(user)
|
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def prune_read_forum_topics(user)
|
|
||||||
# if user.last_forum_read_at
|
|
||||||
# read_forum_topic_ids = session[:read_forum_topics].to_s.scan(/\S+/)
|
|
||||||
# session[:read_forum_topics] = read_forum_topic_ids.select {|x| ForumTopic.where("updated_at >= ? and id = ?", user.last_forum_read_at, x).exists?}.join(" ")
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -104,20 +104,4 @@ class ForumTopic < ActiveRecord::Base
|
|||||||
def hidden_attributes
|
def hidden_attributes
|
||||||
super + [:text_index]
|
super + [:text_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_by?(user, read_forum_topic_ids)
|
|
||||||
return true if read_forum_topic_ids.include?(id.to_s)
|
|
||||||
return false if user.last_forum_read_at.nil?
|
|
||||||
return true if updated_at < user.last_forum_read_at
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
def mark_as_read(read_forum_topic_ids)
|
|
||||||
result = (read_forum_topic_ids + [id.to_s]).uniq.join(" ")
|
|
||||||
if result.size > 3000
|
|
||||||
ids = result.scan(/\S+/)
|
|
||||||
result = ids[(ids.size / 2)..-1].join(" ")
|
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<span class="sticky">Sticky:</span>
|
<span class="sticky">Sticky:</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% unless topic.read_by?(CurrentUser.user, @read_forum_topic_ids) %>
|
<% if topic.updated_at > (CurrentUser.last_forum_read_at || Time.now) %>
|
||||||
<span class="new">NEW</span>
|
<span class="new">NEW</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user