fix #2403, remove unused code
This commit is contained in:
@@ -81,6 +81,24 @@ class ForumTopicsController < ApplicationController
|
||||
redirect_to forum_topic_path(@merged_topic)
|
||||
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
|
||||
def normalize_search
|
||||
if params[:title_matches]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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_readonly :topic_id
|
||||
belongs_to :creator, :class_name => "User"
|
||||
@@ -16,8 +16,6 @@ class ForumPost < ActiveRecord::Base
|
||||
validate :topic_id_not_invalid
|
||||
before_destroy :validate_topic_is_unlocked
|
||||
after_save :delete_topic_if_original_post
|
||||
after_save :update_email_notifications
|
||||
attr_accessor :receive_email_notifications
|
||||
|
||||
module SearchMethods
|
||||
def body_matches(body)
|
||||
@@ -213,22 +211,4 @@ class ForumPost < ActiveRecord::Base
|
||||
def hidden_attributes
|
||||
super + [:text_index]
|
||||
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
|
||||
|
||||
@@ -108,26 +108,15 @@ class ForumTopic < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module SubscriptionMethods
|
||||
def update_subscription!(user)
|
||||
user_subscription = 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
|
||||
def user_subscription(user)
|
||||
subscriptions.where(:user_id => user.id).first
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include CategoryMethods
|
||||
include VisitMethods
|
||||
include SubscriptionMethods
|
||||
|
||||
def editable_by?(user)
|
||||
creator_id == user.id || user.is_janitor?
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
<%= f.input :topic_id, :as => :hidden %>
|
||||
<%= dtext_field "forum_post", "body" %>
|
||||
|
||||
<%= f.input :receive_email_notifications, :as => :boolean %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= dtext_preview_button "forum_post", "body" %>
|
||||
<% end %>
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
<% 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}" %>
|
||||
|
||||
<%= pf.input :receive_email_notifications, :as => :boolean %>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.is_janitor? %>
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
<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) %>
|
||||
<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 @forum_topic.is_deleted? %>
|
||||
<li><%= link_to "Undelete", undelete_forum_topic_path(@forum_topic), :method => :post %></li>
|
||||
|
||||
@@ -122,6 +122,8 @@ Rails.application.routes.draw do
|
||||
post :undelete
|
||||
get :new_merge
|
||||
post :create_merge
|
||||
post :subscribe
|
||||
post :unsubscribe
|
||||
end
|
||||
collection do
|
||||
post :mark_all_as_read
|
||||
|
||||
Reference in New Issue
Block a user