2017-07-07 02:02:06 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::StatusSerializer < ActiveModel::Serializer
|
|
|
|
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
|
|
|
|
:sensitive, :spoiler_text, :visibility, :language,
|
2019-05-11 04:46:43 +00:00
|
|
|
:uri, :url, :replies_count, :reblogs_count,
|
2022-03-17 14:25:16 +00:00
|
|
|
:favourites_count, :emoji_reactions_count, :emoji_reactions,
|
|
|
|
:status_reference_ids,
|
2022-08-23 05:14:23 +00:00
|
|
|
:status_references_count, :status_referred_by_count,
|
|
|
|
:searchability
|
2017-07-07 02:02:06 +00:00
|
|
|
|
|
|
|
attribute :favourited, if: :current_user?
|
|
|
|
attribute :reblogged, if: :current_user?
|
|
|
|
attribute :muted, if: :current_user?
|
2019-11-13 22:02:10 +00:00
|
|
|
attribute :bookmarked, if: :current_user?
|
2021-05-19 05:58:27 +00:00
|
|
|
attribute :emoji_reactioned, if: :current_user?
|
2017-08-24 23:41:18 +00:00
|
|
|
attribute :pinned, if: :pinnable?
|
2020-09-05 07:33:17 +00:00
|
|
|
attribute :circle_id, if: :limited_owned_parent_status?
|
2017-07-07 02:02:06 +00:00
|
|
|
|
2019-05-11 04:46:43 +00:00
|
|
|
attribute :content, unless: :source_requested?
|
|
|
|
attribute :text, if: :source_requested?
|
|
|
|
|
2022-02-09 20:47:09 +00:00
|
|
|
attribute :nyaize_content, if: :joke_applied?
|
|
|
|
|
2021-02-11 03:52:31 +00:00
|
|
|
attribute :quote_id, if: :quote?
|
2020-02-21 12:49:06 +00:00
|
|
|
|
2022-08-27 10:57:05 +00:00
|
|
|
attribute :expires_at, if: :expires?
|
|
|
|
attribute :expires_action, if: :expires?
|
2021-02-11 03:52:31 +00:00
|
|
|
attribute :visibility_ex, if: :visibility_ex?
|
2020-06-15 22:56:38 +00:00
|
|
|
|
2022-08-27 10:57:05 +00:00
|
|
|
attribute :account
|
|
|
|
attribute :reblog
|
|
|
|
|
2019-02-02 18:18:15 +00:00
|
|
|
belongs_to :application, if: :show_application?
|
2017-07-07 02:02:06 +00:00
|
|
|
|
|
|
|
has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
|
2018-03-19 19:19:35 +00:00
|
|
|
has_many :ordered_mentions, key: :mentions
|
2017-07-07 02:02:06 +00:00
|
|
|
has_many :tags
|
2017-09-22 23:57:23 +00:00
|
|
|
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
2017-07-07 02:02:06 +00:00
|
|
|
|
2018-10-28 05:35:03 +00:00
|
|
|
has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer
|
2019-03-28 03:44:59 +00:00
|
|
|
has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer
|
2018-10-28 05:35:03 +00:00
|
|
|
|
2022-08-27 10:57:05 +00:00
|
|
|
delegate :quote?, to: :object
|
|
|
|
|
Change IDs to strings rather than numbers in API JSON output (#5019)
* Fix JavaScript interface with long IDs
Somewhat predictably, the JS interface handled IDs as numbers, which in
JS are IEEE double-precision floats. This loses some precision when
working with numbers as large as those generated by the new ID scheme,
so we instead handle them here as strings. This is relatively simple,
and doesn't appear to have caused any problems, but should definitely
be tested more thoroughly than the built-in tests. Several days of use
appear to support this working properly.
BREAKING CHANGE:
The major(!) change here is that IDs are now returned as strings by the
REST endpoints, rather than as integers. In practice, relatively few
changes were required to make the existing JS UI work with this change,
but it will likely hit API clients pretty hard: it's an entirely
different type to consume. (The one API client I tested, Tusky, handles
this with no problems, however.)
Twitter ran into this issue when introducing Snowflake IDs, and decided
to instead introduce an `id_str` field in JSON responses. I have opted
to *not* do that, and instead force all IDs to 64-bit integers
represented by strings in one go. (I believe Twitter exacerbated their
problem by rolling out the changes three times: once for statuses, once
for DMs, and once for user IDs, as well as by leaving an integer ID
value in JSON. As they said, "If you’re using the `id` field with JSON
in a Javascript-related language, there is a very high likelihood that
the integers will be silently munged by Javascript interpreters. In most
cases, this will result in behavior such as being unable to load or
delete a specific direct message, because the ID you're sending to the
API is different than the actual identifier associated with the
message." [1]) However, given that this is a significant change for API
users, alternatives or a transition time may be appropriate.
1: https://blog.twitter.com/developer/en_us/a/2011/direct-messages-going-snowflake-on-sep-30-2011.html
* Additional fixes for stringified IDs in JSON
These should be the last two. These were identified using eslint to try
to identify any plain casts to JavaScript numbers. (Some such casts are
legitimate, but these were not.)
Adding the following to .eslintrc.yml will identify casts to numbers:
~~~
no-restricted-syntax:
- warn
- selector: UnaryExpression[operator='+'] > :not(Literal)
message: Avoid the use of unary +
- selector: CallExpression[callee.name='Number']
message: Casting with Number() may coerce string IDs to numbers
~~~
The remaining three casts appear legitimate: two casts to array indices,
one in a server to turn an environment variable into a number.
* Back out RelationshipsController Change
This was made to make a test a bit less flakey, but has nothing to
do with this branch.
* Change internal streaming payloads to stringified IDs as well
Per
https://github.com/tootsuite/mastodon/pull/5019#issuecomment-330736452
we need these changes to send deleted status IDs as strings, not
integers.
2017-09-20 12:53:48 +00:00
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_reply_to_id
|
2017-09-24 02:09:32 +00:00
|
|
|
object.in_reply_to_id&.to_s
|
Change IDs to strings rather than numbers in API JSON output (#5019)
* Fix JavaScript interface with long IDs
Somewhat predictably, the JS interface handled IDs as numbers, which in
JS are IEEE double-precision floats. This loses some precision when
working with numbers as large as those generated by the new ID scheme,
so we instead handle them here as strings. This is relatively simple,
and doesn't appear to have caused any problems, but should definitely
be tested more thoroughly than the built-in tests. Several days of use
appear to support this working properly.
BREAKING CHANGE:
The major(!) change here is that IDs are now returned as strings by the
REST endpoints, rather than as integers. In practice, relatively few
changes were required to make the existing JS UI work with this change,
but it will likely hit API clients pretty hard: it's an entirely
different type to consume. (The one API client I tested, Tusky, handles
this with no problems, however.)
Twitter ran into this issue when introducing Snowflake IDs, and decided
to instead introduce an `id_str` field in JSON responses. I have opted
to *not* do that, and instead force all IDs to 64-bit integers
represented by strings in one go. (I believe Twitter exacerbated their
problem by rolling out the changes three times: once for statuses, once
for DMs, and once for user IDs, as well as by leaving an integer ID
value in JSON. As they said, "If you’re using the `id` field with JSON
in a Javascript-related language, there is a very high likelihood that
the integers will be silently munged by Javascript interpreters. In most
cases, this will result in behavior such as being unable to load or
delete a specific direct message, because the ID you're sending to the
API is different than the actual identifier associated with the
message." [1]) However, given that this is a significant change for API
users, alternatives or a transition time may be appropriate.
1: https://blog.twitter.com/developer/en_us/a/2011/direct-messages-going-snowflake-on-sep-30-2011.html
* Additional fixes for stringified IDs in JSON
These should be the last two. These were identified using eslint to try
to identify any plain casts to JavaScript numbers. (Some such casts are
legitimate, but these were not.)
Adding the following to .eslintrc.yml will identify casts to numbers:
~~~
no-restricted-syntax:
- warn
- selector: UnaryExpression[operator='+'] > :not(Literal)
message: Avoid the use of unary +
- selector: CallExpression[callee.name='Number']
message: Casting with Number() may coerce string IDs to numbers
~~~
The remaining three casts appear legitimate: two casts to array indices,
one in a server to turn an environment variable into a number.
* Back out RelationshipsController Change
This was made to make a test a bit less flakey, but has nothing to
do with this branch.
* Change internal streaming payloads to stringified IDs as well
Per
https://github.com/tootsuite/mastodon/pull/5019#issuecomment-330736452
we need these changes to send deleted status IDs as strings, not
integers.
2017-09-20 12:53:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def in_reply_to_account_id
|
2017-09-24 02:09:32 +00:00
|
|
|
object.in_reply_to_account_id&.to_s
|
Change IDs to strings rather than numbers in API JSON output (#5019)
* Fix JavaScript interface with long IDs
Somewhat predictably, the JS interface handled IDs as numbers, which in
JS are IEEE double-precision floats. This loses some precision when
working with numbers as large as those generated by the new ID scheme,
so we instead handle them here as strings. This is relatively simple,
and doesn't appear to have caused any problems, but should definitely
be tested more thoroughly than the built-in tests. Several days of use
appear to support this working properly.
BREAKING CHANGE:
The major(!) change here is that IDs are now returned as strings by the
REST endpoints, rather than as integers. In practice, relatively few
changes were required to make the existing JS UI work with this change,
but it will likely hit API clients pretty hard: it's an entirely
different type to consume. (The one API client I tested, Tusky, handles
this with no problems, however.)
Twitter ran into this issue when introducing Snowflake IDs, and decided
to instead introduce an `id_str` field in JSON responses. I have opted
to *not* do that, and instead force all IDs to 64-bit integers
represented by strings in one go. (I believe Twitter exacerbated their
problem by rolling out the changes three times: once for statuses, once
for DMs, and once for user IDs, as well as by leaving an integer ID
value in JSON. As they said, "If you’re using the `id` field with JSON
in a Javascript-related language, there is a very high likelihood that
the integers will be silently munged by Javascript interpreters. In most
cases, this will result in behavior such as being unable to load or
delete a specific direct message, because the ID you're sending to the
API is different than the actual identifier associated with the
message." [1]) However, given that this is a significant change for API
users, alternatives or a transition time may be appropriate.
1: https://blog.twitter.com/developer/en_us/a/2011/direct-messages-going-snowflake-on-sep-30-2011.html
* Additional fixes for stringified IDs in JSON
These should be the last two. These were identified using eslint to try
to identify any plain casts to JavaScript numbers. (Some such casts are
legitimate, but these were not.)
Adding the following to .eslintrc.yml will identify casts to numbers:
~~~
no-restricted-syntax:
- warn
- selector: UnaryExpression[operator='+'] > :not(Literal)
message: Avoid the use of unary +
- selector: CallExpression[callee.name='Number']
message: Casting with Number() may coerce string IDs to numbers
~~~
The remaining three casts appear legitimate: two casts to array indices,
one in a server to turn an environment variable into a number.
* Back out RelationshipsController Change
This was made to make a test a bit less flakey, but has nothing to
do with this branch.
* Change internal streaming payloads to stringified IDs as well
Per
https://github.com/tootsuite/mastodon/pull/5019#issuecomment-330736452
we need these changes to send deleted status IDs as strings, not
integers.
2017-09-20 12:53:48 +00:00
|
|
|
end
|
|
|
|
|
2020-02-21 12:49:06 +00:00
|
|
|
def quote_id
|
|
|
|
object.quote_id.to_s
|
|
|
|
end
|
|
|
|
|
2022-08-27 10:57:05 +00:00
|
|
|
def account
|
|
|
|
if instance_options[:compact]
|
|
|
|
object.account.id.to_s
|
|
|
|
else
|
|
|
|
REST::AccountSerializer.new(object.account, root: false, scope: current_user, scope_name: :current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reblog
|
|
|
|
if object.reblog.nil?
|
|
|
|
nil
|
|
|
|
elsif instance_options[:compact]
|
|
|
|
object.reblog.id.to_s
|
|
|
|
else
|
|
|
|
REST::StatusSerializer.new(object.reblog, root: false, relationships: instance_options[:relationships], account_relationships: instance_options[:account_relationships], compact: false, scope: current_user, scope_name: :current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 02:02:06 +00:00
|
|
|
def current_user?
|
|
|
|
!current_user.nil?
|
|
|
|
end
|
|
|
|
|
2020-09-05 07:33:17 +00:00
|
|
|
def owned_status?
|
|
|
|
current_user? && current_user.account_id == object.account_id
|
|
|
|
end
|
|
|
|
|
2019-02-02 18:18:15 +00:00
|
|
|
def show_application?
|
2020-09-05 07:33:17 +00:00
|
|
|
object.account.user_shows_application? || owned_status?
|
2019-02-02 18:18:15 +00:00
|
|
|
end
|
|
|
|
|
2022-08-27 10:57:05 +00:00
|
|
|
def expires?
|
2021-07-16 06:38:50 +00:00
|
|
|
object.expires? || object.expired?
|
|
|
|
end
|
|
|
|
|
|
|
|
def expires_at
|
|
|
|
object&.status_expire&.expires_at || object.expired_at
|
2021-02-11 03:52:31 +00:00
|
|
|
end
|
|
|
|
|
2021-07-27 12:05:40 +00:00
|
|
|
def expires_action
|
|
|
|
object&.status_expire&.action || 'mark'
|
|
|
|
end
|
|
|
|
|
2021-02-11 03:52:31 +00:00
|
|
|
def visibility_ex?
|
|
|
|
object.limited_visibility?
|
|
|
|
end
|
|
|
|
|
2018-10-17 15:13:04 +00:00
|
|
|
def visibility
|
|
|
|
# This visibility is masked behind "private"
|
|
|
|
# to avoid API changes because there are no
|
|
|
|
# UX differences
|
|
|
|
if object.limited_visibility?
|
|
|
|
'private'
|
|
|
|
else
|
|
|
|
object.visibility
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-11 03:52:31 +00:00
|
|
|
def visibility_ex
|
|
|
|
object.visibility
|
|
|
|
end
|
|
|
|
|
2022-08-23 05:14:23 +00:00
|
|
|
def searchability
|
|
|
|
object.compute_searchability
|
|
|
|
end
|
|
|
|
|
2020-11-04 19:45:01 +00:00
|
|
|
def sensitive
|
|
|
|
if current_user? && current_user.account_id == object.account_id
|
|
|
|
object.sensitive
|
|
|
|
else
|
|
|
|
object.account.sensitized? || object.sensitive
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-05 07:33:17 +00:00
|
|
|
def limited_owned_parent_status?
|
2020-09-26 11:06:00 +00:00
|
|
|
object.limited_visibility? && owned_status? && (!object.reply? || object.thread&.conversation_id != object.conversation_id)
|
2020-09-05 07:33:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def circle_id
|
|
|
|
Redis.current.get("statuses/#{object.id}/circle_id")
|
|
|
|
end
|
|
|
|
|
2017-07-07 02:02:06 +00:00
|
|
|
def uri
|
2019-07-07 14:16:51 +00:00
|
|
|
ActivityPub::TagManager.instance.uri_for(object)
|
2017-07-07 02:02:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def content
|
2022-02-09 20:47:09 +00:00
|
|
|
@content ||= Formatter.instance.format(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def nyaize_content
|
|
|
|
@nyaize_content ||= Formatter.instance.format(object, nyaize: object.account.cat?)
|
2017-07-07 02:02:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2019-07-07 14:16:51 +00:00
|
|
|
ActivityPub::TagManager.instance.url_for(object)
|
2017-07-07 02:02:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def favourited
|
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].favourites_map[object.id] || false
|
|
|
|
else
|
|
|
|
current_user.account.favourited?(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-19 05:58:27 +00:00
|
|
|
def emoji_reactions
|
2021-06-28 22:15:41 +00:00
|
|
|
object.grouped_emoji_reactions(current_user&.account)
|
2021-05-19 05:58:27 +00:00
|
|
|
end
|
|
|
|
|
2022-03-17 14:25:16 +00:00
|
|
|
def status_reference_ids
|
|
|
|
object.references.map(&:id).map(&:to_s)
|
|
|
|
end
|
|
|
|
|
2017-07-07 02:02:06 +00:00
|
|
|
def reblogged
|
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].reblogs_map[object.id] || false
|
|
|
|
else
|
|
|
|
current_user.account.reblogged?(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def muted
|
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].mutes_map[object.conversation_id] || false
|
|
|
|
else
|
|
|
|
current_user.account.muting_conversation?(object.conversation)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-13 22:02:10 +00:00
|
|
|
def bookmarked
|
2019-11-28 03:08:00 +00:00
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].bookmarks_map[object.id] || false
|
2019-11-13 22:02:10 +00:00
|
|
|
else
|
|
|
|
current_user.account.bookmarked?(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-19 05:58:27 +00:00
|
|
|
def emoji_reactioned
|
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].emoji_reactions_map[object.id] || false
|
|
|
|
else
|
|
|
|
current_user.account.emoji_reactioned?(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-24 23:41:18 +00:00
|
|
|
def pinned
|
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].pins_map[object.id] || false
|
|
|
|
else
|
|
|
|
current_user.account.pinned?(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pinnable?
|
2020-09-05 07:33:17 +00:00
|
|
|
owned_status? &&
|
2017-08-24 23:41:18 +00:00
|
|
|
!object.reblog? &&
|
|
|
|
%w(public unlisted).include?(object.visibility)
|
|
|
|
end
|
|
|
|
|
2019-05-11 04:46:43 +00:00
|
|
|
def source_requested?
|
|
|
|
instance_options[:source_requested]
|
|
|
|
end
|
|
|
|
|
2022-02-09 20:47:09 +00:00
|
|
|
def joke_applied?
|
|
|
|
!source_requested? && object.account.cat? && nyaize_content != content
|
|
|
|
end
|
|
|
|
|
2018-03-19 19:19:35 +00:00
|
|
|
def ordered_mentions
|
2018-10-17 15:13:04 +00:00
|
|
|
object.active_mentions.to_a.sort_by(&:id)
|
2018-03-19 19:19:35 +00:00
|
|
|
end
|
|
|
|
|
2017-07-07 02:02:06 +00:00
|
|
|
class ApplicationSerializer < ActiveModel::Serializer
|
|
|
|
attributes :name, :website
|
|
|
|
end
|
|
|
|
|
|
|
|
class MentionSerializer < ActiveModel::Serializer
|
2020-07-12 13:00:23 +00:00
|
|
|
attributes :id, :username, :url, :acct, :group
|
2017-07-07 02:02:06 +00:00
|
|
|
|
|
|
|
def id
|
Change IDs to strings rather than numbers in API JSON output (#5019)
* Fix JavaScript interface with long IDs
Somewhat predictably, the JS interface handled IDs as numbers, which in
JS are IEEE double-precision floats. This loses some precision when
working with numbers as large as those generated by the new ID scheme,
so we instead handle them here as strings. This is relatively simple,
and doesn't appear to have caused any problems, but should definitely
be tested more thoroughly than the built-in tests. Several days of use
appear to support this working properly.
BREAKING CHANGE:
The major(!) change here is that IDs are now returned as strings by the
REST endpoints, rather than as integers. In practice, relatively few
changes were required to make the existing JS UI work with this change,
but it will likely hit API clients pretty hard: it's an entirely
different type to consume. (The one API client I tested, Tusky, handles
this with no problems, however.)
Twitter ran into this issue when introducing Snowflake IDs, and decided
to instead introduce an `id_str` field in JSON responses. I have opted
to *not* do that, and instead force all IDs to 64-bit integers
represented by strings in one go. (I believe Twitter exacerbated their
problem by rolling out the changes three times: once for statuses, once
for DMs, and once for user IDs, as well as by leaving an integer ID
value in JSON. As they said, "If you’re using the `id` field with JSON
in a Javascript-related language, there is a very high likelihood that
the integers will be silently munged by Javascript interpreters. In most
cases, this will result in behavior such as being unable to load or
delete a specific direct message, because the ID you're sending to the
API is different than the actual identifier associated with the
message." [1]) However, given that this is a significant change for API
users, alternatives or a transition time may be appropriate.
1: https://blog.twitter.com/developer/en_us/a/2011/direct-messages-going-snowflake-on-sep-30-2011.html
* Additional fixes for stringified IDs in JSON
These should be the last two. These were identified using eslint to try
to identify any plain casts to JavaScript numbers. (Some such casts are
legitimate, but these were not.)
Adding the following to .eslintrc.yml will identify casts to numbers:
~~~
no-restricted-syntax:
- warn
- selector: UnaryExpression[operator='+'] > :not(Literal)
message: Avoid the use of unary +
- selector: CallExpression[callee.name='Number']
message: Casting with Number() may coerce string IDs to numbers
~~~
The remaining three casts appear legitimate: two casts to array indices,
one in a server to turn an environment variable into a number.
* Back out RelationshipsController Change
This was made to make a test a bit less flakey, but has nothing to
do with this branch.
* Change internal streaming payloads to stringified IDs as well
Per
https://github.com/tootsuite/mastodon/pull/5019#issuecomment-330736452
we need these changes to send deleted status IDs as strings, not
integers.
2017-09-20 12:53:48 +00:00
|
|
|
object.account_id.to_s
|
2017-07-07 02:02:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
object.account_username
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2019-07-07 14:16:51 +00:00
|
|
|
ActivityPub::TagManager.instance.url_for(object.account)
|
2017-07-07 02:02:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def acct
|
2020-02-03 20:16:37 +00:00
|
|
|
object.account.pretty_acct
|
2017-07-07 02:02:06 +00:00
|
|
|
end
|
2020-07-12 13:00:23 +00:00
|
|
|
|
|
|
|
def group
|
|
|
|
object.account.group?
|
|
|
|
end
|
2017-07-07 02:02:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class TagSerializer < ActiveModel::Serializer
|
|
|
|
include RoutingHelper
|
|
|
|
|
|
|
|
attributes :name, :url
|
|
|
|
|
|
|
|
def url
|
|
|
|
tag_url(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-21 12:49:06 +00:00
|
|
|
|
|
|
|
class REST::NestedQuoteSerializer < REST::StatusSerializer
|
|
|
|
attribute :quote do
|
|
|
|
nil
|
|
|
|
end
|
2020-06-06 03:59:45 +00:00
|
|
|
attribute :quote_muted, if: :current_user?
|
|
|
|
|
|
|
|
def quote_muted
|
|
|
|
if instance_options && instance_options[:account_relationships]
|
|
|
|
instance_options[:account_relationships].muting[object.account_id] ? true : false || instance_options[:account_relationships].blocking[object.account_id] || instance_options[:account_relationships].blocked_by[object.account_id] || instance_options[:account_relationships].domain_blocking[object.account_id] || false
|
|
|
|
else
|
2022-08-27 10:57:05 +00:00
|
|
|
current_user.account.muting?(object.account) || object.account.blocking?(current_user.account) || current_user.account.blocking?(object.account) || current_user.account.domain_blocking?(object.account.domain)
|
2020-06-06 03:59:45 +00:00
|
|
|
end
|
|
|
|
end
|
2020-02-21 12:49:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class REST::StatusSerializer < ActiveModel::Serializer
|
2022-08-27 10:57:05 +00:00
|
|
|
attribute :quote
|
|
|
|
|
|
|
|
def quote
|
|
|
|
if object.quote.nil?
|
|
|
|
nil
|
|
|
|
elsif instance_options[:compact]
|
|
|
|
object.quote.id.to_s
|
|
|
|
else
|
|
|
|
REST::NestedQuoteSerializer.new(object.quote, root: false, relationships: instance_options[:relationships], account_relationships: instance_options[:account_relationships], compact: false, scope: current_user, scope_name: :current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-02-21 12:49:06 +00:00
|
|
|
end
|