Merge commit 'b9f59ebcc68e9da0a7158741a1a2ef3564e1321e' into merging-upstream
This commit is contained in:
@@ -3,23 +3,38 @@
|
||||
class ActivityPub::CollectionSerializer < ActiveModel::Serializer
|
||||
def self.serializer_for(model, options)
|
||||
return ActivityPub::ActivitySerializer if model.class.name == 'Status'
|
||||
return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter'
|
||||
super
|
||||
end
|
||||
|
||||
attributes :id, :type, :total_items
|
||||
attribute :next, if: -> { object.next.present? }
|
||||
attribute :prev, if: -> { object.prev.present? }
|
||||
attribute :part_of, if: -> { object.part_of.present? }
|
||||
|
||||
has_many :items, key: :ordered_items
|
||||
has_one :first, if: -> { object.first.present? }
|
||||
has_many :items, key: :items, if: -> { (object.items.present? || page?) && !ordered? }
|
||||
has_many :items, key: :ordered_items, if: -> { (object.items.present? || page?) && ordered? }
|
||||
|
||||
def type
|
||||
case object.type
|
||||
when :ordered
|
||||
'OrderedCollection'
|
||||
if page?
|
||||
ordered? ? 'OrderedCollectionPage' : 'CollectionPage'
|
||||
else
|
||||
'Collection'
|
||||
ordered? ? 'OrderedCollection' : 'Collection'
|
||||
end
|
||||
end
|
||||
|
||||
def total_items
|
||||
object.size
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ordered?
|
||||
object.type == :ordered
|
||||
end
|
||||
|
||||
def page?
|
||||
object.part_of.present?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class ActivityPub::DeleteSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def atom_uri
|
||||
::TagManager.instance.uri_for(object)
|
||||
OStatus::TagManager.instance.uri_for(object)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -63,13 +63,13 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
def atom_uri
|
||||
return unless object.local?
|
||||
|
||||
::TagManager.instance.uri_for(object)
|
||||
OStatus::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def in_reply_to_atom_uri
|
||||
return unless object.reply? && !object.thread.nil?
|
||||
|
||||
::TagManager.instance.uri_for(object.thread)
|
||||
OStatus::TagManager.instance.uri_for(object.thread)
|
||||
end
|
||||
|
||||
def conversation
|
||||
@@ -78,7 +78,7 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
|
||||
if object.conversation.uri?
|
||||
object.conversation.uri
|
||||
else
|
||||
TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
|
||||
OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,17 +4,23 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||
attributes :meta, :compose, :accounts,
|
||||
:media_attachments, :settings, :push_subscription
|
||||
|
||||
has_many :custom_emojis, serializer: REST::CustomEmojiSerializer
|
||||
|
||||
def custom_emojis
|
||||
CustomEmoji.local
|
||||
end
|
||||
|
||||
def meta
|
||||
store = {
|
||||
streaming_api_base_url: Rails.configuration.x.streaming_api_base_url,
|
||||
access_token: object.token,
|
||||
locale: I18n.locale,
|
||||
domain: Rails.configuration.x.local_domain,
|
||||
admin: object.admin&.id,
|
||||
admin: object.admin&.id&.to_s,
|
||||
}
|
||||
|
||||
if object.current_account
|
||||
store[:me] = object.current_account.id
|
||||
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[:delete_modal] = object.current_account.user.setting_delete_modal
|
||||
@@ -28,7 +34,7 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||
store = {}
|
||||
|
||||
if object.current_account
|
||||
store[:me] = object.current_account.id
|
||||
store[:me] = object.current_account.id.to_s
|
||||
store[:default_privacy] = object.current_account.user.setting_default_privacy
|
||||
store[:default_sensitive] = object.current_account.user.setting_default_sensitive
|
||||
end
|
||||
@@ -40,12 +46,12 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||
|
||||
def accounts
|
||||
store = {}
|
||||
store[object.current_account.id] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
|
||||
store[object.admin.id] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
|
||||
store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
|
||||
store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
|
||||
store
|
||||
end
|
||||
|
||||
def media_attachments
|
||||
{ accept_content_types: MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
|
||||
{ accept_content_types: MediaAttachment::IMAGE_FILE_EXTENSIONS + MediaAttachment::VIDEO_FILE_EXTENSIONS + MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,10 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||
:note, :url, :avatar, :avatar_static, :header, :header_static,
|
||||
:followers_count, :following_count, :statuses_count
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def note
|
||||
Formatter.instance.simplified_format(object)
|
||||
end
|
||||
|
||||
@@ -4,6 +4,10 @@ class REST::ApplicationSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :website, :redirect_uri,
|
||||
:client_id, :client_secret
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def client_id
|
||||
object.uid
|
||||
end
|
||||
|
||||
11
app/serializers/rest/custom_emoji_serializer.rb
Normal file
11
app/serializers/rest/custom_emoji_serializer.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::CustomEmojiSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :shortcode, :url
|
||||
|
||||
def url
|
||||
full_asset_url(object.image.url)
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,10 @@ class REST::MediaAttachmentSerializer < ActiveModel::Serializer
|
||||
attributes :id, :type, :url, :preview_url,
|
||||
:remote_url, :text_url, :meta
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def url
|
||||
if object.needs_redownload?
|
||||
media_proxy_url(object.id, :original)
|
||||
|
||||
@@ -6,6 +6,10 @@ class REST::NotificationSerializer < ActiveModel::Serializer
|
||||
belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
|
||||
belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def status_type?
|
||||
[:favourite, :reblog, :mention].include?(object.type)
|
||||
end
|
||||
|
||||
@@ -4,6 +4,10 @@ class REST::RelationshipSerializer < ActiveModel::Serializer
|
||||
attributes :id, :following, :followed_by, :blocking,
|
||||
:muting, :requested, :domain_blocking
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def following
|
||||
instance_options[:relationships].following[object.id] || false
|
||||
end
|
||||
|
||||
@@ -2,4 +2,8 @@
|
||||
|
||||
class REST::ReportSerializer < ActiveModel::Serializer
|
||||
attributes :id, :action_taken
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,14 +17,26 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
|
||||
has_many :mentions
|
||||
has_many :tags
|
||||
has_many :emojis
|
||||
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def in_reply_to_id
|
||||
object.in_reply_to_id&.to_s
|
||||
end
|
||||
|
||||
def in_reply_to_account_id
|
||||
object.in_reply_to_account_id&.to_s
|
||||
end
|
||||
|
||||
def current_user?
|
||||
!current_user.nil?
|
||||
end
|
||||
|
||||
def uri
|
||||
TagManager.instance.uri_for(object)
|
||||
OStatus::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def content
|
||||
@@ -82,7 +94,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
attributes :id, :username, :url, :acct
|
||||
|
||||
def id
|
||||
object.account_id
|
||||
object.account_id.to_s
|
||||
end
|
||||
|
||||
def username
|
||||
@@ -107,14 +119,4 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
tag_url(object)
|
||||
end
|
||||
end
|
||||
|
||||
class CustomEmojiSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :shortcode, :url
|
||||
|
||||
def url
|
||||
full_asset_url(object.image.url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user