From c716972740dba2f5882b658008c27a1807e1d585 Mon Sep 17 00:00:00 2001 From: Moshi <54333972+MoshiKoi@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:31:54 -0700 Subject: [PATCH 1/2] Remove special case notifying author of threads Instead of special casing creating a notification, we just have them follow normally automatically. --- app/controllers/comments_controller.rb | 5 +---- app/controllers/posts_controller.rb | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 57894f297..0a2b3751f 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) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d3295ea77..3b95348f6 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}", From f0f5555f5c9851eda6c14e5cb40817551375468e Mon Sep 17 00:00:00 2001 From: Moshi <54333972+MoshiKoi@users.noreply.github.com> Date: Tue, 16 May 2023 17:00:36 -0700 Subject: [PATCH 2/2] Fix duplicate ThreadFollowers --- app/controllers/comments_controller.rb | 3 +-- app/models/comment_thread.rb | 10 ---------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0a2b3751f..a3eb1f311 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -227,8 +227,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/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