Merge tag 'v3.1.1' into instance_only_statuses

This commit is contained in:
Renato "Lond" Cerqueira
2020-02-21 14:21:59 +01:00
1431 changed files with 34462 additions and 10030 deletions

View File

@ -49,6 +49,8 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
'Application'
elsif object.bot?
'Service'
elsif object.group?
'Group'
else
'Person'
end

View File

@ -38,11 +38,13 @@ class InitialStateSerializer < ActiveModel::Serializer
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
store[:crop_images] = object.current_account.user.setting_crop_images
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
store[:crop_images] = Setting.crop_images
end
store

View File

@ -3,7 +3,7 @@
class REST::AccountSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :id, :username, :acct, :display_name, :locked, :bot, :created_at,
attributes :id, :username, :acct, :display_name, :locked, :bot, :discoverable, :group, :created_at,
:note, :url, :avatar, :avatar_static, :header, :header_static,
:followers_count, :following_count, :statuses_count, :last_status_at
@ -24,6 +24,10 @@ class REST::AccountSerializer < ActiveModel::Serializer
object.id.to_s
end
def acct
object.pretty_acct
end
def note
Formatter.instance.simplified_format(object)
end
@ -51,4 +55,8 @@ class REST::AccountSerializer < ActiveModel::Serializer
def moved_and_not_nested?
object.moved? && object.moved_to_account.moved_to_account_id.nil?
end
def last_status_at
object.last_status_at&.to_date&.iso8601
end
end

View File

@ -0,0 +1,49 @@
# frozen_string_literal: true
class REST::AnnouncementSerializer < ActiveModel::Serializer
attributes :id, :content, :starts_at, :ends_at, :all_day,
:published_at, :updated_at
attribute :read, if: :current_user?
has_many :mentions
has_many :tags, serializer: REST::StatusSerializer::TagSerializer
has_many :emojis, serializer: REST::CustomEmojiSerializer
has_many :reactions, serializer: REST::ReactionSerializer
def current_user?
!current_user.nil?
end
def id
object.id.to_s
end
def read
object.announcement_mutes.where(account: current_user.account).exists?
end
def content
Formatter.instance.linkify(object.text)
end
def reactions
object.reactions(current_user&.account)
end
class AccountSerializer < ActiveModel::Serializer
attributes :id, :username, :url, :acct
def id
object.id.to_s
end
def url
ActivityPub::TagManager.instance.url_for(object)
end
def acct
object.pretty_acct
end
end
end

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
class REST::ReactionSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :name, :count
attribute :me, if: :current_user?
attribute :url, if: :custom_emoji?
attribute :static_url, if: :custom_emoji?
def count
object.respond_to?(:count) ? object.count : 0
end
def current_user?
!current_user.nil?
end
def custom_emoji?
object.custom_emoji.present?
end
def url
full_asset_url(object.custom_emoji.image.url)
end
def static_url
full_asset_url(object.custom_emoji.image.url(:static))
end
end

View File

@ -9,6 +9,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
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 :content, unless: :source_requested?
@ -93,6 +94,14 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
end
def bookmarked
if instance_options && instance_options[:relationships]
instance_options[:relationships].bookmarks_map[object.id] || false
else
current_user.account.bookmarked?(object)
end
end
def pinned
if instance_options && instance_options[:relationships]
instance_options[:relationships].pins_map[object.id] || false
@ -136,7 +145,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
def acct
object.account_acct
object.account.pretty_acct
end
end

View File

@ -2,7 +2,7 @@
class RSS::AccountSerializer
include ActionView::Helpers::NumberHelper
include StatusesHelper
include AccountsHelper
include RoutingHelper
def render(account, statuses, tag)

View File

@ -3,7 +3,6 @@
class RSS::TagSerializer
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::SanitizeHelper
include StatusesHelper
include RoutingHelper
def render(tag, statuses)