Merge branch 'hometown-dev' into hometown-dev-max-chars-patch
This commit is contained in:
@ -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
|
||||
|
||||
62
app/serializers/rest/announcement_serializer.rb
Normal file
62
app/serializers/rest/announcement_serializer.rb
Normal file
@ -0,0 +1,62 @@
|
||||
# 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 :statuses
|
||||
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
|
||||
|
||||
class StatusSerializer < ActiveModel::Serializer
|
||||
attributes :id, :url
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def url
|
||||
ActivityPub::TagManager.instance.url_for(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -5,7 +5,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
|
||||
attributes :uri, :title, :short_description, :description, :email,
|
||||
:version, :urls, :stats, :thumbnail, :max_toot_chars,
|
||||
:languages, :registrations, :approval_required
|
||||
:languages, :registrations, :approval_required, :invites_enabled
|
||||
|
||||
has_one :contact_account, serializer: REST::AccountSerializer
|
||||
|
||||
@ -67,6 +67,10 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
Setting.registrations_mode == 'approved'
|
||||
end
|
||||
|
||||
def invites_enabled
|
||||
Setting.min_invite_role == 'user'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def instance_presenter
|
||||
|
||||
@ -12,7 +12,9 @@ class REST::MediaAttachmentSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def url
|
||||
if object.needs_redownload?
|
||||
if object.not_processed?
|
||||
nil
|
||||
elsif object.needs_redownload?
|
||||
media_proxy_url(object.id, :original)
|
||||
else
|
||||
full_asset_url(object.file.url(:original))
|
||||
|
||||
31
app/serializers/rest/reaction_serializer.rb
Normal file
31
app/serializers/rest/reaction_serializer.rb
Normal 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
|
||||
@ -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?
|
||||
@ -97,6 +98,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
|
||||
@ -140,7 +149,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def acct
|
||||
object.account_acct
|
||||
object.account.pretty_acct
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user