diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 1df399405afbbf..065ec07613c9d3 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -44,7 +44,7 @@ def context ancestors_results = @status.in_reply_to_id.nil? ? [] : @status.ancestors(ancestors_limit, current_account) descendants_results = @status.descendants(descendants_limit, current_account, descendants_depth_limit) - references_results = @status.references + references_results = @status.readable_references(current_account) loaded_ancestors = cache_collection(ancestors_results, Status) loaded_descendants = cache_collection(descendants_results, Status) loaded_references = cache_collection(references_results, Status) diff --git a/app/helpers/kmyblue_capabilities_helper.rb b/app/helpers/kmyblue_capabilities_helper.rb new file mode 100644 index 00000000000000..c1a67b26278ff9 --- /dev/null +++ b/app/helpers/kmyblue_capabilities_helper.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module KmyblueCapabilitiesHelper + def fedibird_capabilities + capabilities = [ + :enable_wide_emoji, + :kmyblue_searchability, + :searchability, + :kmyblue_markdown, + :kmyblue_reaction_deck, + :kmyblue_visibility_login, + :status_reference, + :visibility_mutual, + :visibility_limited, + :kmyblue_limited_scope, + :kmyblue_antenna, + :kmyblue_bookmark_category, + :kmyblue_quote, + :kmyblue_searchability_limited, + :kmyblue_visibility_public_unlisted, + ] + + capabilities << :profile_search unless Chewy.enabled? + if Setting.enable_emoji_reaction + capabilities << :emoji_reaction + capabilities << :enable_wide_emoji_reaction + end + + capabilities + end +end diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb index 38d0f393b79587..52b397b47d5ec3 100644 --- a/app/models/concerns/status_threading_concern.rb +++ b/app/models/concerns/status_threading_concern.rb @@ -11,6 +11,15 @@ def descendants(limit, account = nil, depth = nil) find_statuses_from_tree_path(descendant_ids(limit, depth), account, promote: true) end + def readable_references(account = nil) + statuses = references.to_a + account_ids = statuses.map(&:account_id).uniq + domains = statuses.filter_map(&:account_domain).uniq + relations = account&.relations_map(account_ids, domains) || {} + statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? } + statuses + end + def self_replies(limit) account.statuses.where(in_reply_to_id: id, visibility: [:public, :unlisted, :public_unlisted, :login]).reorder(id: :asc).limit(limit) end diff --git a/app/serializers/nodeinfo/serializer.rb b/app/serializers/nodeinfo/serializer.rb index f70cc38f0697f8..3555f0bd8ddc17 100644 --- a/app/serializers/nodeinfo/serializer.rb +++ b/app/serializers/nodeinfo/serializer.rb @@ -2,6 +2,7 @@ class NodeInfo::Serializer < ActiveModel::Serializer include RoutingHelper + include KmyblueCapabilitiesHelper attributes :version, :software, :protocols, :services, :usage, :open_registrations, :metadata @@ -38,7 +39,9 @@ def open_registrations end def metadata - {} + { + features: fedibird_capabilities, + } end private diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 9b52277bf04d1b..ed4e40523aa42b 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -8,6 +8,7 @@ class ContactSerializer < ActiveModel::Serializer end include RoutingHelper + include KmyblueCapabilitiesHelper attributes :domain, :title, :version, :source_url, :description, :usage, :thumbnail, :languages, :configuration, @@ -105,31 +106,6 @@ def registrations } end - # for third party apps - def fedibird_capabilities - capabilities = [ - :enable_wide_emoji, - :enable_wide_emoji_reaction, - :kmyblue_searchability, - :searchability, - :kmyblue_markdown, - :kmyblue_reaction_deck, - :kmyblue_visibility_login, - :status_reference, - :visibility_mutual, - :visibility_limited, - :kmyblue_limited_scope, - :kmyblue_antenna, - :kmyblue_bookmark_category, - ] - - capabilities << :profile_search unless Chewy.enabled? - capabilities << :emoji_reaction if Setting.enable_emoji_reaction - capabilities << :kmyblue_visibility_public_unlisted if Setting.enable_public_unlisted_visibility - - capabilities - end - private def registrations_enabled? diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index 64951b3db5293d..d0473f5f97ca1c 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -2,6 +2,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer include RoutingHelper + include KmyblueCapabilitiesHelper attributes :uri, :title, :short_description, :description, :email, :version, :urls, :stats, :thumbnail, @@ -114,31 +115,6 @@ def invites_enabled UserRole.everyone.can?(:invite_users) end - # for third party apps - def fedibird_capabilities - capabilities = [ - :enable_wide_emoji, - :enable_wide_emoji_reaction, - :kmyblue_searchability, - :searchability, - :kmyblue_markdown, - :kmyblue_reaction_deck, - :kmyblue_visibility_login, - :status_reference, - :visibility_mutual, - :visibility_limited, - :kmyblue_limited_scope, - :kmyblue_antenna, - :kmyblue_bookmark_category, - ] - - capabilities << :profile_search unless Chewy.enabled? - capabilities << :emoji_reaction if Setting.enable_emoji_reaction - capabilities << :kmyblue_visibility_public_unlisted if Setting.enable_public_unlisted_visibility - - capabilities - end - private def instance_presenter diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index bcb0741bd159bb..183a9ae55637df 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -9,7 +9,7 @@ def kmyblue_major end def kmyblue_minor - 0 + 1 end def kmyblue_flag @@ -25,11 +25,11 @@ def minor end def patch - 1 + 0 end def default_prerelease - 'rc1' + '' end def prerelease diff --git a/spec/serializers/nodeinfo/serializer_spec.rb b/spec/serializers/nodeinfo/serializer_spec.rb new file mode 100644 index 00000000000000..c43b0b569fb6db --- /dev/null +++ b/spec/serializers/nodeinfo/serializer_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe NodeInfo::Serializer do # rubocop:disable RSpec/FilePath + let(:serialization) do + JSON.parse( + ActiveModelSerializers::SerializableResource.new( + record, adapter: NodeInfo::Adapter, serializer: described_class, root: 'nodeinfo' + ).to_json + ) + end + let(:record) { {} } + + describe 'nodeinfo version' do + it 'returns 2.0' do + expect(serialization['version']).to eq '2.0' + end + end + + describe 'mastodon version' do + it 'contains kmyblue' do + expect(serialization['software']['version'].include?('kmyblue')).to be true + end + end + + describe 'metadata' do + it 'returns features' do + expect(serialization['metadata']['features']).to include 'emoji_reaction' + end + end +end diff --git a/spec/serializers/rest/instance_serializer_spec.rb b/spec/serializers/rest/instance_serializer_spec.rb index 15a5de18dd039a..a9a3259aa87e73 100644 --- a/spec/serializers/rest/instance_serializer_spec.rb +++ b/spec/serializers/rest/instance_serializer_spec.rb @@ -17,4 +17,10 @@ expect(serialization['usage']).to eq({ 'users' => { 'active_month' => 0 } }) end end + + describe 'fedibird_capabilities' do + it 'returns fedibird_capabilities' do + expect(serialization['fedibird_capabilities']).to include 'emoji_reaction' + end + end end