Merge tag 'v2.8.0' into instance_only_statuses
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AcceptFollowSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::AcceptFollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::FollowSerializer
|
||||
|
@ -1,10 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ActivitySerializer < ActiveModel::Serializer
|
||||
class ActivityPub::ActivitySerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :published, :to, :cc
|
||||
|
||||
has_one :proper, key: :object, serializer: ActivityPub::NoteSerializer, unless: :owned_announce?
|
||||
attribute :proper_uri, key: :object, if: :owned_announce?
|
||||
has_one :proper, key: :object, serializer: ActivityPub::NoteSerializer, if: :serialize_object?
|
||||
attribute :proper_uri, key: :object, unless: :serialize_object?
|
||||
attribute :atom_uri, if: :announce?
|
||||
|
||||
def id
|
||||
@ -43,7 +43,9 @@ class ActivityPub::ActivitySerializer < ActiveModel::Serializer
|
||||
object.reblog?
|
||||
end
|
||||
|
||||
def owned_announce?
|
||||
announce? && object.account == object.proper.account && object.proper.private_visibility?
|
||||
def serialize_object?
|
||||
return true unless announce?
|
||||
# Serialize private self-boosts of local toots
|
||||
object.account == object.proper.account && object.proper.private_visibility? && object.local?
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ActorSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
context :security
|
||||
|
||||
context_extensions :manually_approves_followers, :featured, :also_known_as,
|
||||
:moved_to, :property_value, :hashtag, :emoji, :identity_proof
|
||||
|
||||
attributes :id, :type, :following, :followers,
|
||||
:inbox, :outbox, :featured,
|
||||
:preferred_username, :name, :summary,
|
||||
@ -16,7 +21,7 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer
|
||||
attribute :moved_to, if: :moved?
|
||||
attribute :also_known_as, if: :also_known_as?
|
||||
|
||||
class EndpointsSerializer < ActiveModel::Serializer
|
||||
class EndpointsSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :shared_inbox
|
||||
@ -110,7 +115,7 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def virtual_attachments
|
||||
object.fields
|
||||
object.fields + object.identity_proofs.active
|
||||
end
|
||||
|
||||
def moved_to
|
||||
@ -124,7 +129,7 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer
|
||||
class CustomEmojiSerializer < ActivityPub::EmojiSerializer
|
||||
end
|
||||
|
||||
class TagSerializer < ActiveModel::Serializer
|
||||
class TagSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :href, :name
|
||||
@ -142,7 +147,7 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer
|
||||
end
|
||||
end
|
||||
|
||||
class Account::FieldSerializer < ActiveModel::Serializer
|
||||
class Account::FieldSerializer < ActivityPub::Serializer
|
||||
attributes :type, :name, :value
|
||||
|
||||
def type
|
||||
@ -153,4 +158,24 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer
|
||||
Formatter.instance.format_field(object.account, object.value)
|
||||
end
|
||||
end
|
||||
|
||||
class AccountIdentityProofSerializer < ActivityPub::Serializer
|
||||
attributes :type, :name, :signature_algorithm, :signature_value
|
||||
|
||||
def type
|
||||
'IdentityProof'
|
||||
end
|
||||
|
||||
def name
|
||||
object.provider_username
|
||||
end
|
||||
|
||||
def signature_algorithm
|
||||
object.provider
|
||||
end
|
||||
|
||||
def signature_value
|
||||
object.token
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AddSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::AddSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::BlockSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::BlockSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::CollectionSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::CollectionSerializer < ActivityPub::Serializer
|
||||
def self.serializer_for(model, options)
|
||||
return ActivityPub::NoteSerializer if model.class.name == 'Status'
|
||||
return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter'
|
||||
super
|
||||
end
|
||||
|
||||
attributes :id, :type
|
||||
attribute :id, if: -> { object.id.present? }
|
||||
attribute :type
|
||||
attribute :total_items, if: -> { object.size.present? }
|
||||
attribute :next, if: -> { object.next.present? }
|
||||
attribute :prev, if: -> { object.prev.present? }
|
||||
@ -37,6 +38,6 @@ class ActivityPub::CollectionSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def page?
|
||||
object.part_of.present?
|
||||
object.part_of.present? || object.page.present?
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::DeleteActorSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::DeleteActorSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::DeleteSerializer < ActiveModel::Serializer
|
||||
class TombstoneSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::DeleteSerializer < ActivityPub::Serializer
|
||||
class TombstoneSerializer < ActivityPub::Serializer
|
||||
context_extensions :atom_uri
|
||||
|
||||
attributes :id, :type, :atom_uri
|
||||
|
||||
def id
|
||||
|
@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::EmojiSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::EmojiSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
context_extensions :emoji
|
||||
|
||||
attributes :id, :type, :name, :updated
|
||||
|
||||
has_one :icon, serializer: ActivityPub::ImageSerializer
|
||||
|
@ -1,11 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::FlagSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::FlagSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :content
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
def id
|
||||
# This is nil for now
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::FollowSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::FollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ImageSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::ImageSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
context_extensions :focal_point
|
||||
|
||||
attributes :type, :media_type, :url
|
||||
attribute :focal_point, if: :focal_point?
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::LikeSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::LikeSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
||||
context_extensions :atom_uri, :conversation, :sensitive,
|
||||
:hashtag, :emoji, :focal_point
|
||||
|
||||
attributes :id, :type, :summary,
|
||||
:in_reply_to, :published, :url,
|
||||
:attributed_to, :to, :cc, :sensitive,
|
||||
@ -13,12 +16,20 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
has_many :media_attachments, key: :attachment
|
||||
has_many :virtual_tags, key: :tag
|
||||
|
||||
has_one :replies, serializer: ActivityPub::CollectionSerializer, if: :local?
|
||||
|
||||
has_many :poll_options, key: :one_of, if: :poll_and_not_multiple?
|
||||
has_many :poll_options, key: :any_of, if: :poll_and_multiple?
|
||||
|
||||
attribute :end_time, if: :poll_and_expires?
|
||||
attribute :closed, if: :poll_and_expired?
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'Note'
|
||||
object.preloadable_poll ? 'Question' : 'Note'
|
||||
end
|
||||
|
||||
def summary
|
||||
@ -33,6 +44,22 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
{ object.language => Formatter.instance.format(object) }
|
||||
end
|
||||
|
||||
def replies
|
||||
replies = object.self_replies(5).pluck(:id, :uri)
|
||||
last_id = replies.last&.first
|
||||
|
||||
ActivityPub::CollectionPresenter.new(
|
||||
type: :unordered,
|
||||
id: ActivityPub::TagManager.instance.replies_uri_for(object),
|
||||
first: ActivityPub::CollectionPresenter.new(
|
||||
type: :unordered,
|
||||
part_of: ActivityPub::TagManager.instance.replies_uri_for(object),
|
||||
items: replies.map(&:second),
|
||||
next: last_id ? ActivityPub::TagManager.instance.replies_uri_for(object, page: true, min_id: last_id) : nil
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def language?
|
||||
object.language.present?
|
||||
end
|
||||
@ -97,7 +124,33 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
object.account.local?
|
||||
end
|
||||
|
||||
class MediaAttachmentSerializer < ActiveModel::Serializer
|
||||
def poll_options
|
||||
object.preloadable_poll.loaded_options
|
||||
end
|
||||
|
||||
def poll_and_multiple?
|
||||
object.preloadable_poll&.multiple?
|
||||
end
|
||||
|
||||
def poll_and_not_multiple?
|
||||
object.preloadable_poll && !object.preloadable_poll.multiple?
|
||||
end
|
||||
|
||||
def closed
|
||||
object.preloadable_poll.expires_at.iso8601
|
||||
end
|
||||
|
||||
alias end_time closed
|
||||
|
||||
def poll_and_expires?
|
||||
object.preloadable_poll&.expires_at&.present?
|
||||
end
|
||||
|
||||
def poll_and_expired?
|
||||
object.preloadable_poll&.expired?
|
||||
end
|
||||
|
||||
class MediaAttachmentSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :media_type, :url, :name
|
||||
@ -128,7 +181,7 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
end
|
||||
end
|
||||
|
||||
class MentionSerializer < ActiveModel::Serializer
|
||||
class MentionSerializer < ActivityPub::Serializer
|
||||
attributes :type, :href, :name
|
||||
|
||||
def type
|
||||
@ -144,7 +197,7 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
end
|
||||
end
|
||||
|
||||
class TagSerializer < ActiveModel::Serializer
|
||||
class TagSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :href, :name
|
||||
@ -164,4 +217,34 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
|
||||
class CustomEmojiSerializer < ActivityPub::EmojiSerializer
|
||||
end
|
||||
|
||||
class OptionSerializer < ActivityPub::Serializer
|
||||
class RepliesSerializer < ActivityPub::Serializer
|
||||
attributes :type, :total_items
|
||||
|
||||
def type
|
||||
'Collection'
|
||||
end
|
||||
|
||||
def total_items
|
||||
object.votes_count
|
||||
end
|
||||
end
|
||||
|
||||
attributes :type, :name
|
||||
|
||||
has_one :replies, serializer: ActivityPub::NoteSerializer::OptionSerializer::RepliesSerializer
|
||||
|
||||
def type
|
||||
'Note'
|
||||
end
|
||||
|
||||
def name
|
||||
object.title
|
||||
end
|
||||
|
||||
def replies
|
||||
object
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::PublicKeySerializer < ActiveModel::Serializer
|
||||
class ActivityPub::PublicKeySerializer < ActivityPub::Serializer
|
||||
context :security
|
||||
|
||||
attributes :id, :owner, :public_key_pem
|
||||
|
||||
def id
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RejectFollowSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::RejectFollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::FollowSerializer
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RemoveSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::RemoveSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoAnnounceSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::UndoAnnounceSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: ActivityPub::ActivitySerializer
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoBlockSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::UndoBlockSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::BlockSerializer
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoFollowSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::UndoFollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::FollowSerializer
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoLikeSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::UndoLikeSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::LikeSerializer
|
||||
|
27
app/serializers/activitypub/update_poll_serializer.rb
Normal file
27
app/serializers/activitypub/update_poll_serializer.rb
Normal file
@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UpdatePollSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: ActivityPub::NoteSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object), '#updates/', object.preloadable_poll.updated_at.to_i].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Update'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.to(object)
|
||||
end
|
||||
|
||||
def cc
|
||||
ActivityPub::TagManager.instance.cc(object)
|
||||
end
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UpdateSerializer < ActiveModel::Serializer
|
||||
class ActivityPub::UpdateSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: ActivityPub::ActorSerializer
|
||||
|
52
app/serializers/activitypub/vote_serializer.rb
Normal file
52
app/serializers/activitypub/vote_serializer.rb
Normal file
@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::VoteSerializer < ActivityPub::Serializer
|
||||
class NoteSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :name, :attributed_to,
|
||||
:in_reply_to, :to
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object) || [ActivityPub::TagManager.instance.uri_for(object.account), '#votes/', object.id].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Note'
|
||||
end
|
||||
|
||||
def name
|
||||
object.poll.options[object.choice.to_i]
|
||||
end
|
||||
|
||||
def attributed_to
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def in_reply_to
|
||||
ActivityPub::TagManager.instance.uri_for(object.poll.status)
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.uri_for(object.poll.account)
|
||||
end
|
||||
end
|
||||
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: ActivityPub::VoteSerializer::NoteSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.account), '#votes/', object.id, '/activity'].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Create'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.uri_for(object.poll.account)
|
||||
end
|
||||
end
|
@ -18,7 +18,7 @@ class ManifestSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def description
|
||||
strip_tags(object.site_description.presence || I18n.t('about.about_mastodon_html'))
|
||||
strip_tags(object.site_short_description.presence || I18n.t('about.about_mastodon_html'))
|
||||
end
|
||||
|
||||
def icons
|
||||
@ -52,6 +52,14 @@ class ManifestSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def share_target
|
||||
{ url_template: 'share?title={title}&text={text}&url={url}' }
|
||||
{
|
||||
url_template: 'share?title={title}&text={text}&url={url}',
|
||||
action: 'share',
|
||||
params: {
|
||||
title: 'title',
|
||||
text: 'text',
|
||||
url: 'url',
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -43,6 +43,7 @@ class OEmbedSerializer < ActiveModel::Serializer
|
||||
style: 'max-width: 100%; border: 0',
|
||||
width: width,
|
||||
height: height,
|
||||
allowfullscreen: true,
|
||||
}
|
||||
|
||||
content_tag(:iframe, nil, attributes) + content_tag(:script, nil, src: full_asset_url('embed.js', skip_pipeline: true), async: true)
|
||||
|
17
app/serializers/rest/identity_proof_serializer.rb
Normal file
17
app/serializers/rest/identity_proof_serializer.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::IdentityProofSerializer < ActiveModel::Serializer
|
||||
attributes :provider, :provider_username, :updated_at, :proof_url, :profile_url
|
||||
|
||||
def proof_url
|
||||
object.badge.proof_url
|
||||
end
|
||||
|
||||
def profile_url
|
||||
object.badge.profile_url
|
||||
end
|
||||
|
||||
def provider
|
||||
object.provider.capitalize
|
||||
end
|
||||
end
|
@ -32,7 +32,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def thumbnail
|
||||
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('preview.jpg')
|
||||
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.jpg')
|
||||
end
|
||||
|
||||
def stats
|
||||
@ -52,7 +52,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def registrations
|
||||
Setting.open_registrations && !Rails.configuration.x.single_user_mode
|
||||
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -11,6 +11,6 @@ class REST::NotificationSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def status_type?
|
||||
[:favourite, :reblog, :mention].include?(object.type)
|
||||
[:favourite, :reblog, :mention, :poll].include?(object.type)
|
||||
end
|
||||
end
|
||||
|
31
app/serializers/rest/poll_serializer.rb
Normal file
31
app/serializers/rest/poll_serializer.rb
Normal file
@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::PollSerializer < ActiveModel::Serializer
|
||||
attributes :id, :expires_at, :expired,
|
||||
:multiple, :votes_count
|
||||
|
||||
has_many :loaded_options, key: :options
|
||||
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
||||
|
||||
attribute :voted, if: :current_user?
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def expired
|
||||
object.expired?
|
||||
end
|
||||
|
||||
def voted
|
||||
object.voted?(current_user.account)
|
||||
end
|
||||
|
||||
def current_user?
|
||||
!current_user.nil?
|
||||
end
|
||||
|
||||
class OptionSerializer < ActiveModel::Serializer
|
||||
attributes :title, :votes_count
|
||||
end
|
||||
end
|
30
app/serializers/rest/preferences_serializer.rb
Normal file
30
app/serializers/rest/preferences_serializer.rb
Normal file
@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::PreferencesSerializer < ActiveModel::Serializer
|
||||
attribute :posting_default_privacy, key: 'posting:default:visibility'
|
||||
attribute :posting_default_sensitive, key: 'posting:default:sensitive'
|
||||
attribute :posting_default_language, key: 'posting:default:language'
|
||||
|
||||
attribute :reading_default_sensitive_media, key: 'reading:expand:media'
|
||||
attribute :reading_default_sensitive_text, key: 'reading:expand:spoilers'
|
||||
|
||||
def posting_default_privacy
|
||||
object.user.setting_default_privacy
|
||||
end
|
||||
|
||||
def posting_default_sensitive
|
||||
object.user.setting_default_sensitive
|
||||
end
|
||||
|
||||
def posting_default_language
|
||||
object.user.setting_default_language.presence
|
||||
end
|
||||
|
||||
def reading_default_sensitive_media
|
||||
object.user.setting_display_media
|
||||
end
|
||||
|
||||
def reading_default_sensitive_text
|
||||
object.user.setting_expand_spoilers
|
||||
end
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::RelationshipSerializer < ActiveModel::Serializer
|
||||
attributes :id, :following, :showing_reblogs, :followed_by, :blocking,
|
||||
attributes :id, :following, :showing_reblogs, :followed_by, :blocking, :blocked_by,
|
||||
:muting, :muting_notifications, :requested, :domain_blocking,
|
||||
:endorsed
|
||||
|
||||
@ -27,6 +27,10 @@ class REST::RelationshipSerializer < ActiveModel::Serializer
|
||||
instance_options[:relationships].blocking[object.id] || false
|
||||
end
|
||||
|
||||
def blocked_by
|
||||
instance_options[:relationships].blocked_by[object.id] || false
|
||||
end
|
||||
|
||||
def muting
|
||||
instance_options[:relationships].muting[object.id] ? true : false
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
attribute :pinned, if: :pinnable?
|
||||
|
||||
belongs_to :reblog, serializer: REST::StatusSerializer
|
||||
belongs_to :application
|
||||
belongs_to :application, if: :show_application?
|
||||
belongs_to :account, serializer: REST::AccountSerializer
|
||||
|
||||
has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
|
||||
@ -21,6 +21,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
||||
|
||||
has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer
|
||||
has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
@ -38,6 +39,10 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
!current_user.nil?
|
||||
end
|
||||
|
||||
def show_application?
|
||||
object.account.user_shows_application? || (current_user? && current_user.account_id == object.account_id)
|
||||
end
|
||||
|
||||
def visibility
|
||||
# This visibility is masked behind "private"
|
||||
# to avoid API changes because there are no
|
||||
|
@ -11,7 +11,7 @@ class RSS::AccountSerializer
|
||||
builder.title("#{display_name(account)} (@#{account.local_username_and_domain})")
|
||||
.description(account_description(account))
|
||||
.link(TagManager.instance.url_for(account))
|
||||
.logo(full_asset_url(asset_pack_path('logo.svg')))
|
||||
.logo(full_pack_url('media/images/logo.svg'))
|
||||
.accent_color('2b90d9')
|
||||
|
||||
builder.image(full_asset_url(account.avatar.url(:original))) if account.avatar?
|
||||
@ -22,7 +22,7 @@ class RSS::AccountSerializer
|
||||
item.title(status.title)
|
||||
.link(TagManager.instance.url_for(status))
|
||||
.pub_date(status.created_at)
|
||||
.description(status.spoiler_text.presence || Formatter.instance.format(status).to_str)
|
||||
.description(status.spoiler_text.presence || Formatter.instance.format(status, inline_poll_options: true).to_str)
|
||||
|
||||
status.media_attachments.each do |media|
|
||||
item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, length: media.file.size)
|
||||
|
@ -12,7 +12,7 @@ class RSS::TagSerializer
|
||||
builder.title("##{tag.name}")
|
||||
.description(strip_tags(I18n.t('about.about_hashtag_html', hashtag: tag.name)))
|
||||
.link(tag_url(tag))
|
||||
.logo(full_asset_url(asset_pack_path('logo.svg')))
|
||||
.logo(full_pack_url('media/images/logo.svg'))
|
||||
.accent_color('2b90d9')
|
||||
|
||||
statuses.each do |status|
|
||||
|
Reference in New Issue
Block a user