diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index be87161cc8c631..c375afc9132b5e 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -79,13 +79,9 @@ def misskey_software? @misskey_software = false return false if !@status.local? || signed_request_account&.domain.blank? || !@status.sending_maybe_compromised_privacy? - return @misskey_software = true if DomainBlock.detect_invalid_subscription?(signed_request_account.domain) - info = InstanceInfo.find_by(domain: signed_request_account.domain) - return false if info.nil? - - @misskey_software = %w(misskey calckey cherrypick sharkey).include?(info.software) + @misskey_software = InstanceInfo.invalid_subscription_software?(signed_request_account.domain) end def status_activity_serializer diff --git a/app/helpers/follow_helper.rb b/app/helpers/follow_helper.rb index d7d7ff35e94520..a02e2a8832fec5 100644 --- a/app/helpers/follow_helper.rb +++ b/app/helpers/follow_helper.rb @@ -27,9 +27,6 @@ def proxy_account?(account) def proxyable_software?(account) return false if account.local? - info = InstanceInfo.find_by(domain: account.domain) - return false if info.nil? - - %w(misskey calckey firefish meisskey cherrypick sharkey).include?(info.software) + InstanceInfo.proxy_account_software?(account.domain) end end diff --git a/app/lib/account_statuses_filter.rb b/app/lib/account_statuses_filter.rb index f97d9def3e54cf..a14c943d01aae6 100644 --- a/app/lib/account_statuses_filter.rb +++ b/app/lib/account_statuses_filter.rb @@ -161,14 +161,7 @@ def domain_block def misskey_software? return false if @account.nil? || @account.local? - return false if instance_info.nil? - %w(misskey cherrypick).include?(instance_info.software) - end - - def instance_info - return @instance_info if defined?(@instance_info) - - @instance_info = InstanceInfo.find_by(domain: @account.domain) + InstanceInfo.invalid_subscription_software?(@account.domain) end end diff --git a/app/lib/activitypub/parser/status_parser.rb b/app/lib/activitypub/parser/status_parser.rb index e982a12e633b43..a2ae6588741815 100644 --- a/app/lib/activitypub/parser/status_parser.rb +++ b/app/lib/activitypub/parser/status_parser.rb @@ -103,7 +103,7 @@ def searchability return from_audience if from_audience return nil if default_searchability_from_bio? - searchability_from_bio || (misskey_software? ? misskey_searchability : nil) + searchability_from_bio || (invalid_subscription_software? ? misskey_searchability : nil) end def limited_scope @@ -120,7 +120,7 @@ def limited_scope end def language - lang = raw_language_code || (misskey_software? ? 'ja' : nil) + lang = raw_language_code || (no_language_flag_software? ? 'ja' : nil) lang.presence && NORMALIZED_LOCALE_NAMES.fetch(lang.downcase.to_sym, lang) end @@ -162,15 +162,12 @@ def name_language_map? @object['nameMap'].is_a?(Hash) && !@object['nameMap'].empty? end - def instance_info - @instance_info ||= InstanceInfo.find_by(domain: @account.domain) + def no_language_flag_software? + InstanceInfo.no_language_flag_software?(@account.domain) end - def misskey_software? - info = instance_info - return false if info.nil? - - %w(misskey calckey).include?(info.software) + def invalid_subscription_software? + InstanceInfo.invalid_subscription_software?(@account.domain) end def misskey_searchability diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb index 1058bd30e730b6..47f8256d21fc95 100644 --- a/app/lib/status_reach_finder.rb +++ b/app/lib/status_reach_finder.rb @@ -220,7 +220,7 @@ def banned_domains_for_misskey def banned_domains_for_misskey_of_status(status) return [] if status.public_searchability? - from_info = InstanceInfo.where(software: %w(misskey calckey cherrypick sharkey)).pluck(:domain) + from_info = InstanceInfo.where(software: InstanceInfo::INVALID_SUBSCRIPTION_SOFTWARES).pluck(:domain) from_domain_block = DomainBlock.where(detect_invalid_subscription: true).pluck(:domain) (from_info + from_domain_block).uniq end diff --git a/app/models/instance_info.rb b/app/models/instance_info.rb index da6396517a5676..45278e37f9f946 100644 --- a/app/models/instance_info.rb +++ b/app/models/instance_info.rb @@ -37,19 +37,43 @@ class InstanceInfo < ApplicationRecord CIRCLE_AVAILABLE_SOFTWARES = %w(fedibird).freeze - class << self - def emoji_reaction_available?(domain) - return Setting.enable_emoji_reaction if domain.nil? + MISSKEY_FORKS = %w( + calckey + cherrypick + firefish + iceshrimp + meisskey + misskey + rosekey + sharkey + tanukey + ).freeze - Rails.cache.fetch("emoji_reaction_available_domain:#{domain}") { load_emoji_reaction_available(domain) } - end + INVALID_SUBSCRIPTION_SOFTWARES = MISSKEY_FORKS - %w(firefish) + + PROXY_ACCOUNT_SOFTWARES = MISSKEY_FORKS + + NO_LANGUAGE_FLAG_SOFTWARES = MISSKEY_FORKS - %w(firefish) + class << self def available_features(domain) return local_features if domain.nil? Rails.cache.fetch("domain_available_features:#{domain}") { load_available_features(domain) } end + def invalid_subscription_software?(domain) + INVALID_SUBSCRIPTION_SOFTWARES.include?(software_name(domain)) + end + + def proxy_account_software?(domain) + PROXY_ACCOUNT_SOFTWARES.include?(software_name(domain)) + end + + def no_language_flag_software?(domain) + NO_LANGUAGE_FLAG_SOFTWARES.include?(software_name(domain)) + end + private def load_available_features(domain) @@ -77,7 +101,7 @@ def local_features def feature_available?(info, softwares, feature_name) return false if info.nil? - softwares.include?(software_name(info)) || metadata_features(info)&.include?(feature_name) || false + softwares.include?(info.software) || metadata_features(info)&.include?(feature_name) || false end def metadata_features(info) @@ -86,7 +110,16 @@ def metadata_features(info) info.data['metadata']['features'] end - def software_name(info) + def software_name(domain) + Rails.cache.fetch("software_name:#{domain}") { load_software_name(domain) } + end + + def load_software_name(domain) + return 'threads' if domain == 'threads.net' + + info = InstanceInfo.find_by(domain: domain) + return nil if info.nil? + info.software end end @@ -94,7 +127,7 @@ def software_name(info) private def reset_cache - Rails.cache.delete("emoji_reaction_available_domain:#{domain}") Rails.cache.delete("domain_available_features:#{domain}") + Rails.cache.delete("software_name:#{domain}") end end diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 6897ef30682970..474fad59d531eb 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -286,7 +286,7 @@ def searchability_from_audience bio = searchability_from_bio return bio unless bio.nil? - return misskey_software? ? misskey_searchability_from_indexable : :direct + return invalid_subscription_software? ? misskey_searchability_from_indexable : :direct end if audience_searchable_by.any? { |uri| ActivityPub::TagManager.instance.public_collection?(uri) } @@ -328,11 +328,8 @@ def instance_info @instance_info ||= InstanceInfo.find_by(domain: @domain) end - def misskey_software? - info = instance_info - return false if info.nil? - - %w(misskey calckey).include?(info.software) + def invalid_subscription_software? + InstanceInfo.invalid_subscription_software?(@domain) end def subscribable_by diff --git a/spec/models/instance_info_spec.rb b/spec/models/instance_info_spec.rb index 32208ee8f8af9a..2694de65ac64b0 100644 --- a/spec/models/instance_info_spec.rb +++ b/spec/models/instance_info_spec.rb @@ -59,4 +59,37 @@ expect(subject).to be true end end + + describe '.software_name' do + before do + Fabricate(:instance_info, domain: 'misskey.io', software: 'misskey') + Fabricate(:instance_info, domain: 'novelskey.tarbin.net', software: 'tanukey') + Fabricate(:instance_info, domain: 'mastodon.social', software: 'mastodon') + Fabricate(:instance_info, domain: 'firefish.social', software: 'firefish') + end + + it 'detect invalid subscription domains' do + expect(described_class.invalid_subscription_software?('misskey.io')).to be true + expect(described_class.invalid_subscription_software?('novelskey.tarbin.net')).to be true + expect(described_class.invalid_subscription_software?('mastodon.social')).to be false + expect(described_class.invalid_subscription_software?('firefish.social')).to be false + expect(described_class.invalid_subscription_software?('ohagi.social')).to be false + end + + it 'detect proxy account software domains' do + expect(described_class.proxy_account_software?('misskey.io')).to be true + expect(described_class.proxy_account_software?('novelskey.tarbin.net')).to be true + expect(described_class.proxy_account_software?('mastodon.social')).to be false + expect(described_class.proxy_account_software?('firefish.social')).to be true + expect(described_class.proxy_account_software?('ohagi.social')).to be false + end + + it 'detect no language software domains' do + expect(described_class.no_language_flag_software?('misskey.io')).to be true + expect(described_class.no_language_flag_software?('novelskey.tarbin.net')).to be true + expect(described_class.no_language_flag_software?('mastodon.social')).to be false + expect(described_class.no_language_flag_software?('firefish.social')).to be false + expect(described_class.no_language_flag_software?('ohagi.social')).to be false + end + end end