Add spoiler_text to keyword antenna

This commit is contained in:
KMY 2023-08-25 14:29:37 +09:00
parent 579a48ce5f
commit bde0ddaca6
4 changed files with 49 additions and 8 deletions

View file

@ -14,6 +14,10 @@ module FormattingHelper
end end
module_function :extract_status_plain_text 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) 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) : [])) 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 end

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class DeliveryAntennaService class DeliveryAntennaService
include FormattingHelper
def call(status, update, stl_home) def call(status, update, stl_home)
@status = status @status = status
@account = @status.account @account = @status.account
@ -37,12 +39,13 @@ class DeliveryAntennaService
antennas = antennas.where(stl: false) antennas = antennas.where(stl: false)
collection = AntennaCollection.new(@status, @update, false) collection = AntennaCollection.new(@status, @update, false)
content = extract_status_plain_text_with_spoiler_text(@status)
antennas.in_batches do |ans| antennas.in_batches do |ans|
ans.each do |antenna| ans.each do |antenna|
next unless antenna.enabled? next unless antenna.enabled?
next if antenna.keywords&.any? && antenna.keywords&.none? { |keyword| @status.text.include?(keyword) } next if antenna.keywords&.any? && antenna.keywords&.none? { |keyword| content.include?(keyword) }
next if antenna.exclude_keywords&.any? { |keyword| @status.text.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_accounts&.include?(@status.account_id)
next if antenna.exclude_domains&.include?(domain) next if antenna.exclude_domains&.include?(domain)
next if antenna.exclude_tags&.any? { |tag_id| tag_ids.include?(tag_id) } next if antenna.exclude_tags&.any? { |tag_id| tag_ids.include?(tag_id) }

View file

@ -5,7 +5,7 @@ ja:
display_name: フルネーム、ハンドルネームなど display_name: フルネーム、ハンドルネームなど
fields: ホームページ、代名詞、年齢など何でも構いません。 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. 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. locked: People will request to follow you and you will be able to either accept or reject new followers.
note: '自己紹介には #ハッシュタグ や、ほかのアカウントのユーザー名 (@user) を使用できます' note: '自己紹介には #ハッシュタグ や、ほかのアカウントのユーザー名 (@user) を使用できます'
account_alias: account_alias:

View file

@ -6,20 +6,22 @@ RSpec.describe DeliveryAntennaService, type: :service do
subject { described_class.new } subject { described_class.new }
let(:last_active_at) { Time.now.utc } let(:last_active_at) { Time.now.utc }
let(:last_active_at_tom) { Time.now.utc }
let(:visibility) { 'public' } let(:visibility) { 'public' }
let(:searchability) { 'public' } let(:searchability) { 'public' }
let(:domain) { nil } let(:domain) { nil }
let(:spoiler_text) { '' }
let(:tags) { Tag.find_or_create_by_names(['hoge']) } let(:tags) { Tag.find_or_create_by_names(['hoge']) }
let(:status) do let(:status) do
url = domain.present? ? 'https://example.com/status' : nil 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.tags << tags.first if tags.present?
status status
end end
let!(:alice) { Fabricate(:account, domain: domain, uri: domain ? "https://#{domain}.com/alice" : '') } 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!(: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!(:ohagi) { Fabricate(:user, current_sign_in_at: last_active_at).account }
let!(:antenna) { nil } let!(:antenna) { nil }
@ -89,12 +91,16 @@ RSpec.describe DeliveryAntennaService, type: :service do
end end
context 'when blocked' do context 'when blocked' do
let!(:antenna) { antenna_with_account(bob, alice) }
let!(:empty_antenna) { antenna_with_account(ohagi, alice) } let!(:empty_antenna) { antenna_with_account(ohagi, alice) }
it 'detecting antenna' do it 'not detecting antenna' do
expect(antenna_feed_of(antenna)).to include status.id expect(antenna_feed_of(empty_antenna)).to_not include status.id
end 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 it 'not detecting antenna' do
expect(antenna_feed_of(empty_antenna)).to_not include status.id expect(antenna_feed_of(empty_antenna)).to_not include status.id
@ -141,6 +147,34 @@ RSpec.describe DeliveryAntennaService, type: :service do
end end
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 context 'with domain and excluding account' do
let(:domain) { 'fast.example.com' } let(:domain) { 'fast.example.com' }
let!(:antenna) { antenna_with_domain(bob, 'fast.example.com', exclude_accounts: [tom.id]) } let!(:antenna) { antenna_with_domain(bob, 'fast.example.com', exclude_accounts: [tom.id]) }