Commiting
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user