Refactor: インスタンスで利用可能な機能を検出する処理 (#721)
This commit is contained in:
parent
3af1b90795
commit
389ae9d339
2 changed files with 24 additions and 7 deletions
|
@ -77,15 +77,18 @@ class InstanceInfo < ApplicationRecord
|
||||||
|
|
||||||
def feature_available?(info, softwares, feature_name)
|
def feature_available?(info, softwares, feature_name)
|
||||||
return false if info.nil?
|
return false if info.nil?
|
||||||
return true if softwares.include?(info['software'])
|
|
||||||
|
|
||||||
return false unless info.data.is_a?(Hash)
|
softwares.include?(software_name(info)) || metadata_features(info)&.include?(feature_name) || false
|
||||||
return false unless info.data['metadata'].is_a?(Hash)
|
end
|
||||||
|
|
||||||
features = info.data.dig('metadata', 'features')
|
def metadata_features(info)
|
||||||
return false unless features.is_a?(Array)
|
return nil unless info.data.is_a?(Hash) && info.data['metadata'].is_a?(Hash) && info.data['metadata']['features'].is_a?(Array)
|
||||||
|
|
||||||
features.include?(feature_name)
|
info.data['metadata']['features']
|
||||||
|
end
|
||||||
|
|
||||||
|
def software_name(info)
|
||||||
|
info.software
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe InstanceInfo do
|
RSpec.describe InstanceInfo do
|
||||||
describe '.available_features' do
|
describe '.available_features#emoji_reaction' do
|
||||||
subject { described_class.available_features('example.com')[:emoji_reaction] }
|
subject { described_class.available_features('example.com')[:emoji_reaction] }
|
||||||
|
|
||||||
it 'availables if local account' do
|
it 'availables if local account' do
|
||||||
|
@ -45,4 +45,18 @@ RSpec.describe InstanceInfo do
|
||||||
expect(subject).to be false
|
expect(subject).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.available_features#circle' do
|
||||||
|
subject { described_class.available_features('example.com')[:circle] }
|
||||||
|
|
||||||
|
it 'does not available if misskey server' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'misskey')
|
||||||
|
expect(subject).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'availables if misskey server with features' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'misskey', data: { metadata: { features: ['circle'] } })
|
||||||
|
expect(subject).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue