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.
2017-09-20 14:53:48 +02:00
..
activitypub Fix incomplete account records being read (#4998) 2017-09-19 06:53:16 +02:00
concerns Introduce OStatus::TagManager (#5008) 2017-09-19 18:08:08 +02:00
pubsubhubbub
account_search_service.rb
after_block_service.rb
authorize_follow_service.rb Add handling of Linked Data Signatures in payloads (#4687) 2017-08-26 13:47:38 +02:00
base_service.rb
batched_remove_status_service.rb Change IDs to strings rather than numbers in API JSON output (#5019) 2017-09-20 14:53:48 +02:00
block_domain_from_account_service.rb
block_domain_service.rb Admin interface for listing, adding and removing custom emojis (#5002) 2017-09-19 03:52:38 +02:00
block_service.rb Add handling of Linked Data Signatures in payloads (#4687) 2017-08-26 13:47:38 +02:00
bootstrap_timeline_service.rb Default follows for new users (#4871) 2017-09-10 09:58:38 +02:00
fan_out_on_write_service.rb
favourite_service.rb Add handling of Linked Data Signatures in payloads (#4687) 2017-08-26 13:47:38 +02:00
fetch_atom_service.rb Fix accessing to XML attribute in FetchAtomService (#4668) 2017-08-23 12:25:57 +02:00
fetch_link_card_service.rb Enable to recognize most kinds of characters as URL paths (#4941) 2017-09-14 18:03:20 +02:00
fetch_remote_account_service.rb Introduce OStatus::TagManager (#5008) 2017-09-19 18:08:08 +02:00
fetch_remote_resource_service.rb Add support for searching AP users (#4599) 2017-08-14 14:08:34 +02:00
fetch_remote_status_service.rb Introduce OStatus::TagManager (#5008) 2017-09-19 18:08:08 +02:00
follow_service.rb Default follows for new users (#4871) 2017-09-10 09:58:38 +02:00
mute_service.rb
notify_service.rb
post_status_service.rb Fix filterable_languages method of SettingsHelper (#4966) 2017-09-16 14:59:41 +02:00
precompute_feed_service.rb
process_feed_service.rb Introduce OStatus::TagManager (#5008) 2017-09-19 18:08:08 +02:00
process_hashtags_service.rb
process_interaction_service.rb Introduce OStatus::TagManager (#5008) 2017-09-19 18:08:08 +02:00
process_mentions_service.rb Fix mentions in direct statuses not being delivered via AP (#4806) 2017-09-05 20:55:25 +02:00
reblog_service.rb Avoid sending some ActivityPub payloads if the receiver will get them through distribution (#4739) 2017-09-01 21:26:01 +02:00
reject_follow_service.rb Add handling of Linked Data Signatures in payloads (#4687) 2017-08-26 13:47:38 +02:00
remove_status_service.rb Change IDs to strings rather than numbers in API JSON output (#5019) 2017-09-20 14:53:48 +02:00
resolve_remote_account_service.rb Fix an error when actor json couldn't be fetched in ResolveRemoteAccountService (#4979) 2017-09-17 11:54:23 +02:00
search_service.rb
send_interaction_service.rb
subscribe_service.rb Guarantee Subscription service first account has proper URL details (#4732) 2017-08-31 15:44:00 +02:00
suspend_account_service.rb
unblock_domain_service.rb
unblock_service.rb Add handling of Linked Data Signatures in payloads (#4687) 2017-08-26 13:47:38 +02:00
unfavourite_service.rb Add handling of Linked Data Signatures in payloads (#4687) 2017-08-26 13:47:38 +02:00
unfollow_service.rb Make "unfollow" undo pending outgoing follow request too (#4781) 2017-09-02 20:44:41 +02:00
unmute_service.rb Fix #231 - Muting 2017-03-02 18:49:32 +01:00
unsubscribe_service.rb Fix errors preventing UnsubscribeService from working (#4866) 2017-09-09 17:36:27 +02:00
update_account_service.rb authorize-follow-requests-after-unlocking (#4658) 2017-08-26 12:40:03 +02:00
update_remote_profile_service.rb
verify_salmon_service.rb Introduce OStatus::TagManager (#5008) 2017-09-19 18:08:08 +02:00