Merge tag 'v3.0.0' into hometown-dev

This commit is contained in:
Darius Kazemi
2019-10-08 13:24:20 -07:00
1012 changed files with 31176 additions and 15165 deletions

View File

@ -4,6 +4,7 @@ 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?

View File

@ -6,12 +6,14 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
context :security
context_extensions :manually_approves_followers, :featured, :also_known_as,
:moved_to, :property_value, :hashtag, :emoji, :identity_proof
:moved_to, :property_value, :identity_proof,
:discoverable
attributes :id, :type, :following, :followers,
:inbox, :outbox, :featured,
:preferred_username, :name, :summary,
:url, :manually_approves_followers
:url, :manually_approves_followers,
:discoverable
has_one :public_key, serializer: ActivityPub::PublicKeySerializer
@ -39,11 +41,17 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
delegate :moved?, to: :object
def id
account_url(object)
object.instance_actor? ? instance_actor_url : account_url(object)
end
def type
object.bot? ? 'Service' : 'Person'
if object.instance_actor?
'Application'
elsif object.bot?
'Service'
else
'Person'
end
end
def following
@ -55,7 +63,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def inbox
account_inbox_url(object)
object.instance_actor? ? instance_actor_inbox_url : account_inbox_url(object)
end
def outbox
@ -95,7 +103,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def url
short_account_url(object)
object.instance_actor? ? about_more_url(instance_actor: true) : short_account_url(object)
end
def avatar_exists?
@ -130,6 +138,8 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
class TagSerializer < ActivityPub::Serializer
context_extensions :hashtag
include RoutingHelper
attributes :type, :href, :name

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
class ActivityPub::MoveSerializer < ActivityPub::Serializer
attributes :id, :type, :target, :actor
attribute :virtual_object, key: :object
def id
[ActivityPub::TagManager.instance.uri_for(object.account), '#moves/', object.id].join
end
def type
'Move'
end
def target
ActivityPub::TagManager.instance.uri_for(object.target_account)
end
def virtual_object
ActivityPub::TagManager.instance.uri_for(object.account)
end
def actor
ActivityPub::TagManager.instance.uri_for(object.account)
end
end

View File

@ -1,8 +1,7 @@
# frozen_string_literal: true
class ActivityPub::NoteSerializer < ActivityPub::Serializer
context_extensions :atom_uri, :conversation, :sensitive,
:hashtag, :emoji, :focal_point, :blurhash
context_extensions :atom_uri, :conversation, :sensitive, :voters_count
attributes :id, :type, :summary,
:in_reply_to, :published, :url,
@ -24,6 +23,8 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
attribute :end_time, if: :poll_and_expires?
attribute :closed, if: :poll_and_expired?
attribute :voters_count, if: :poll_and_voters_count?
def id
ActivityPub::TagManager.instance.uri_for(object)
end
@ -55,7 +56,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
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
next: last_id ? ActivityPub::TagManager.instance.replies_uri_for(object, page: true, min_id: last_id) : ActivityPub::TagManager.instance.replies_uri_for(object, page: true, only_other_accounts: true)
)
)
end
@ -142,6 +143,10 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
alias end_time closed
def voters_count
object.preloadable_poll.voters_count
end
def poll_and_expires?
object.preloadable_poll&.expires_at&.present?
end
@ -150,7 +155,13 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
object.preloadable_poll&.expired?
end
def poll_and_voters_count?
object.preloadable_poll&.voters_count
end
class MediaAttachmentSerializer < ActivityPub::Serializer
context_extensions :blurhash, :focal_point
include RoutingHelper
attributes :type, :media_type, :url, :name, :blurhash
@ -198,6 +209,8 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
end
class TagSerializer < ActivityPub::Serializer
context_extensions :hashtag
include RoutingHelper
attributes :type, :href, :name

View File

