fix #2403, remove unused code
This commit is contained in:
@@ -81,6 +81,24 @@ class ForumTopicsController < ApplicationController
|
|||||||
redirect_to forum_topic_path(@merged_topic)
|
redirect_to forum_topic_path(@merged_topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subscribe
|
||||||
|
@forum_topic = ForumTopic.find(params[:id])
|
||||||
|
subscription = ForumSubscription.where(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id).first
|
||||||
|
unless subscription
|
||||||
|
ForumSubscription.create(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id, :last_read_at => @forum_topic.updated_at)
|
||||||
|
end
|
||||||
|
respond_with(@forum_topic)
|
||||||
|
end
|
||||||
|
|
||||||
|
def unsubscribe
|
||||||
|
@forum_topic = ForumTopic.find(params[:id])
|
||||||
|
subscription = ForumSubscription.where(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id).first
|
||||||
|
if subscription
|
||||||
|
subscription.destroy
|
||||||
|
end
|
||||||
|
respond_with(@forum_topic)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def normalize_search
|
def normalize_search
|
||||||
if params[:title_matches]
|
if params[:title_matches]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class ForumPost < ActiveRecord::Base
|
class ForumPost < ActiveRecord::Base
|
||||||
attr_accessible :body, :topic_id, :receive_email_notifications, :as => [:member, :builder, :janitor, :gold, :platinum, :contributor, :admin, :moderator, :default]
|
attr_accessible :body, :topic_id, :as => [:member, :builder, :janitor, :gold, :platinum, :contributor, :admin, :moderator, :default]
|
||||||
attr_accessible :is_locked, :is_sticky, :is_deleted, :as => [:admin, :moderator, :janitor]
|
attr_accessible :is_locked, :is_sticky, :is_deleted, :as => [:admin, :moderator, :janitor]
|
||||||
attr_readonly :topic_id
|
attr_readonly :topic_id
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
@@ -16,8 +16,6 @@ class ForumPost < ActiveRecord::Base
|
|||||||
validate :topic_id_not_invalid
|
validate :topic_id_not_invalid
|
||||||
before_destroy :validate_topic_is_unlocked
|
before_destroy :validate_topic_is_unlocked
|
||||||
after_save :delete_topic_if_original_post
|
after_save :delete_topic_if_original_post
|
||||||
after_save :update_email_notifications
|
|
||||||
attr_accessor :receive_email_notifications
|
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def body_matches(body)
|
def body_matches(body)
|
||||||
@@ -213,22 +211,4 @@ class ForumPost < ActiveRecord::Base
|
|||||||
def hidden_attributes
|
def hidden_attributes
|
||||||
super + [:text_index]
|
super + [:text_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive_email_notifications
|
|
||||||
@receive_email_notifications ||= ForumSubscription.where(:forum_topic_id => topic_id, :user_id => CurrentUser.user.id).exists?
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_email_notifications
|
|
||||||
subscription = ForumSubscription.where(:forum_topic_id => topic_id, :user_id => CurrentUser.user.id).first
|
|
||||||
|
|
||||||
if receive_email_notifications == "1" || receive_email_notifications == true
|
|
||||||
if subscription
|
|
||||||
subscription.update_attribute(:last_read_at, updated_at)
|
|
||||||
else
|
|
||||||
ForumSubscription.create(:forum_topic_id => topic_id, :user_id => CurrentUser.user.id, :last_read_at => updated_at)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
subscription.destroy if subscription
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -108,26 +108,15 @@ class ForumTopic < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
module SubscriptionMethods
|
module SubscriptionMethods
|
||||||
def update_subscription!(user)
|
def user_subscription(user)
|
||||||
user_subscription = subscriptions.where(:user_id => user.id).first
|
subscriptions.where(:user_id => user.id).first
|
||||||
|
|
||||||
if user_subscription
|
|
||||||
user_subscription.update_attribute(:last_read_at, updated_at)
|
|
||||||
else
|
|
||||||
subscriptions.create(:user_id => user.id, :last_read_at => updated_at, :delete_key => SecureRandom.urlsafe_base64(10))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def notify_subscriptions!
|
|
||||||
ForumSubscription.where(:forum_topic_id => id).where("last_read_at < ?", updated_at).find_each do |subscription|
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
include CategoryMethods
|
include CategoryMethods
|
||||||
include VisitMethods
|
include VisitMethods
|
||||||
|
include SubscriptionMethods
|
||||||
|
|
||||||
def editable_by?(user)
|
def editable_by?(user)
|
||||||
creator_id == user.id || user.is_janitor?
|
creator_id == user.id || user.is_janitor?
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
<%= f.input :topic_id, :as => :hidden %>
|
<%= f.input :topic_id, :as => :hidden %>
|
||||||
<%= dtext_field "forum_post", "body" %>
|
<%= dtext_field "forum_post", "body" %>
|
||||||
|
|
||||||
<%= f.input :receive_email_notifications, :as => :boolean %>
|
|
||||||
|
|
||||||
<%= f.button :submit, "Submit" %>
|
<%= f.button :submit, "Submit" %>
|
||||||
<%= dtext_preview_button "forum_post", "body" %>
|
<%= dtext_preview_button "forum_post", "body" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= dtext_field "forum_post", "body", :input_name => "forum_topic[original_post_attributes][body]", :value => forum_topic.original_post.body, :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %>
|
<%= dtext_field "forum_post", "body", :input_name => "forum_topic[original_post_attributes][body]", :value => forum_topic.original_post.body, :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %>
|
||||||
|
|
||||||
<%= pf.input :receive_email_notifications, :as => :boolean %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if CurrentUser.is_janitor? %>
|
<% if CurrentUser.is_janitor? %>
|
||||||
|
|||||||
@@ -15,6 +15,11 @@
|
|||||||
<li><%= link_to "Reply", new_forum_post_path(:topic_id => @forum_topic.id) %></li>
|
<li><%= link_to "Reply", new_forum_post_path(:topic_id => @forum_topic.id) %></li>
|
||||||
<% if !@forum_topic.new_record? && @forum_topic.editable_by?(CurrentUser.user) %>
|
<% if !@forum_topic.new_record? && @forum_topic.editable_by?(CurrentUser.user) %>
|
||||||
<li><%= link_to "Edit", edit_forum_topic_path(@forum_topic) %></li>
|
<li><%= link_to "Edit", edit_forum_topic_path(@forum_topic) %></li>
|
||||||
|
<% if @forum_topic.user_subscription(CurrentUser.user) %>
|
||||||
|
<li><%= link_to "Unsubscribe", unsubscribe_forum_topic_path(@forum_topic), :method => :post %></li>
|
||||||
|
<% else %>
|
||||||
|
<li><%= link_to "Subscribe", subscribe_forum_topic_path(@forum_topic), :method => :post, :data => {:confirm => "Are you sure you want to subscribe to this forum topic?"} %></li>
|
||||||
|
<% end %>
|
||||||
<% if CurrentUser.is_janitor? %>
|
<% if CurrentUser.is_janitor? %>
|
||||||
<% if @forum_topic.is_deleted? %>
|
<% if @forum_topic.is_deleted? %>
|
||||||
<li><%= link_to "Undelete", undelete_forum_topic_path(@forum_topic), :method => :post %></li>
|
<li><%= link_to "Undelete", undelete_forum_topic_path(@forum_topic), :method => :post %></li>
|
||||||
|
|||||||
@@ -122,6 +122,8 @@ Rails.application.routes.draw do
|
|||||||
post :undelete
|
post :undelete
|
||||||
get :new_merge
|
get :new_merge
|
||||||
post :create_merge
|
post :create_merge
|
||||||
|
post :subscribe
|
||||||
|
post :unsubscribe
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
post :mark_all_as_read
|
post :mark_all_as_read
|
||||||
|
|||||||
Reference in New Issue
Block a user