Commiting
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AcceptFollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::FollowSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.target_account), '#accepts/follows/', object.id].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Accept'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.target_account)
|
||||
end
|
||||
end
|
||||
@@ -1,51 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ActivitySerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :published, :to, :cc
|
||||
|
||||
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
|
||||
ActivityPub::TagManager.instance.activity_uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
announce? ? 'Announce' : 'Create'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def published
|
||||
object.created_at.iso8601
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.to(object)
|
||||
end
|
||||
|
||||
def cc
|
||||
ActivityPub::TagManager.instance.cc(object)
|
||||
end
|
||||
|
||||
def proper_uri
|
||||
ActivityPub::TagManager.instance.uri_for(object.proper)
|
||||
end
|
||||
|
||||
def atom_uri
|
||||
OStatus::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def announce?
|
||||
object.reblog?
|
||||
end
|
||||
|
||||
def serialize_object?
|
||||
return true unless announce?
|
||||
# Serialize private self-reposts of local gabs
|
||||
object.account == object.proper.account && object.proper.private_visibility? && object.local?
|
||||
end
|
||||
end
|
||||
@@ -1,200 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
# Conditionally serialize Gab image for gab:// URLs
|
||||
def self.serializer_for(object, options)
|
||||
gab_image = object.is_a?(String) and object.start_with?('gab://')
|
||||
if gab_image and options[:serializer] == ActivityPub::ImageSerializer
|
||||
return ActivityPub::GabImageSerializer
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
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,
|
||||
:url, :manually_approves_followers
|
||||
|
||||
has_one :public_key, serializer: ActivityPub::PublicKeySerializer
|
||||
|
||||
has_many :virtual_tags, key: :tag
|
||||
has_many :virtual_attachments, key: :attachment
|
||||
|
||||
attribute :moved_to, if: :moved?
|
||||
attribute :also_known_as, if: :also_known_as?
|
||||
|
||||
class EndpointsSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :shared_inbox
|
||||
|
||||
def shared_inbox
|
||||
inbox_url
|
||||
end
|
||||
end
|
||||
|
||||
has_one :endpoints, serializer: EndpointsSerializer
|
||||
|
||||
has_one :icon, serializer: ActivityPub::ImageSerializer, if: :avatar_exists?
|
||||
has_one :image, serializer: ActivityPub::ImageSerializer, if: :header_exists?
|
||||
|
||||
delegate :moved?, to: :object
|
||||
|
||||
def id
|
||||
account_url(object)
|
||||
end
|
||||
|
||||
def type
|
||||
object.bot? ? 'Service' : 'Person'
|
||||
end
|
||||
|
||||
def following
|
||||
account_following_index_url(object)
|
||||
end
|
||||
|
||||
def followers
|
||||
account_followers_url(object)
|
||||
end
|
||||
|
||||
def inbox
|
||||
account_inbox_url(object)
|
||||
end
|
||||
|
||||
def outbox
|
||||
account_outbox_url(object)
|
||||
end
|
||||
|
||||
def featured
|
||||
account_collection_url(object, :featured)
|
||||
end
|
||||
|
||||
def endpoints
|
||||
object
|
||||
end
|
||||
|
||||
def preferred_username
|
||||
object.username
|
||||
end
|
||||
|
||||
def name
|
||||
object.display_name
|
||||
end
|
||||
|
||||
def summary
|
||||
Formatter.instance.simplified_format(object)
|
||||
end
|
||||
|
||||
def icon
|
||||
return object.avatar if object.avatar?
|
||||
return object.avatar_remote_url if is_gab_avatar?
|
||||
end
|
||||
|
||||
def image
|
||||
return object.header if object.header?
|
||||
return object.header_remote_url if is_gab_header?
|
||||
end
|
||||
|
||||
def public_key
|
||||
object
|
||||
end
|
||||
|
||||
def url
|
||||
short_account_url(object)
|
||||
end
|
||||
|
||||
def avatar_exists?
|
||||
object.avatar? or is_gab_avatar?
|
||||
end
|
||||
|
||||
def header_exists?
|
||||
object.header? or is_gab_header?
|
||||
end
|
||||
|
||||
def is_gab_avatar?
|
||||
object.avatar_remote_url&.start_with?('gab://') or false
|
||||
end
|
||||
|
||||
def is_gab_header?
|
||||
object.header_remote_url&.start_with?('gab://') or false
|
||||
end
|
||||
|
||||
def manually_approves_followers
|
||||
object.locked
|
||||
end
|
||||
|
||||
def virtual_tags
|
||||
object.emojis + object.tags
|
||||
end
|
||||
|
||||
def virtual_attachments
|
||||
object.fields + object.identity_proofs.active
|
||||
end
|
||||
|
||||
def moved_to
|
||||
ActivityPub::TagManager.instance.uri_for(object.moved_to_account)
|
||||
end
|
||||
|
||||
def also_known_as?
|
||||
!object.also_known_as.empty?
|
||||
end
|
||||
|
||||
class CustomEmojiSerializer < ActivityPub::EmojiSerializer
|
||||
end
|
||||
|
||||
class TagSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :href, :name
|
||||
|
||||
def type
|
||||
'Hashtag'
|
||||
end
|
||||
|
||||
def href
|
||||
explore_hashtag_url(object)
|
||||
end
|
||||
|
||||
def name
|
||||
"##{object.name}"
|
||||
end
|
||||
end
|
||||
|
||||
class Account::FieldSerializer < ActivityPub::Serializer
|
||||
attributes :type, :name, :value
|
||||
|
||||
def type
|
||||
'PropertyValue'
|
||||
end
|
||||
|
||||
def value
|
||||
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,24 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::AddSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
attribute :proper_object, key: :object
|
||||
|
||||
def type
|
||||
'Add'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def proper_object
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def target
|
||||
account_collection_url(object.account, :featured)
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::BlockSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object) || [ActivityPub::TagManager.instance.uri_for(object.account), '#blocks/', object.id].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Block'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def virtual_object
|
||||
ActivityPub::TagManager.instance.uri_for(object.target_account)
|
||||
end
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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
|
||||
|
||||
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? }
|
||||
attribute :part_of, if: -> { object.part_of.present? }
|
||||
|
||||
has_one :first, if: -> { object.first.present? }
|
||||
has_one :last, if: -> { object.last.present? }
|
||||
has_many :items, key: :items, if: -> { (!object.items.nil? || page?) && !ordered? }
|
||||
has_many :items, key: :ordered_items, if: -> { (!object.items.nil? || page?) && ordered? }
|
||||
|
||||
def type
|
||||
if page?
|
||||
ordered? ? 'OrderedCollectionPage' : 'CollectionPage'
|
||||
else
|
||||
ordered? ? 'OrderedCollection' : 'Collection'
|
||||
end
|
||||
end
|
||||
|
||||
def total_items
|
||||
object.size
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ordered?
|
||||
object.type == :ordered
|
||||
end
|
||||
|
||||
def page?
|
||||
object.part_of.present? || object.page.present?
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::DeleteActorSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object), '#delete'].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Delete'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def virtual_object
|
||||
actor
|
||||
end
|
||||
|
||||
def to
|
||||
[ActivityPub::TagManager::COLLECTIONS[:public]]
|
||||
end
|
||||
end
|
||||
@@ -1,41 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::DeleteSerializer < ActivityPub::Serializer
|
||||
class TombstoneSerializer < ActivityPub::Serializer
|
||||
context_extensions :atom_uri
|
||||
|
||||
attributes :id, :type, :atom_uri
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'Tombstone'
|
||||
end
|
||||
|
||||
def atom_uri
|
||||
OStatus::TagManager.instance.uri_for(object)
|
||||
end
|
||||
end
|
||||
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: TombstoneSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object), '#delete'].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Delete'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def to
|
||||
[ActivityPub::TagManager::COLLECTIONS[:public]]
|
||||
end
|
||||
end
|
||||
@@ -1,31 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::EmojiSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
context_extensions :emoji
|
||||
|
||||
attributes :id, :type, :name, :updated
|
||||
|
||||
has_one :icon, serializer: ActivityPub::ImageSerializer
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'Emoji'
|
||||
end
|
||||
|
||||
def icon
|
||||
object.image
|
||||
end
|
||||
|
||||
def updated
|
||||
object.updated_at.iso8601
|
||||
end
|
||||
|
||||
def name
|
||||
":#{object.shortcode}:"
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::FlagSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :content
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'Flag'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(instance_options[:account] || object.account)
|
||||
end
|
||||
|
||||
def virtual_object
|
||||
[ActivityPub::TagManager.instance.uri_for(object.target_account)] + object.statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s) }
|
||||
end
|
||||
|
||||
def content
|
||||
object.comment
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::FollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object) || [ActivityPub::TagManager.instance.uri_for(object.account), '#follows/', object.id].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Follow'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def virtual_object
|
||||
ActivityPub::TagManager.instance.uri_for(object.target_account)
|
||||
end
|
||||
end
|
||||
@@ -1,11 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::GabImageSerializer < ActivityPub::ImageSerializer
|
||||
def url
|
||||
object
|
||||
.sub('gab://avatar/', 'https://gab.com/media/user/')
|
||||
.sub('gab://header/', 'https://gab.com/media/user/')
|
||||
end
|
||||
|
||||
def media_type; end
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ImageSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
context_extensions :focal_point
|
||||
|
||||
attributes :type, :media_type, :url
|
||||
attribute :focal_point, if: :focal_point?
|
||||
|
||||
def type
|
||||
'Image'
|
||||
end
|
||||
|
||||
def url
|
||||
full_asset_url(object.url(:original))
|
||||
end
|
||||
|
||||
def media_type
|
||||
object.content_type
|
||||
end
|
||||
|
||||
def focal_point?
|
||||
object.respond_to?(:meta) && object.meta.is_a?(Hash) && object.meta['focus'].is_a?(Hash)
|
||||
end
|
||||
|
||||
def focal_point
|
||||
[object.meta['focus']['x'], object.meta['focus']['y']]
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::LikeSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
attribute :virtual_object, key: :object
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.account), '#likes/', object.id].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Like'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def virtual_object
|
||||
ActivityPub::TagManager.instance.uri_for(object.status)
|
||||
end
|
||||
end
|
||||
@@ -1,250 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
||||
context_extensions :atom_uri, :conversation, :sensitive,
|
||||
:hashtag, :emoji, :focal_point, :blurhash
|
||||
|
||||
attributes :id, :type, :summary,
|
||||
:in_reply_to, :published, :url,
|
||||
:attributed_to, :to, :cc, :sensitive,
|
||||
:atom_uri, :in_reply_to_atom_uri,
|
||||
:conversation
|
||||
|
||||
attribute :content
|
||||
attribute :content_map, if: :language?
|
||||
|
||||
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
|
||||
object.preloadable_poll ? 'Question' : 'Note'
|
||||
end
|
||||
|
||||
def summary
|
||||
object.spoiler_text.presence
|
||||
end
|
||||
|
||||
def content
|
||||
Formatter.instance.format(object)
|
||||
end
|
||||
|
||||
def content_map
|
||||
{ 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
|
||||
|
||||
def in_reply_to
|
||||
return unless object.reply? && !object.thread.nil?
|
||||
|
||||
if object.thread.uri.nil? || object.thread.uri.start_with?('http')
|
||||
ActivityPub::TagManager.instance.uri_for(object.thread)
|
||||
else
|
||||
object.thread.url
|
||||
end
|
||||
end
|
||||
|
||||
def published
|
||||
object.created_at.iso8601
|
||||
end
|
||||
|
||||
def url
|
||||
ActivityPub::TagManager.instance.url_for(object)
|
||||
end
|
||||
|
||||
def attributed_to
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def to
|
||||
ActivityPub::TagManager.instance.to(object)
|
||||
end
|
||||
|
||||
def cc
|
||||
ActivityPub::TagManager.instance.cc(object)
|
||||
end
|
||||
|
||||
def virtual_tags
|
||||
object.active_mentions.to_a.sort_by(&:id) + object.tags + object.emojis
|
||||
end
|
||||
|
||||
def atom_uri
|
||||
return unless object.local?
|
||||
|
||||
OStatus::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def in_reply_to_atom_uri
|
||||
return unless object.reply? && !object.thread.nil?
|
||||
|
||||
OStatus::TagManager.instance.uri_for(object.thread)
|
||||
end
|
||||
|
||||
def conversation
|
||||
return if object.conversation.nil?
|
||||
|
||||
if object.conversation.uri?
|
||||
object.conversation.uri
|
||||
else
|
||||
OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
|
||||
end
|
||||
end
|
||||
|
||||
def local?
|
||||
object.account.local?
|
||||
end
|
||||
|
||||
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, :blurhash
|
||||
attribute :focal_point, if: :focal_point?
|
||||
|
||||
def type
|
||||
'Document'
|
||||
end
|
||||
|
||||
def name
|
||||
object.description
|
||||
end
|
||||
|
||||
def media_type
|
||||
object.file_content_type
|
||||
end
|
||||
|
||||
def url
|
||||
object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url
|
||||
end
|
||||
|
||||
def focal_point?
|
||||
object.file.meta.is_a?(Hash) && object.file.meta['focus'].is_a?(Hash)
|
||||
end
|
||||
|
||||
def focal_point
|
||||
[object.file.meta['focus']['x'], object.file.meta['focus']['y']]
|
||||
end
|
||||
end
|
||||
|
||||
class MentionSerializer < ActivityPub::Serializer
|
||||
attributes :type, :href, :name
|
||||
|
||||
def type
|
||||
'Mention'
|
||||
end
|
||||
|
||||
def href
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def name
|
||||
"@#{object.account.acct}"
|
||||
end
|
||||
end
|
||||
|
||||
class TagSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :href, :name
|
||||
|
||||
def type
|
||||
'Hashtag'
|
||||
end
|
||||
|
||||
def href
|
||||
tag_url(object)
|
||||
end
|
||||
|
||||
def name
|
||||
"##{object.name}"
|
||||
end
|
||||
end
|
||||
|
||||
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,8 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::OutboxSerializer < ActivityPub::CollectionSerializer
|
||||
def self.serializer_for(model, options)
|
||||
return ActivityPub::ActivitySerializer if model.is_a?(Status)
|
||||
super
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::PublicKeySerializer < ActivityPub::Serializer
|
||||
context :security
|
||||
|
||||
attributes :id, :owner, :public_key_pem
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object), '#main-key'].join
|
||||
end
|
||||
|
||||
def owner
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def public_key_pem
|
||||
object.public_key
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RejectFollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::FollowSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.target_account), '#rejects/follows/', object.id].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Reject'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.target_account)
|
||||
end
|
||||
end
|
||||
@@ -1,24 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::RemoveSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :actor, :target
|
||||
attribute :proper_object, key: :object
|
||||
|
||||
def type
|
||||
'Remove'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def proper_object
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def target
|
||||
account_collection_url(object.account, :featured)
|
||||
end
|
||||
end
|
||||
@@ -1,23 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoAnnounceSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: ActivityPub::ActivitySerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.account), '#announces/', object.id, '/undo'].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Undo'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def to
|
||||
[ActivityPub::TagManager::COLLECTIONS[:public]]
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoBlockSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::BlockSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.account), '#blocks/', object.id, '/undo'].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Undo'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoFollowSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::FollowSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.account), '#follows/', object.id, '/undo'].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Undo'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UndoLikeSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor
|
||||
|
||||
has_one :object, serializer: ActivityPub::LikeSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object.account), '#likes/', object.id, '/undo'].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Undo'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
end
|
||||
@@ -1,27 +0,0 @@
|
||||
# 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,23 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::UpdateSerializer < ActivityPub::Serializer
|
||||
attributes :id, :type, :actor, :to
|
||||
|
||||
has_one :object, serializer: ActivityPub::ActorSerializer
|
||||
|
||||
def id
|
||||
[ActivityPub::TagManager.instance.uri_for(object), '#updates/', object.updated_at.to_i].join
|
||||
end
|
||||
|
||||
def type
|
||||
'Update'
|
||||
end
|
||||
|
||||
def actor
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def to
|
||||
[ActivityPub::TagManager::COLLECTIONS[:public]]
|
||||
end
|
||||
end
|
||||
@@ -1,52 +0,0 @@
|
||||
# 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
|
||||
@@ -31,7 +31,6 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||
store[:unread_count] = unread_count object.current_account
|
||||
store[:last_read_notification_id] = object.current_account.user.last_read_notification
|
||||
store[:monthly_expenses_complete] = Redis.current.get("monthly_funding_amount") || 0
|
||||
store[:favourites_count] = object.current_account.favourites.count.to_s
|
||||
store[:is_first_session] = is_first_session object.current_account
|
||||
store[:email_confirmed] = object.current_account.user.confirmed?
|
||||
store[:email] = object.current_account.user.confirmed? ? '[hidden]' : object.current_account.user.email
|
||||
@@ -65,7 +64,7 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def unread_count(account)
|
||||
last_read = account.user.last_read_notification || 0
|
||||
account.notifications.where("id > #{last_read}").count
|
||||
|
||||
@@ -4,8 +4,8 @@ class OEmbedSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
attributes :type, :version, :title, :author_name,
|
||||
:author_url, :provider_name, :provider_url,
|
||||
attributes :type, :version, :title
|
||||
:provider_name, :provider_url,
|
||||
:cache_age, :html, :width, :height
|
||||
|
||||
def type
|
||||
@@ -16,14 +16,6 @@ class OEmbedSerializer < ActiveModel::Serializer
|
||||
'1.0'
|
||||
end
|
||||
|
||||
def author_name
|
||||
object.account.display_name.presence || object.account.username
|
||||
end
|
||||
|
||||
def author_url
|
||||
short_account_url(object.account)
|
||||
end
|
||||
|
||||
def provider_name
|
||||
Rails.configuration.x.local_domain
|
||||
end
|
||||
|
||||
@@ -33,34 +33,18 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def avatar
|
||||
if object.avatar_file_name.nil? and object.avatar_remote_url and object.avatar_remote_url.start_with? "gab://avatar/"
|
||||
return object.avatar_remote_url.sub("gab://avatar/", "https://gab.com/media/user/")
|
||||
end
|
||||
|
||||
full_asset_url(object.avatar_original_url)
|
||||
end
|
||||
|
||||
def avatar_static
|
||||
if object.avatar_file_name.nil? and object.avatar_remote_url and object.avatar_remote_url.start_with? "gab://avatar/"
|
||||
return object.avatar_remote_url.sub("gab://avatar/", "https://gab.com/media/user/")
|
||||
end
|
||||
|
||||
full_asset_url(object.avatar_static_url)
|
||||
end
|
||||
|
||||
def header
|
||||
if object.header_file_name.nil? and object.header_remote_url and object.header_remote_url.start_with? "gab://header/"
|
||||
return object.header_remote_url.sub("gab://header/", "https://gab.com/media/user/")
|
||||
end
|
||||
|
||||
full_asset_url(object.header_original_url)
|
||||
end
|
||||
|
||||
def header_static
|
||||
if object.header_file_name.nil? and object.header_remote_url and object.header_remote_url.start_with? "gab://header/"
|
||||
return object.header_remote_url.sub("gab://header/", "https://gab.com/media/user/")
|
||||
end
|
||||
|
||||
full_asset_url(object.header_static_url)
|
||||
end
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
class REST::GroupSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :id, :title, :description, :description_html, :cover_image_url, :is_archived,
|
||||
:member_count, :created_at, :is_private, :is_visible, :slug, :tags, :group_category, :password,
|
||||
:has_password
|
||||
attributes :id, :title, :description, :description_html,
|
||||
:cover_image_url, :is_archived, :member_count,
|
||||
:created_at, :is_private, :is_visible, :slug,
|
||||
:tags, :group_category, :password, :has_password
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# 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
|
||||
@@ -1,63 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :uri, :title, :description, :email,
|
||||
:version, :urls, :stats, :thumbnail,
|
||||
:languages, :registrations
|
||||
|
||||
has_one :contact_account, serializer: REST::AccountSerializer
|
||||
|
||||
delegate :contact_account, to: :instance_presenter
|
||||
|
||||
def uri
|
||||
Rails.configuration.x.local_domain
|
||||
end
|
||||
|
||||
def title
|
||||
Setting::SITE_TITLE
|
||||
end
|
||||
|
||||
def description
|
||||
Setting.site_description
|
||||
end
|
||||
|
||||
def email
|
||||
Setting.site_contact_email
|
||||
end
|
||||
|
||||
def version
|
||||
GabSocial::Version.to_s
|
||||
end
|
||||
|
||||
def thumbnail
|
||||
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.png')
|
||||
end
|
||||
|
||||
def stats
|
||||
{
|
||||
user_count: instance_presenter.user_count,
|
||||
status_count: instance_presenter.status_count,
|
||||
domain_count: instance_presenter.domain_count,
|
||||
}
|
||||
end
|
||||
|
||||
def urls
|
||||
{ streaming_api: Rails.configuration.x.streaming_api_base_url }
|
||||
end
|
||||
|
||||
def languages
|
||||
[I18n.default_locale]
|
||||
end
|
||||
|
||||
def registrations
|
||||
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def instance_presenter
|
||||
@instance_presenter ||= InstancePresenter.new
|
||||
end
|
||||
end
|
||||
@@ -4,9 +4,8 @@ class REST::PreviewCardSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :id, :url, :title, :description, :type,
|
||||
:author_name, :author_url, :provider_name,
|
||||
:provider_url, :html, :width, :height,
|
||||
:image, :embed_url, :updated_at
|
||||
:provider_name, :provider_url, :html,
|
||||
:width, :height, :image, :embed_url, :updated_at
|
||||
|
||||
def image
|
||||
object.image? ? full_asset_url(object.image.url(:original)) : nil
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::RelationshipSerializer < ActiveModel::Serializer
|
||||
attributes :id, :following, :showing_reblogs, :followed_by, :blocking, :blocked_by,
|
||||
:muting, :muting_notifications, :requested, :domain_blocking,
|
||||
:endorsed
|
||||
attributes :id, :following, :showing_reblogs, :followed_by, :blocking,
|
||||
:blocked_by, :muting, :muting_notifications, :requested
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
@@ -42,12 +41,4 @@ class REST::RelationshipSerializer < ActiveModel::Serializer
|
||||
def requested
|
||||
instance_options[:relationships].requested[object.id] ? true : false
|
||||
end
|
||||
|
||||
def domain_blocking
|
||||
instance_options[:relationships].domain_blocking[object.id] || false
|
||||
end
|
||||
|
||||
def endorsed
|
||||
instance_options[:relationships].endorsed[object.id] || false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::SearchSerializer < ActiveModel::Serializer
|
||||
attributes :hashtags
|
||||
|
||||
has_many :accounts, serializer: REST::AccountSerializer
|
||||
has_many :statuses, serializer: REST::StatusSerializer
|
||||
has_many :groups, serializer: REST::GroupSerializer
|
||||
has_many :links, serializer: REST::PreviewCardSerializer
|
||||
|
||||
def hashtags
|
||||
object.hashtags.map(&:name)
|
||||
end
|
||||
end
|
||||
|
||||
0
app/serializers/rest/status_pinned_serializer.rb
Normal file
0
app/serializers/rest/status_pinned_serializer.rb
Normal file
@@ -3,15 +3,15 @@
|
||||
class REST::StatusSerializer < ActiveModel::Serializer
|
||||
attributes :id, :created_at, :revised_at, :in_reply_to_id, :in_reply_to_account_id,
|
||||
:sensitive, :spoiler_text, :visibility, :language,
|
||||
:uri, :url, :replies_count, :reblogs_count,
|
||||
:url, :replies_count, :reblogs_count,
|
||||
:favourites_count, :quote_of_id, :expires_at, :has_quote
|
||||
|
||||
attribute :favourited, if: :current_user?
|
||||
attribute :reblogged, if: :current_user?
|
||||
attribute :muted, if: :current_user?
|
||||
attribute :bookmarked, if: :current_user?
|
||||
attribute :pinned, if: :pinnable?
|
||||
attribute :pinned_by_group, if: :pinnable_by_group?
|
||||
|
||||
attribute :account_id, if: :account_id?
|
||||
attribute :group_id, if: :group_id?
|
||||
attribute :preview_card_id, if: :preview_card_id?
|
||||
|
||||
attribute :content, unless: :source_requested?
|
||||
attribute :rich_content, unless: :source_requested?
|
||||
@@ -20,16 +20,15 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
|
||||
belongs_to :reblog, serializer: REST::StatusSerializer
|
||||
belongs_to :quote, serializer: REST::StatusSerializer
|
||||
belongs_to :application, if: :show_application?
|
||||
belongs_to :account, serializer: REST::AccountSerializer
|
||||
belongs_to :group, serializer: REST::GroupSerializer
|
||||
belongs_to :account, serializer: REST::AccountSerializer, unless: :account_id?
|
||||
belongs_to :group, serializer: REST::GroupSerializer, unless: :group_id?
|
||||
|
||||
has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
|
||||
has_many :ordered_mentions, key: :mentions
|
||||
has_many :tags
|
||||
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
||||
|
||||
has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer
|
||||
has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer, unless: :preview_card_id?
|
||||
has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer
|
||||
|
||||
def id
|
||||
@@ -52,8 +51,28 @@ 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)
|
||||
def account_id
|
||||
instance_options[:account_id]
|
||||
end
|
||||
|
||||
def account_id?
|
||||
!instance_options[:account_id].nil?
|
||||
end
|
||||
|
||||
def group_id
|
||||
instance_options[:group_id]
|
||||
end
|
||||
|
||||
def group_id?
|
||||
!instance_options[:group_id].nil?
|
||||
end
|
||||
|
||||
def preview_card_id
|
||||
instance_options[:preview_card_id]
|
||||
end
|
||||
|
||||
def preview_card_id?
|
||||
!instance_options[:preview_card_id].nil?
|
||||
end
|
||||
|
||||
def visibility
|
||||
@@ -68,7 +87,10 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def uri
|
||||
OStatus::TagManager.instance.uri_for(object)
|
||||
"/#{object.account.username}/posts/#{object.id}"
|
||||
# uri: "https://gab.com/users/a/statuses/105075286733432550"
|
||||
# url: "https://gab.com/a/posts/105075286733432550"
|
||||
# TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def content
|
||||
@@ -111,14 +133,6 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
end
|
||||
end
|
||||
|
||||
def muted
|
||||
if instance_options && instance_options[:relationships]
|
||||
instance_options[:relationships].mutes_map[object.conversation_id] || false
|
||||
else
|
||||
current_user.account.muting_conversation?(object.conversation)
|
||||
end
|
||||
end
|
||||
|
||||
def bookmarked
|
||||
if instance_options && instance_options[:relationships]
|
||||
instance_options[:relationships].bookmarks_map[object.id] || false
|
||||
@@ -196,7 +210,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
attributes :name, :url
|
||||
|
||||
def url
|
||||
tag_url(object)
|
||||
"/tags/#{object.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
41
app/serializers/rest/status_stat_serializer.rb
Normal file
41
app/serializers/rest/status_stat_serializer.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::StatusStatSerializer < ActiveModel::Serializer
|
||||
attributes :status_id, :replies_count, :reblogs_count, :favourites_count
|
||||
|
||||
attribute :favourited, if: :current_user?
|
||||
attribute :reblogged, if: :current_user?
|
||||
|
||||
def status_id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def favourited
|
||||
if instance_options && instance_options[:relationships]
|
||||
instance_options[:relationships].favourites_map[object.id] || false
|
||||
else
|
||||
current_user.account.favourited?(object)
|
||||
end
|
||||
end
|
||||
|
||||
def favourites_count
|
||||
if instance_options && instance_options[:unfavourite]
|
||||
object.favourites_count - 1
|
||||
else
|
||||
object.favourites_count
|
||||
end
|
||||
end
|
||||
|
||||
def reblogged
|
||||
if instance_options && instance_options[:relationships]
|
||||
instance_options[:relationships].reblogs_map[object.id] || false
|
||||
else
|
||||
current_user.account.reblogged?(object)
|
||||
end
|
||||
end
|
||||
|
||||
def current_user?
|
||||
!current_user.nil?
|
||||
end
|
||||
|
||||
end
|
||||
@@ -6,6 +6,6 @@ class REST::TagSerializer < ActiveModel::Serializer
|
||||
attributes :name, :url, :history
|
||||
|
||||
def url
|
||||
tag_url(object)
|
||||
"/tags/#{object.name}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
class REST::V2::SearchSerializer < ActiveModel::Serializer
|
||||
has_many :accounts, serializer: REST::AccountSerializer
|
||||
has_many :statuses, serializer: REST::StatusSerializer
|
||||
has_many :hashtags, serializer: REST::TagSerializer
|
||||
has_many :groups, serializer: REST::GroupSerializer
|
||||
has_many :links, serializer: REST::PreviewCardSerializer
|
||||
end
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RSS::AccountSerializer
|
||||
include ActionView::Helpers::NumberHelper
|
||||
include StreamEntriesHelper
|
||||
include RoutingHelper
|
||||
|
||||
def render(account, statuses)
|
||||
builder = RSSBuilder.new
|
||||
|
||||
builder.title("#{display_name(account)} (@#{account.local_username_and_domain})")
|
||||
.description(account_description(account))
|
||||
.link(TagManager.instance.url_for(account))
|
||||
.logo(full_pack_url('media/images/logo.png'))
|
||||
.accent_color('2b90d9')
|
||||
|
||||
builder.image(full_asset_url(account.avatar.url(:original))) if account.avatar?
|
||||
builder.cover(full_asset_url(account.header.url(:original))) if account.header?
|
||||
|
||||
statuses.each do |status|
|
||||
builder.item do |item|
|
||||
item.title(status.title)
|
||||
.link(TagManager.instance.url_for(status))
|
||||
.pub_date(status.created_at)
|
||||
.description(status.spoiler_text.presence || Formatter.instance.plaintext(status).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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
builder.to_xml
|
||||
end
|
||||
|
||||
def self.render(account, statuses)
|
||||
new.render(account, statuses)
|
||||
end
|
||||
end
|
||||
@@ -1,37 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RSS::TagSerializer
|
||||
include ActionView::Helpers::NumberHelper
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
include StreamEntriesHelper
|
||||
include RoutingHelper
|
||||
|
||||
def render(tag, statuses)
|
||||
builder = RSSBuilder.new
|
||||
|
||||
builder.title("##{tag.name}")
|
||||
.description(strip_tags(I18n.t('about.about_hashtag_html', hashtag: tag.name)))
|
||||
.link(tag_url(tag))
|
||||
.logo(full_pack_url('media/images/logo.png'))
|
||||
.accent_color('2b90d9')
|
||||
|
||||
statuses.each do |status|
|
||||
builder.item do |item|
|
||||
item.title(status.title)
|
||||
.link(TagManager.instance.url_for(status))
|
||||
.pub_date(status.created_at)
|
||||
.description(status.spoiler_text.presence || Formatter.instance.plaintext(status).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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
builder.to_xml
|
||||
end
|
||||
|
||||
def self.render(tag, statuses)
|
||||
new.render(tag, statuses)
|
||||
end
|
||||
end
|
||||
@@ -1,25 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WebfingerSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :subject, :aliases, :links
|
||||
|
||||
def subject
|
||||
object.to_webfinger_s
|
||||
end
|
||||
|
||||
def aliases
|
||||
[short_account_url(object), account_url(object)]
|
||||
end
|
||||
|
||||
def links
|
||||
[
|
||||
{ rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(object) },
|
||||
{ rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(object, format: 'atom') },
|
||||
{ rel: 'self', type: 'application/activity+json', href: account_url(object) },
|
||||
{ rel: 'magic-public-key', href: "data:application/magic-public-key,#{object.magic_key}" },
|
||||
{ rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_interaction_url}?uri={uri}" },
|
||||
]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user