Merge branch 'master' into glitch-soc/merge-upstream

Conflicts:
- Gemfile
- Gemfile.lock
- app/controllers/about_controller.rb
- app/controllers/auth/sessions_controller.rb
This commit is contained in:
Thibaut Girka
2019-09-30 12:23:57 +02:00
352 changed files with 7151 additions and 2269 deletions
@@ -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
+11 -1
View File
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class ActivityPub::NoteSerializer < ActivityPub::Serializer
context_extensions :atom_uri, :conversation, :sensitive
context_extensions :atom_uri, :conversation, :sensitive, :voters_count
attributes :id, :type, :summary,
:in_reply_to, :published, :url,
@@ -23,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
raise Mastodon::NotPermittedError, 'Local-only statuses should not be serialized' if object.local_only? && !instance_options[:allow_local_only]
ActivityPub::TagManager.instance.uri_for(object)
@@ -142,6 +144,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,6 +156,10 @@ 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
@@ -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
+41
View File
@@ -0,0 +1,41 @@
# frozen_string_literal: true
class NodeInfo::Serializer < ActiveModel::Serializer
include RoutingHelper
attributes :version, :software, :protocols, :usage
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
private
def instance_presenter
@instance_presenter ||= InstancePresenter.new
end
end
@@ -12,6 +12,7 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer
language: user.setting_default_language,
note: object.note,
fields: object.fields.map(&:to_h),
follow_requests_count: FollowRequest.where(target_account: object).limit(40).count,
}
end
end
+6 -1
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
+1 -1
View File
@@ -25,7 +25,7 @@ class RSS::AccountSerializer
.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
+1 -1
View File
@@ -23,7 +23,7 @@ class RSS::TagSerializer
.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