diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 607d391a8..6398f8abe 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -41,12 +41,9 @@ def create_thread if success notification = "New comment thread on #{@comment.root.title}: #{@comment_thread.title}" - unless @comment.post.user == current_user - @comment.post.user.create_notification(notification, helpers.comment_link(@comment)) - end ThreadFollower.where(post: @post).each do |tf| - unless tf.user == current_user || tf.user == @comment.post.user + unless tf.user == current_user tf.user.create_notification(notification, helpers.comment_link(@comment)) end ThreadFollower.create(user: tf.user, comment_thread: @comment_thread) @@ -237,8 +234,7 @@ def thread_unrestrict end @comment_thread.update(deleted: false, deleted_by: nil) when 'follow' - tf = ThreadFollower.find_by(comment_thread: @comment_thread, user: current_user) - tf&.destroy + ThreadFollower.where(comment_thread: @comment_thread, user: current_user).destroy_all else return not_found end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index faf89737e..393ed36e7 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -100,6 +100,7 @@ def create if @post.save @post.update(last_activity: @post.created_at, last_activity_by: current_user) + ThreadFollower.create user: @post.user, post: @post if @post_type.has_parent? unless @post.user_id == @post.parent.user_id @post.parent.user.create_notification("New response to your post #{@post.parent.title}", diff --git a/app/models/comment_thread.rb b/app/models/comment_thread.rb index 39f5dcf5c..4858a4d16 100644 --- a/app/models/comment_thread.rb +++ b/app/models/comment_thread.rb @@ -13,8 +13,6 @@ class CommentThread < ApplicationRecord scope :publicly_available, -> { where(deleted: false).where('reply_count > 0') } scope :archived, -> { where(archived: true) } - after_create :create_follower - def read_only? locked? || archived? || deleted? end @@ -38,12 +36,4 @@ def self.post_followed?(post, user) private - # Comment author and post author are automatically followed to the thread. Question author is NOT - # automatically followed on new answer comment threads. Comment author follower creation is done - # on the Comment model. - def create_follower - if post.user.preference('auto_follow_comment_threads') == 'true' - ThreadFollower.create comment_thread: self, user: post.user - end - end end