@ -12,6 +12,7 @@ class InitialStateSerializer < ActiveModel::Serializer
access_token: object.token,
locale: I18n.locale,
domain: Rails.configuration.x.local_domain,
title: instance_presenter.site_title,
admin: object.admin&.id&.to_s,
search_enabled: Chewy.enabled?,
repository: Mastodon::Version.repository,
@ -20,19 +21,28 @@ class InitialStateSerializer < ActiveModel::Serializer
invites_enabled: Setting.min_invite_role == 'user',
mascot: instance_presenter.mascot&.file&.url,
profile_directory: Setting.profile_directory,
trends: Setting.trends,
}
if object.current_account
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
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
store[:display_media] = object.current_account.user.setting_display_media
store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
store[:advanced_layout] = object.current_account.user.setting_advanced_layout
store[:is_staff] = object.current_account.user.staff?
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
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
store[:display_media] = object.current_account.user.setting_display_media
store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
store[:advanced_layout] = object.current_account.user.setting_advanced_layout
store[:use_blurhash] = object.current_account.user.setting_use_blurhash
store[:use_pending_items] = object.current_account.user.setting_use_pending_items
store[:is_staff] = object.current_account.user.staff?
store[:trends] = Setting.trends && object.current_account.user.setting_trends
else
store[:auto_play_gif] = Setting.auto_play_gif
store[:display_media] = Setting.display_media
store[:reduce_motion] = Setting.reduce_motion
store[:use_blurhash] = Setting.use_blurhash
end
store

View File

