Skip to content

Commit

Permalink
Change: #737 tanukeyなど小規模Misskeyフォークも、対Misskey配送制限設定対象にする (#823)
Browse files Browse the repository at this point in the history
* Change: #737 tanukeyなど小規模Misskeyフォークも、対Misskey配送制限設定対象にする

* Fix test

* Add cache

* Remove caches
  • Loading branch information
kmycode authored Aug 28, 2024
1 parent ae0d35a commit a7d9fd1
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 41 deletions.
6 changes: 1 addition & 5 deletions app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions app/helpers/follow_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 1 addition & 8 deletions app/lib/account_statuses_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 6 additions & 9 deletions app/lib/activitypub/parser/status_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/status_reach_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 41 additions & 8 deletions app/models/instance_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -86,15 +110,24 @@ 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

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
9 changes: 3 additions & 6 deletions app/services/activitypub/process_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions spec/models/instance_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a7d9fd1

Please sign in to comment.