diff options
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/activitypub/note_serializer.rb | 17 | ||||
-rw-r--r-- | app/serializers/initial_state_serializer.rb | 17 | ||||
-rw-r--r-- | app/serializers/rest/account_serializer.rb | 4 | ||||
-rw-r--r-- | app/serializers/rest/instance_serializer.rb | 1 | ||||
-rw-r--r-- | app/serializers/rest/mute_serializer.rb | 15 | ||||
-rw-r--r-- | app/serializers/rest/status_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/rest/status_source_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/rest/v1/instance_serializer.rb | 16 |
8 files changed, 69 insertions, 5 deletions
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb index 27e058199..ca067ed9b 100644 --- a/app/serializers/activitypub/note_serializer.rb +++ b/app/serializers/activitypub/note_serializer.rb @@ -3,7 +3,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer include FormattingHelper - context_extensions :atom_uri, :conversation, :sensitive, :voters_count + context_extensions :atom_uri, :conversation, :sensitive, :voters_count, :direct_message attributes :id, :type, :summary, :in_reply_to, :published, :url, @@ -15,6 +15,8 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer attribute :content_map, if: :language? attribute :updated, if: :edited? + attribute :direct_message, if: :non_public? + has_many :virtual_attachments, key: :attachment has_many :virtual_tags, key: :tag @@ -29,6 +31,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer attribute :voters_count, if: :poll_and_voters_count? def id + raise Mastodon::NotPermittedError, 'Local-only statuses should not be serialized' if object.local_only? && !instance_options[:allow_local_only] ActivityPub::TagManager.instance.uri_for(object) end @@ -37,7 +40,15 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer end def summary - object.spoiler_text.presence + object.spoiler_text.presence || (instance_options[:allow_local_only] ? nil : Setting.outgoing_spoilers.presence) + end + + def direct_message + object.direct_visibility? + end + + def non_public? + !object.distributable? end def content @@ -105,7 +116,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer end def sensitive - object.account.sensitized? || object.sensitive + object.account.sensitized? || object.sensitive || (!instance_options[:allow_local_only] && Setting.outgoing_spoilers.present?) end def virtual_attachments diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 769ba653e..45ee06e12 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -5,11 +5,25 @@ class InitialStateSerializer < ActiveModel::Serializer attributes :meta, :compose, :accounts, :media_attachments, :settings, + :max_toot_chars, :poll_limits, :languages has_one :push_subscription, serializer: REST::WebPushSubscriptionSerializer has_one :role, serializer: REST::RoleSerializer + def max_toot_chars + StatusLengthValidator::MAX_CHARS + end + + def poll_limits + { + max_options: PollValidator::MAX_OPTIONS, + max_option_chars: PollValidator::MAX_OPTION_CHARS, + min_expiration: PollValidator::MIN_EXPIRATION, + max_expiration: PollValidator::MAX_EXPIRATION, + } + end + def meta store = { streaming_api_base_url: Rails.configuration.x.streaming_api_base_url, @@ -38,6 +52,7 @@ class InitialStateSerializer < ActiveModel::Serializer store[:me] = object.current_account.id.to_s store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal store[:boost_modal] = object.current_account.user.setting_boost_modal + store[:favourite_modal] = object.current_account.user.setting_favourite_modal store[:delete_modal] = object.current_account.user.setting_delete_modal store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif store[:display_media] = object.current_account.user.setting_display_media @@ -48,6 +63,8 @@ class InitialStateSerializer < ActiveModel::Serializer store[:use_blurhash] = object.current_account.user.setting_use_blurhash store[:use_pending_items] = object.current_account.user.setting_use_pending_items store[:trends] = Setting.trends && object.current_account.user.setting_trends + store[:default_content_type] = object.current_account.user.setting_default_content_type + store[:system_emoji_font] = object.current_account.user.setting_system_emoji_font store[:crop_images] = object.current_account.user.setting_crop_images else store[:auto_play_gif] = Setting.auto_play_gif diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 2845470be..e6c8fe4b2 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -90,6 +90,10 @@ class REST::AccountSerializer < ActiveModel::Serializer object.last_status_at&.to_date&.iso8601 end + def followers_count + (Setting.hide_followers_count || object.user&.setting_hide_followers_count) ? -1 : object.followers_count + end + def display_name object.suspended? ? '' : object.display_name end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index a07840f0c..41adaed80 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -56,6 +56,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer max_characters: StatusLengthValidator::MAX_CHARS, max_media_attachments: 4, characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS, + supported_mime_types: HtmlAwareFormatter::STATUS_MIME_TYPES, }, media_attachments: { diff --git a/app/serializers/rest/mute_serializer.rb b/app/serializers/rest/mute_serializer.rb new file mode 100644 index 000000000..043a2f059 --- /dev/null +++ b/app/serializers/rest/mute_serializer.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class REST::MuteSerializer < ActiveModel::Serializer + include RoutingHelper + + attributes :id, :account, :target_account, :created_at, :hide_notifications + + def account + REST::AccountSerializer.new(object.account) + end + + def target_account + REST::AccountSerializer.new(object.target_account) + end +end \ No newline at end of file diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index a422f5b25..ce08b6db8 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -13,10 +13,12 @@ class REST::StatusSerializer < ActiveModel::Serializer attribute :muted, if: :current_user? attribute :bookmarked, if: :current_user? attribute :pinned, if: :pinnable? + attribute :local_only if :local? has_many :filtered, serializer: REST::FilterResultSerializer, if: :current_user? attribute :content, unless: :source_requested? attribute :text, if: :source_requested? + attribute :content_type, if: :source_requested? belongs_to :reblog, serializer: REST::StatusSerializer belongs_to :application, if: :show_application? diff --git a/app/serializers/rest/status_source_serializer.rb b/app/serializers/rest/status_source_serializer.rb index cd3c74084..c03cbd20d 100644 --- a/app/serializers/rest/status_source_serializer.rb +++ b/app/serializers/rest/status_source_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class REST::StatusSourceSerializer < ActiveModel::Serializer - attributes :id, :text, :spoiler_text + attributes :id, :text, :spoiler_text, :content_type def id object.id.to_s diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index 99d1b2bd6..0c2101404 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -4,7 +4,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer include RoutingHelper attributes :uri, :title, :short_description, :description, :email, - :version, :urls, :stats, :thumbnail, + :version, :urls, :stats, :thumbnail, :max_toot_chars, :poll_limits, :languages, :registrations, :approval_required, :invites_enabled, :configuration @@ -36,6 +36,19 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url(:'@1x')) : full_pack_url('media/images/preview.png') end + def max_toot_chars + StatusLengthValidator::MAX_CHARS + end + + def poll_limits + { + max_options: PollValidator::MAX_OPTIONS, + max_option_chars: PollValidator::MAX_OPTION_CHARS, + min_expiration: PollValidator::MIN_EXPIRATION, + max_expiration: PollValidator::MAX_EXPIRATION, + } + end + def stats { user_count: instance_presenter.user_count, @@ -66,6 +79,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer max_characters: StatusLengthValidator::MAX_CHARS, max_media_attachments: 4, characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS, + supported_mime_types: HtmlAwareFormatter::STATUS_MIME_TYPES, }, media_attachments: { |