diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb index 024ea64fbb..112c4256f5 100644 --- a/app/helpers/formatting_helper.rb +++ b/app/helpers/formatting_helper.rb @@ -14,6 +14,10 @@ module FormattingHelper end module_function :extract_status_plain_text + def extract_status_plain_text_with_spoiler_text(status) + PlainTextFormatter.new("#{status.spoiler_text}\n#{status.text}", status.local?).to_s + end + def status_content_format(status) html_aware_format(status.text, status.local?, markdown: status.markdown, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : [])) end diff --git a/app/services/delivery_antenna_service.rb b/app/services/delivery_antenna_service.rb index 2d53571d87..9bc67dea59 100644 --- a/app/services/delivery_antenna_service.rb +++ b/app/services/delivery_antenna_service.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class DeliveryAntennaService + include FormattingHelper + def call(status, update, stl_home) @status = status @account = @status.account @@ -37,12 +39,13 @@ class DeliveryAntennaService antennas = antennas.where(stl: false) collection = AntennaCollection.new(@status, @update, false) + content = extract_status_plain_text_with_spoiler_text(@status) antennas.in_batches do |ans| ans.each do |antenna| next unless antenna.enabled? - next if antenna.keywords&.any? && antenna.keywords&.none? { |keyword| @status.text.include?(keyword) } - next if antenna.exclude_keywords&.any? { |keyword| @status.text.include?(keyword) } + next if antenna.keywords&.any? && antenna.keywords&.none? { |keyword| content.include?(keyword) } + next if antenna.exclude_keywords&.any? { |keyword| content.include?(keyword) } next if antenna.exclude_accounts&.include?(@status.account_id) next if antenna.exclude_domains&.include?(domain) next if antenna.exclude_tags&.any? { |tag_id| tag_ids.include?(tag_id) } diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index 0ad1e7d2e4..4617d6c849 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -5,7 +5,7 @@ ja: display_name: フルネーム、ハンドルネームなど fields: ホームページ、代名詞、年齢など何でも構いません。 hide_collections: People will not be able to browse through your follows and followers. People that you follow will see that you follow them regardless. - indexable: 他のMastodonサーバーの人は誰でもあなたの公開投稿を検索できるようになります。kmyblue内での検索では、この設定は無視され代わりに「検索許可」が適用されます。FedibirdのようなSearchability対応サーバー、Misskey、その他個別にSearchabilityをプロフィールに設定したアカウントの投稿も同様に「検索許可」が優先されます + indexable: 他のMastodonサーバーの人は誰でもあなたの公開投稿を検索できるようになります。ただしkmyblue内での検索の場合、この設定は無視され代わりに「検索許可」が適用されます locked: People will request to follow you and you will be able to either accept or reject new followers. note: '自己紹介には #ハッシュタグ や、ほかのアカウントのユーザー名 (@user) を使用できます' account_alias: diff --git a/spec/services/delivery_antenna_service_spec.rb b/spec/services/delivery_antenna_service_spec.rb index b2df43ac26..ba20157348 100644 --- a/spec/services/delivery_antenna_service_spec.rb +++ b/spec/services/delivery_antenna_service_spec.rb @@ -6,20 +6,22 @@ RSpec.describe DeliveryAntennaService, type: :service do subject { described_class.new } let(:last_active_at) { Time.now.utc } + let(:last_active_at_tom) { Time.now.utc } let(:visibility) { 'public' } let(:searchability) { 'public' } let(:domain) { nil } + let(:spoiler_text) { '' } let(:tags) { Tag.find_or_create_by_names(['hoge']) } let(:status) do url = domain.present? ? 'https://example.com/status' : nil - status = Fabricate(:status, account: alice, visibility: visibility, searchability: searchability, text: 'Hello my body #hoge', url: url) + status = Fabricate(:status, account: alice, spoiler_text: spoiler_text, visibility: visibility, searchability: searchability, text: 'Hello my body #hoge', url: url) status.tags << tags.first if tags.present? status end let!(:alice) { Fabricate(:account, domain: domain, uri: domain ? "https://#{domain}.com/alice" : '') } let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at).account } - let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at).account } + let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at_tom).account } let!(:ohagi) { Fabricate(:user, current_sign_in_at: last_active_at).account } let!(:antenna) { nil } @@ -89,12 +91,16 @@ RSpec.describe DeliveryAntennaService, type: :service do end context 'when blocked' do - let!(:antenna) { antenna_with_account(bob, alice) } let!(:empty_antenna) { antenna_with_account(ohagi, alice) } - it 'detecting antenna' do - expect(antenna_feed_of(antenna)).to include status.id + it 'not detecting antenna' do + expect(antenna_feed_of(empty_antenna)).to_not include status.id end + end + + context 'when non-used' do + let(:last_active_at_tom) { Time.now.utc.ago(1.year) } + let!(:empty_antenna) { antenna_with_account(tom, alice) } it 'not detecting antenna' do expect(antenna_feed_of(empty_antenna)).to_not include status.id @@ -141,6 +147,34 @@ RSpec.describe DeliveryAntennaService, type: :service do end end + context 'with keyword and spoiler_text' do + let(:spoiler_text) { 'some self' } + let!(:antenna) { antenna_with_keyword(bob, 'some') } + let!(:empty_antenna) { antenna_with_keyword(tom, 'anime') } + + it 'detecting antenna' do + expect(antenna_feed_of(antenna)).to include status.id + end + + it 'not detecting antenna' do + expect(antenna_feed_of(empty_antenna)).to_not include status.id + end + end + + context 'with keyword and spoiler_text but pick from text' do + let(:spoiler_text) { 'some self' } + let!(:antenna) { antenna_with_keyword(bob, 'body') } + let!(:empty_antenna) { antenna_with_keyword(tom, 'anime') } + + it 'detecting antenna' do + expect(antenna_feed_of(antenna)).to include status.id + end + + it 'not detecting antenna' do + expect(antenna_feed_of(empty_antenna)).to_not include status.id + end + end + context 'with domain and excluding account' do let(:domain) { 'fast.example.com' } let!(:antenna) { antenna_with_domain(bob, 'fast.example.com', exclude_accounts: [tom.id]) }