diff --git a/app/models/status.rb b/app/models/status.rb index 95d4f2b759..cdfd7b9555 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -78,6 +78,7 @@ class Status < ApplicationRecord has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy has_many :reblogged_by_accounts, through: :reblogs, class_name: 'Account', source: :account has_many :quotes, foreign_key: 'quote_of_id', class_name: 'Status', inverse_of: :quote + has_many :quoted_by_accounts, through: :quotes, class_name: 'Account', source: :account has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread has_many :mentions, dependent: :destroy, inverse_of: :status has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account' diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 89e1b6c9c5..6df3364d85 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -89,7 +89,7 @@ class FanOutOnWriteService < BaseService end def notify_about_update! - @status.reblogged_by_accounts.merge(Account.local).select(:id).reorder(nil).find_in_batches do |accounts| + @status.reblogged_by_accounts.or(@status.quoted_by_accounts).merge(Account.local).select(:id).reorder(nil).find_in_batches do |accounts| LocalNotificationWorker.push_bulk(accounts) do |account| [account.id, @status.id, 'Status', 'update'] end diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb index 17d9f91252..1df413b7a8 100644 --- a/spec/services/fan_out_on_write_service_spec.rb +++ b/spec/services/fan_out_on_write_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe FanOutOnWriteService, type: :service do subject { described_class.new } let(:last_active_at) { Time.now.utc } + let(:visibility) { 'public' } let(:searchability) { 'public' } let(:dissubscribable) { false } let(:status) { Fabricate(:status, account: alice, visibility: visibility, searchability: searchability, text: 'Hello @bob #hoge') } @@ -20,6 +21,8 @@ RSpec.describe FanOutOnWriteService, type: :service do let!(:antenna) { nil } let!(:empty_antenna) { nil } + let(:custom_before) { false } + before do bob.follow!(alice) tom.follow!(alice) @@ -30,7 +33,7 @@ RSpec.describe FanOutOnWriteService, type: :service do allow(redis).to receive(:publish) - subject.call(status) + subject.call(status) unless custom_before end def home_feed_of(account) @@ -469,4 +472,35 @@ RSpec.describe FanOutOnWriteService, type: :service do end end end + + context 'when updated status is already boosted or quoted' do + let(:custom_before) { true } + + before do + ReblogService.new.call(bob, status) + PostStatusService.new.call(tom, text: "Hello QT #{ActivityPub::TagManager.instance.uri_for(status)}") + + subject.call(status, update: true) + end + + it 'notified to boosted account' do + notification = Notification.find_by(account: bob, type: 'update') + + expect(notification).to_not be_nil + expect(notification.activity_id).to eq status.id + end + + it 'notified to quoted account' do + notification = Notification.find_by(account: tom, type: 'update') + + expect(notification).to_not be_nil + expect(notification.activity_id).to eq status.id + end + + it 'notified not to non-boosted account' do + notification = Notification.find_by(account: ohagi, type: 'update') + + expect(notification).to be_nil + end + end end