You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastodon/app/services
aschmitz 669fe9ee06 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.
7 years ago
..
activitypub Fix incomplete account records being read (#4998) 7 years ago
concerns Introduce OStatus::TagManager (#5008) 7 years ago
pubsubhubbub Fix #2672 - Connect signed PuSH subscription requests to instance domain (#4205) 8 years ago
account_search_service.rb Fix an error when a user tries to search nonexistent remote user (regression from #4275) (#4400) 8 years ago
after_block_service.rb Optimize MuteService and AfterBlockService (#2836) 8 years ago
authorize_follow_service.rb Add handling of Linked Data Signatures in payloads (#4687) 8 years ago
base_service.rb Remove unused AtomBuilderHelper (#1364) 8 years ago
batched_remove_status_service.rb Change IDs to strings rather than numbers in API JSON output (#5019) 7 years ago
block_domain_from_account_service.rb Add buttons to block and unblock domain (#3127) 8 years ago
block_domain_service.rb Admin interface for listing, adding and removing custom emojis (#5002) 7 years ago
block_service.rb Add handling of Linked Data Signatures in payloads (#4687) 8 years ago
bootstrap_timeline_service.rb Default follows for new users (#4871) 8 years ago
fan_out_on_write_service.rb Refactor JSON templates to be generated with ActiveModelSerializers instead of Rabl (#4090) 8 years ago
favourite_service.rb Add handling of Linked Data Signatures in payloads (#4687) 8 years ago
fetch_atom_service.rb Fix accessing to XML attribute in FetchAtomService (#4668) 8 years ago
fetch_link_card_service.rb Enable to recognize most kinds of characters as URL paths (#4941) 8 years ago
fetch_remote_account_service.rb Introduce OStatus::TagManager (#5008) 7 years ago
fetch_remote_resource_service.rb Add support for searching AP users (#4599) 8 years ago
fetch_remote_status_service.rb Introduce OStatus::TagManager (#5008) 7 years ago
follow_service.rb Default follows for new users (#4871) 8 years ago
mute_service.rb Optimize MuteService and AfterBlockService (#2836) 8 years ago
notify_service.rb Fix #4172 - Mutes now block notifications (#4300) 8 years ago
post_status_service.rb Fix filterable_languages method of SettingsHelper (#4966) 8 years ago
precompute_feed_service.rb Fix PrecomputeFeedService for filtered statuses (#4148) 8 years ago
process_feed_service.rb Introduce OStatus::TagManager (#5008) 7 years ago
process_hashtags_service.rb Unify the method of extracting tags (#3138) 8 years ago
process_interaction_service.rb Introduce OStatus::TagManager (#5008) 7 years ago
process_mentions_service.rb Fix mentions in direct statuses not being delivered via AP (#4806) 8 years ago
reblog_service.rb Avoid sending some ActivityPub payloads if the receiver will get them through distribution (#4739) 8 years ago
reject_follow_service.rb Add handling of Linked Data Signatures in payloads (#4687) 8 years ago
remove_status_service.rb Change IDs to strings rather than numbers in API JSON output (#5019) 7 years ago
resolve_remote_account_service.rb Fix an error when actor json couldn't be fetched in ResolveRemoteAccountService (#4979) 8 years ago
search_service.rb Add specs (and refactor) of FetchRemoteResourceService and SearchService (#2812) 8 years ago
send_interaction_service.rb Fix webfinger retries (#4275) 8 years ago
subscribe_service.rb Guarantee Subscription service first account has proper URL details (#4732) 8 years ago
suspend_account_service.rb Fix account delete form not accepting password, update suspended (#3745) 8 years ago
unblock_domain_service.rb Allow domain blocks that only reject media without silencing or suspending (#4325) 8 years ago
unblock_service.rb Add handling of Linked Data Signatures in payloads (#4687) 8 years ago
unfavourite_service.rb Add handling of Linked Data Signatures in payloads (#4687) 8 years ago
unfollow_service.rb Make "unfollow" undo pending outgoing follow request too (#4781) 8 years ago
unmute_service.rb Fix #231 - Muting 8 years ago
unsubscribe_service.rb Fix errors preventing UnsubscribeService from working (#4866) 8 years ago
update_account_service.rb authorize-follow-requests-after-unlocking (#4658) 8 years ago
update_remote_profile_service.rb Account deletion (#3728) 8 years ago
verify_salmon_service.rb Introduce OStatus::TagManager (#5008) 7 years ago