@ -55,6 +55,8 @@ class ManifestSerializer < ActiveModel::Serializer
{
url_template: 'share?title={title}&text={text}&url={url}',
action: 'share',
method: 'GET',
enctype: 'application/x-www-form-urlencoded',
params: {
title: 'title',
text: 'text',

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
class NodeInfo::DiscoverySerializer < ActiveModel::Serializer
include RoutingHelper
attribute :links
def links
[{ rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', href: nodeinfo_schema_url }]
end
end

View File

@ -0,0 +1,45 @@
# frozen_string_literal: true
class NodeInfo::Serializer < ActiveModel::Serializer
include RoutingHelper
attributes :version, :software, :protocols, :usage, :open_registrations
def version
'2.0'
end
def software
{ name: 'mastodon', version: Mastodon::Version.to_s }
end
def services
{ outbound: [], inbound: [] }
end
def protocols
%w(activitypub)
end
def usage
{
users: {
total: instance_presenter.user_count,
active_month: instance_presenter.active_user_count(4),
active_halfyear: instance_presenter.active_user_count(24),
},
local_posts: instance_presenter.status_count,
}
end
def open_registrations
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
end
private
def instance_presenter
@instance_presenter ||= InstancePresenter.new
end
end

View File

@ -5,7 +5,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
attributes :id, :username, :acct, :display_name, :locked, :bot, :created_at,
:note, :url, :avatar, :avatar_static, :header, :header_static,
:followers_count, :following_count, :statuses_count
:followers_count, :following_count, :statuses_count, :last_status_at
has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
has_many :emojis, serializer: REST::CustomEmojiSerializer
@ -29,7 +29,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
end
def url
TagManager.instance.url_for(object)
ActivityPub::TagManager.instance.url_for(object)
end
def avatar

View File

@ -13,6 +13,7 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer
federation: user.setting_default_federation,
note: object.note,
fields: object.fields.map(&:to_h),
follow_requests_count: FollowRequest.where(target_account: object).limit(40).count,
}
end
end

View File

@ -5,6 +5,8 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer
attributes :shortcode, :url, :static_url, :visible_in_picker
attribute :category, if: :category_loaded?
def url
full_asset_url(object.image.url)
end
@ -12,4 +14,12 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer
def static_url
full_asset_url(object.image.url(:static))
end
def category
object.category.name
end
def category_loaded?
object.association(:category).loaded? && object.category.present?
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class REST::FeaturedTagSerializer < ActiveModel::Serializer
attributes :id, :name, :statuses_count, :last_status_at
def id
object.id.to_s
end
end

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class REST::MarkerSerializer < ActiveModel::Serializer
attributes :last_read_id, :version, :updated_at
def last_read_id
object.last_read_id.to_s
end
def version
object.lock_version
end
end

View File

@ -2,12 +2,13 @@
class REST::PollSerializer < ActiveModel::Serializer
attributes :id, :expires_at, :expired,
:multiple, :votes_count
:multiple, :votes_count, :voters_count
has_many :loaded_options, key: :options
has_many :emojis, serializer: REST::CustomEmojiSerializer
attribute :voted, if: :current_user?
attribute :own_votes, if: :current_user?
def id
object.id.to_s
@ -21,6 +22,10 @@ class REST::PollSerializer < ActiveModel::Serializer
object.voted?(current_user.account)
end
def own_votes
object.own_votes(current_user.account)
end
def current_user?
!current_user.nil?
end

View File

@ -1,12 +1,7 @@
# frozen_string_literal: true
class REST::SearchSerializer < ActiveModel::Serializer
attributes :hashtags
has_many :accounts, serializer: REST::AccountSerializer
has_many :statuses, serializer: REST::StatusSerializer
def hashtags
object.hashtags.map(&:name)
end
has_many :hashtags, serializer: REST::TagSerializer
end

View File

@ -58,7 +58,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
def uri
OStatus::TagManager.instance.uri_for(object)
ActivityPub::TagManager.instance.uri_for(object)
end
def activity_pub_type
@ -70,7 +70,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
def url
TagManager.instance.url_for(object)
ActivityPub::TagManager.instance.url_for(object)
end
def favourited
@ -136,7 +136,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
def url
TagManager.instance.url_for(object.account)
ActivityPub::TagManager.instance.url_for(object.account)
end
def acct

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
class REST::V2::SearchSerializer < ActiveModel::Serializer
has_many :accounts, serializer: REST::AccountSerializer
has_many :statuses, serializer: REST::StatusSerializer
has_many :hashtags, serializer: REST::TagSerializer
end

View File

@ -2,15 +2,15 @@
class RSS::AccountSerializer
include ActionView::Helpers::NumberHelper
include StreamEntriesHelper
include StatusesHelper
include RoutingHelper
def render(account, statuses)
def render(account, statuses, tag)
builder = RSSBuilder.new
builder.title("#{display_name(account)} (@#{account.local_username_and_domain})")
.description(account_description(account))
.link(TagManager.instance.url_for(account))
.link(tag.present? ? short_account_tag_url(account, tag) : short_account_url(account))
.logo(full_pack_url('media/images/logo.svg'))
.accent_color('2b90d9')
@ -20,12 +20,12 @@ class RSS::AccountSerializer
statuses.each do |status|
builder.item do |item|
item.title(status.title)
.link(TagManager.instance.url_for(status))
.link(ActivityPub::TagManager.instance.url_for(status))
.pub_date(status.created_at)
.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)
item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size)
end
end
end
@ -33,7 +33,7 @@ class RSS::AccountSerializer
builder.to_xml
end
def self.render(account, statuses)
new.render(account, statuses)
def self.render(account, statuses, tag)
new.render(account, statuses, tag)
end
end

View File

@ -3,7 +3,7 @@
class RSS::TagSerializer
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::SanitizeHelper
include StreamEntriesHelper
include StatusesHelper
include RoutingHelper
def render(tag, statuses)
@ -18,12 +18,12 @@ class RSS::TagSerializer
statuses.each do |status|
builder.item do |item|
item.title(status.title)
.link(TagManager.instance.url_for(status))
.link(ActivityPub::TagManager.instance.url_for(status))
.pub_date(status.created_at)
.description(status.spoiler_text.presence || Formatter.instance.format(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)
item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size)
end
end
end

View File

@ -10,17 +10,25 @@ class WebfingerSerializer < ActiveModel::Serializer
end
def aliases
[short_account_url(object), account_url(object)]
if object.instance_actor?
[instance_actor_url]
else
[short_account_url(object), account_url(object)]
end
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: 'salmon', href: api_salmon_url(object.id) },
{ 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}" },
]
if object.instance_actor?
[
{ rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: about_more_url(instance_actor: true) },
{ rel: 'self', type: 'application/activity+json', href: instance_actor_url },
]
else
[
{ rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(object) },
{ rel: 'self', type: 'application/activity+json', href: account_url(object) },
{ rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_interaction_url}?uri={uri}" },
]
end
end
end