Fix lint errors

This commit is contained in:
Karina Kwiatek 2023-08-18 19:43:59 +02:00
parent 620121341e
commit d39f37072d
3 changed files with 21 additions and 11 deletions

View File

@ -28,15 +28,18 @@ class Subscription < ApplicationRecord
def notify(source, target) def notify(source, target)
return nil if source.nil? || target.nil? return nil if source.nil? || target.nil?
muted_by = Relationships::Mute.where(target: source.user).pluck(&:source_id)
# As we will need to notify for each person subscribed, # As we will need to notify for each person subscribed,
# it's much faster to bulk insert than to use +Notification.notify+ # it's much faster to bulk insert than to use +Notification.notify+
notifications = Subscription.where(answer: target) notifications = Subscription.for(source, target).pluck(:user_id).map do |recipient_id|
.where.not(user: source.user) {
.where.not(user_id: muted_by) target_id: source.id,
.map do |s| target_type: Comment,
{ target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented, created_at: source.created_at, updated_at: source.created_at } recipient_id:,
new: true,
type: Notification::Commented,
created_at: source.created_at,
updated_at: source.created_at,
}
end end
return if notifications.empty? return if notifications.empty?
@ -53,5 +56,13 @@ class Subscription < ApplicationRecord
subs = Subscription.where(answer: target) subs = Subscription.where(answer: target)
Notification.where(target:, recipient: subs.map(&:user)).delete_all Notification.where(target:, recipient: subs.map(&:user)).delete_all
end end
def for(source, target)
muted_by = Relationships::Mute.where(target: source.user).pluck(&:source_id)
Subscription.where(answer: target)
.where.not(user: source.user)
.where.not(user_id: muted_by)
end
end end
end end

View File

@ -35,7 +35,6 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
expect { subject }.to change { subscribed_user.reload.notifications_updated_at }.to(DateTime.now) expect { subject }.to change { subscribed_user.reload.notifications_updated_at }.to(DateTime.now)
end end
end end
end end
include_examples "returns the expected response" include_examples "returns the expected response"

View File

@ -43,10 +43,10 @@ describe BootstrapHelper, :type => :helper do
) )
end end
it 'should put an ID on the entry an id if given' do it "should put an ID on the entry an id if given" do
allow(self).to receive(:current_page?).and_return(false) allow(self).to receive(:current_page?).and_return(false)
expect(nav_entry('Example', '/example', id: "testing")).to( expect(nav_entry("Example", "/example", id: "testing")).to(
eq('<li class="nav-item " id="testing"><a class="nav-link" href="/example">Example</a></li>') eq("<li class=\"nav-item \" id=\"testing\"><a class=\"nav-link\" href=\"/example\">Example</a></li>"),
) )
end end
end end