vanita5 / mastodon-api

Mastodon API Client Library
MIT License
122 stars 21 forks source link

Fix #34: don't JSON.parse delete events' IDs #35

Open fasiha opened 1 year ago

fasiha commented 1 year ago

Per discussion in #34, we shouldn't JSON.parse delete events' payload because it's a stringy ID and needs to remain a string to avoid exceeding float precision issues.

This appears to be the only event for which this is the case, per Mastodon docs (no other events mention string ID). Therefore, this PR proposes a simple solution: skip JSON.parseing the event payload if it's a delete.

With this in place, the following streaming data chunk:

event: delete\ndata: 110988741790818968\n\n

is parsed into { event: 'delete', data: '110988741790818968' } as expected (and not parseInt('110988741790818968') which is 110988741790818980…). All other events are processed as before.