2017-07-07 05:02:06 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::StatusSerializer < ActiveModel::Serializer
|
2022-03-26 03:53:34 +02:00
|
|
|
include FormattingHelper
|
|
|
|
|
2017-07-07 05:02:06 +03:00
|
|
|
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
|
2023-03-16 12:07:24 +02:00
|
|
|
:sensitive, :spoiler_text, :visibility, :language,
|
2019-05-11 07:46:43 +03:00
|
|
|
:uri, :url, :replies_count, :reblogs_count,
|
2022-01-19 23:37:27 +02:00
|
|
|
:favourites_count, :edited_at
|
2017-07-07 05:02:06 +03:00
|
|
|
|
|
|
|
attribute :favourited, if: :current_user?
|
|
|
|
attribute :reblogged, if: :current_user?
|
|
|
|
attribute :muted, if: :current_user?
|
2018-04-10 23:13:15 +03:00
|
|
|
attribute :bookmarked, if: :current_user?
|
2017-08-25 02:41:18 +03:00
|
|
|
attribute :pinned, if: :pinnable?
|
2023-04-09 12:25:30 +03:00
|
|
|
attribute :local_only, if: :local?
|
Revamp post filtering system (#18058)
* Add model for custom filter keywords
* Use CustomFilterKeyword internally
Does not change the API
* Fix /filters/edit and /filters/new
* Add migration tests
* Remove whole_word column from custom_filters (covered by custom_filter_keywords)
* Redesign /filters
Instead of a list, present a card that displays more information and handles
multiple keywords per filter.
* Redesign /filters/new and /filters/edit to add and remove keywords
This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.
* Add /api/v2/filters to edit filter with multiple keywords
Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
`keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`
API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
`keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
`keywords_attributes` can also be passed to edit, delete or add keywords in
one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword
* Change from `irreversible` boolean to `action` enum
* Remove irrelevent `irreversible_must_be_within_context` check
* Fix /filters/new and /filters/edit with update for filter_action
* Fix Rubocop/Codeclimate complaining about task names
* Refactor FeedManager#phrase_filtered?
This moves regexp building and filter caching to the `CustomFilter` class.
This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.
* Perform server-side filtering and output result in REST API
* Fix numerous filters_changed events being sent when editing multiple keywords at once
* Add some tests
* Use the new API in the WebUI
- use client-side logic for filters we have fetched rules for.
This is so that filter changes can be retroactively applied without
reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
(e.g. network error, or initial timeline loading)
* Minor optimizations and refactoring
* Perform server-side filtering on the streaming server
* Change the wording of filter action labels
* Fix issues pointed out by linter
* Change design of “Show anyway” link in accordence to review comments
* Drop “irreversible” filtering behavior
* Move /api/v2/filter_keywords to /api/v1/filters/keywords
* Rename `filter_results` attribute to `filtered`
* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer
* Fix systemChannelId value in streaming server
* Simplify code by removing client-side filtering code
The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
2022-06-28 10:42:13 +03:00
|
|
|
has_many :filtered, serializer: REST::FilterResultSerializer, if: :current_user?
|
2017-07-07 05:02:06 +03:00
|
|
|
|
2019-05-11 07:46:43 +03:00
|
|
|
attribute :content, unless: :source_requested?
|
|
|
|
attribute :text, if: :source_requested?
|
2019-05-12 21:34:22 +03:00
|
|
|
attribute :content_type, if: :source_requested?
|
2019-05-11 07:46:43 +03:00
|
|
|
|
2017-07-07 05:02:06 +03:00
|
|
|
belongs_to :reblog, serializer: REST::StatusSerializer
|
2019-01-21 23:40:26 +02:00
|
|
|
belongs_to :application, if: :show_application?
|
2017-07-07 05:02:06 +03:00
|
|
|
belongs_to :account, serializer: REST::AccountSerializer
|
|
|
|
|
2022-03-09 10:06:17 +02:00
|
|
|
has_many :ordered_media_attachments, key: :media_attachments, serializer: REST::MediaAttachmentSerializer
|
2018-03-19 21:19:35 +02:00
|
|
|
has_many :ordered_mentions, key: :mentions
|
2017-07-07 05:02:06 +03:00
|
|
|
has_many :tags
|
2017-09-23 02:57:23 +03:00
|
|
|
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
2017-07-07 05:02:06 +03:00
|
|
|
|
2018-10-28 07:35:03 +02:00
|
|
|
has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer
|
2019-03-28 05:44:59 +02:00
|
|
|
has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer
|
2018-10-28 07:35:03 +02:00
|
|
|
|
2023-04-09 12:25:30 +03:00
|
|
|
delegate :local?, 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 15:53:48 +03:00
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_reply_to_id
|
2017-09-24 05:09:32 +03: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 15:53:48 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def in_reply_to_account_id
|
2017-09-24 05:09:32 +03: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 15:53:48 +03:00
|
|
|
end
|
|
|
|
|
2017-07-07 05:02:06 +03:00
|
|
|
def current_user?
|
|
|
|
!current_user.nil?
|
|
|
|
end
|
|
|
|
|
2019-01-21 23:40:26 +02:00
|
|
|
def show_application?
|
|
|
|
object.account.user_shows_application? || (current_user? && current_user.account_id == object.account_id)
|
2019-01-21 20:36:33 +02:00
|
|
|
end
|
|
|
|
|
2018-10-17 18:13:04 +03: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
|
|
|
|
|
2020-11-04 21:45:01 +02:00
|
|
|
def sensitive
|
|
|
|
if current_user? && current_user.account_id == object.account_id
|
|
|
|
object.sensitive
|
|
|
|
else
|
|
|
|
object.account.sensitized? || object.sensitive
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 05:02:06 +03:00
|
|
|
def uri
|
2019-07-07 17:16:51 +03:00
|
|
|
ActivityPub::TagManager.instance.uri_for(object)
|
2017-07-07 05:02:06 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def content
|
2022-03-26 03:53:34 +02:00
|
|
|
status_content_format(object)
|
2017-07-07 05:02:06 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2019-07-07 17:16:51 +03:00
|
|
|
ActivityPub::TagManager.instance.url_for(object)
|
2017-07-07 05:02:06 +03: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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-04-10 23:13:15 +03:00
|
|
|
def bookmarked
|
2019-11-28 05:08:00 +02:00
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].bookmarks_map[object.id] || false
|
2018-04-10 23:13:15 +03:00
|
|
|
else
|
|
|
|
current_user.account.bookmarked?(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-25 02:41:18 +03: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
|
|
|
|
|
Revamp post filtering system (#18058)
* Add model for custom filter keywords
* Use CustomFilterKeyword internally
Does not change the API
* Fix /filters/edit and /filters/new
* Add migration tests
* Remove whole_word column from custom_filters (covered by custom_filter_keywords)
* Redesign /filters
Instead of a list, present a card that displays more information and handles
multiple keywords per filter.
* Redesign /filters/new and /filters/edit to add and remove keywords
This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.
* Add /api/v2/filters to edit filter with multiple keywords
Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
`keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`
API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
`keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
`keywords_attributes` can also be passed to edit, delete or add keywords in
one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword
* Change from `irreversible` boolean to `action` enum
* Remove irrelevent `irreversible_must_be_within_context` check
* Fix /filters/new and /filters/edit with update for filter_action
* Fix Rubocop/Codeclimate complaining about task names
* Refactor FeedManager#phrase_filtered?
This moves regexp building and filter caching to the `CustomFilter` class.
This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.
* Perform server-side filtering and output result in REST API
* Fix numerous filters_changed events being sent when editing multiple keywords at once
* Add some tests
* Use the new API in the WebUI
- use client-side logic for filters we have fetched rules for.
This is so that filter changes can be retroactively applied without
reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
(e.g. network error, or initial timeline loading)
* Minor optimizations and refactoring
* Perform server-side filtering on the streaming server
* Change the wording of filter action labels
* Fix issues pointed out by linter
* Change design of “Show anyway” link in accordence to review comments
* Drop “irreversible” filtering behavior
* Move /api/v2/filter_keywords to /api/v1/filters/keywords
* Rename `filter_results` attribute to `filtered`
* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer
* Fix systemChannelId value in streaming server
* Simplify code by removing client-side filtering code
The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
2022-06-28 10:42:13 +03:00
|
|
|
def filtered
|
|
|
|
if instance_options && instance_options[:relationships]
|
|
|
|
instance_options[:relationships].filters_map[object.id] || []
|
|
|
|
else
|
|
|
|
current_user.account.status_matches_filters(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-25 02:41:18 +03:00
|
|
|
def pinnable?
|
|
|
|
current_user? &&
|
|
|
|
current_user.account_id == object.account_id &&
|
|
|
|
!object.reblog? &&
|
2022-01-17 10:07:45 +02:00
|
|
|
%w(public unlisted private).include?(object.visibility)
|
2017-08-25 02:41:18 +03:00
|
|
|
end
|
|
|
|
|
2019-05-11 07:46:43 +03:00
|
|
|
def source_requested?
|
|
|
|
instance_options[:source_requested]
|
|
|
|
end
|
|
|
|
|
2018-03-19 21:19:35 +02:00
|
|
|
def ordered_mentions
|
2018-10-17 18:13:04 +03:00
|
|
|
object.active_mentions.to_a.sort_by(&:id)
|
2018-03-19 21:19:35 +02:00
|
|
|
end
|
|
|
|
|
2017-07-07 05:02:06 +03:00
|
|
|
class ApplicationSerializer < ActiveModel::Serializer
|
|
|
|
attributes :name, :website
|
2022-04-05 13:00:31 +03:00
|
|
|
|
|
|
|
def website
|
|
|
|
object.website.presence
|
|
|
|
end
|
2017-07-07 05:02:06 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
class MentionSerializer < ActiveModel::Serializer
|
|
|
|
attributes :id, :username, :url, :acct
|
|
|
|
|
|
|
|
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 15:53:48 +03:00
|
|
|
object.account_id.to_s
|
2017-07-07 05:02:06 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
object.account_username
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2019-07-07 17:16:51 +03:00
|
|
|
ActivityPub::TagManager.instance.url_for(object.account)
|
2017-07-07 05:02:06 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def acct
|
2020-02-03 22:16:37 +02:00
|
|
|
object.account.pretty_acct
|
2017-07-07 05:02:06 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TagSerializer < ActiveModel::Serializer
|
|
|
|
include RoutingHelper
|
|
|
|
|
|
|
|
attributes :name, :url
|
|
|
|
|
|
|
|
def url
|
|
|
|
tag_url(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|