This reverts commit 852223dd86.
This commit is contained in:
parent
b3d7f76dd0
commit
a16fc46f84
12 changed files with 7 additions and 113 deletions
|
|
@ -65,8 +65,10 @@ class CommentsController < ApplicationController
|
|||
checked_code_of_conduct = params[:checked_code_of_conduct].present? && !current_user.checked_code_of_conduct
|
||||
current_user.update(checked_code_of_conduct: true) if checked_code_of_conduct
|
||||
|
||||
Comments::CreateNotificationSubscriptionWorker.perform_async(current_user.id, @comment.id)
|
||||
Notification.send_new_comment_notifications(@comment)
|
||||
NotificationSubscription.create(
|
||||
user: current_user, notifiable_id: @comment.id, notifiable_type: "Comment", config: "all_comments",
|
||||
)
|
||||
Notification.send_new_comment_notifications_without_delay(@comment)
|
||||
Mention.create_all(@comment)
|
||||
|
||||
if @comment.invalid?
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class Article < ApplicationRecord
|
|||
after_save :notify_slack_channel_about_publication
|
||||
|
||||
after_update_commit :update_notifications, if: proc { |article|
|
||||
!article.saved_changes.empty? && article.notifications.any?
|
||||
article.notifications.any? && !article.saved_changes.empty?
|
||||
}
|
||||
after_commit :async_score_calc, :update_main_image_background_hex, :touch_collection, on: %i[create update]
|
||||
after_commit :index_to_elasticsearch, on: %i[create update]
|
||||
|
|
|
|||
|
|
@ -223,18 +223,12 @@ class Comment < ApplicationRecord
|
|||
end
|
||||
|
||||
def synchronous_bust
|
||||
async_touch_commentable_last_comment_at
|
||||
commentable.touch(:last_comment_at) if commentable.respond_to?(:last_comment_at)
|
||||
user.touch(:last_comment_at)
|
||||
CacheBuster.bust(commentable.path.to_s) if commentable
|
||||
expire_root_fragment
|
||||
end
|
||||
|
||||
def async_touch_commentable_last_comment_at
|
||||
return unless commentable
|
||||
|
||||
Comments::UpdateCommentableLastCommentAtWorker.perform_async(commentable.id, commentable.class.name)
|
||||
end
|
||||
|
||||
def send_email_notification
|
||||
Comments::SendEmailNotificationWorker.perform_async(id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,13 +51,6 @@ class Notification < ApplicationRecord
|
|||
Notifications::NewComment::Send.call(comment)
|
||||
end
|
||||
|
||||
def send_new_comment_notifications(comment)
|
||||
return if comment.commentable_type == "PodcastEpisode"
|
||||
return if UserBlock.blocking?(comment.commentable.user_id, comment.user_id)
|
||||
|
||||
Comments::SendNewCommentNotificationsWorker.perform_async(comment.id)
|
||||
end
|
||||
|
||||
def send_new_badge_achievement_notification(badge_achievement)
|
||||
Notifications::NewBadgeAchievementWorker.perform_async(badge_achievement.id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
module Comments
|
||||
class CreateNotificationSubscriptionWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :high_priority
|
||||
|
||||
def perform(user_id, comment_id)
|
||||
comment = Comment.find(comment_id)
|
||||
user = User.find(user_id)
|
||||
NotificationSubscription.create(
|
||||
user: user, notifiable_id: comment.id, notifiable_type: "Comment", config: "all_comments",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
module Comments
|
||||
class SendNewCommentNotificationsWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :high_priority
|
||||
|
||||
def perform(comment_id)
|
||||
comment = Comment.find_by(id: comment_id)
|
||||
Notifications::NewComment::Send.call(comment) if comment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
module Comments
|
||||
class UpdateCommentableLastCommentAtWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :high_priority
|
||||
|
||||
def perform(commentable_id, commentable_type)
|
||||
commentable = commentable_type.constantize.find(commentable_id)
|
||||
commentable.touch(:last_comment_at) if commentable.respond_to?(:last_comment_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -29,7 +29,6 @@ RSpec.describe "CommentsCreate", type: :request do
|
|||
|
||||
it "creates NotificationSubscription for comment" do
|
||||
post comments_path, params: comment_params
|
||||
sidekiq_perform_enqueued_jobs
|
||||
|
||||
expect(NotificationSubscription.last.notifiable).to eq(Comment.last)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -265,12 +265,11 @@ RSpec.describe "Comments", type: :request do
|
|||
it "updates body markdown" do
|
||||
article = create(:article, user: user)
|
||||
comment = create(:comment, commentable: article, user: user)
|
||||
sidekiq_perform_enqueued_jobs
|
||||
|
||||
article.destroy
|
||||
|
||||
params = { comment: { body_markdown: "{edited comment}" } }
|
||||
put "/comments/#{comment.id}", params: params
|
||||
sidekiq_perform_enqueued_jobs
|
||||
|
||||
comment.reload
|
||||
expect(comment.processed_html).to include("edited comment")
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Comments::CreateNotificationSubscriptionWorker, type: :worker do
|
||||
include_examples "#enqueues_on_correct_queue", "high_priority", 1
|
||||
|
||||
describe "#perform_now" do
|
||||
let(:worker) { subject }
|
||||
|
||||
it "creates NotificationSubscription for comment" do
|
||||
comment = create(:comment)
|
||||
worker.perform(comment.user_id, comment.id)
|
||||
|
||||
expect(NotificationSubscription.last.notifiable).to eq(comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Comments::SendNewCommentNotificationsWorker, type: :worker do
|
||||
include_examples "#enqueues_on_correct_queue", "high_priority", 1
|
||||
|
||||
describe "#perform_now" do
|
||||
let(:worker) { subject }
|
||||
|
||||
it "sends new comment notification" do
|
||||
allow(Notifications::NewComment::Send).to receive(:call)
|
||||
comment = create(:comment)
|
||||
worker.perform(comment.id)
|
||||
|
||||
expect(Notifications::NewComment::Send).to have_received(:call)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Comments::UpdateCommentableLastCommentAtWorker, type: :worker do
|
||||
include_examples "#enqueues_on_correct_queue", "high_priority", 1
|
||||
|
||||
describe "#perform_now" do
|
||||
let(:worker) { subject }
|
||||
|
||||
it "updates commentable last_comment_at" do
|
||||
comment = create(:comment)
|
||||
commentable = comment.commentable
|
||||
Timecop.freeze do
|
||||
old_time = 1.week.ago
|
||||
commentable.update(last_comment_at: old_time)
|
||||
worker.perform(commentable.id, commentable.class.name)
|
||||
|
||||
expect(commentable.reload.last_comment_at).not_to eq(old_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue