2017-05-03 00:04:16 +00:00
import React from 'react' ;
2017-01-30 20:40:55 +00:00
import { connect } from 'react-redux' ;
import { makeGetAccount } from '../../../selectors' ;
import Header from '../components/header' ;
import {
followAccount ,
unfollowAccount ,
2017-02-06 01:51:56 +00:00
unblockAccount ,
2017-05-20 15:31:47 +00:00
unmuteAccount ,
2018-08-09 07:56:53 +00:00
pinAccount ,
unpinAccount ,
2017-01-30 20:40:55 +00:00
} from '../../../actions/accounts' ;
2018-03-29 17:08:34 +00:00
import {
mentionCompose ,
directCompose ,
} from '../../../actions/compose' ;
2017-11-15 02:56:41 +00:00
import { initMuteModal } from '../../../actions/mutes' ;
2019-09-29 19:46:05 +00:00
import { initBlockModal } from '../../../actions/blocks' ;
2017-02-14 19:59:26 +00:00
import { initReport } from '../../../actions/reports' ;
2017-04-23 02:39:50 +00:00
import { openModal } from '../../../actions/modal' ;
2017-05-19 19:05:32 +00:00
import { blockDomain , unblockDomain } from '../../../actions/domain_blocks' ;
2017-04-23 02:39:50 +00:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2017-10-29 15:10:15 +00:00
import { unfollowModal } from '../../../initial_state' ;
2019-03-28 17:01:09 +00:00
import { List as ImmutableList } from 'immutable' ;
2017-04-23 02:39:50 +00:00
const messages = defineMessages ( {
2017-07-18 15:14:43 +00:00
unfollowConfirm : { id : 'confirmations.unfollow.confirm' , defaultMessage : 'Unfollow' } ,
2017-05-19 19:05:32 +00:00
blockDomainConfirm : { id : 'confirmations.domain_block.confirm' , defaultMessage : 'Hide entire domain' } ,
2017-04-23 02:39:50 +00:00
} ) ;
2017-01-30 20:40:55 +00:00
const makeMapStateToProps = ( ) => {
const getAccount = makeGetAccount ( ) ;
const mapStateToProps = ( state , { accountId } ) => ( {
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
account : getAccount ( state , accountId ) ,
2019-03-25 23:36:25 +00:00
domain : state . getIn ( [ 'meta' , 'domain' ] ) ,
2019-03-28 17:01:09 +00:00
identity _proofs : state . getIn ( [ 'identity_proofs' , accountId ] , ImmutableList ( ) ) ,
2017-01-30 20:40:55 +00:00
} ) ;
return mapStateToProps ;
} ;
2017-04-23 02:39:50 +00:00
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
2017-07-18 15:14:43 +00:00
2017-01-30 20:40:55 +00:00
onFollow ( account ) {
2017-09-02 18:44:41 +00:00
if ( account . getIn ( [ 'relationship' , 'following' ] ) || account . getIn ( [ 'relationship' , 'requested' ] ) ) {
2017-10-29 15:10:15 +00:00
if ( unfollowModal ) {
2017-07-18 15:14:43 +00:00
dispatch ( openModal ( 'CONFIRM' , {
message : < FormattedMessage id = 'confirmations.unfollow.message' defaultMessage = 'Are you sure you want to unfollow {name}?' values = { { name : < strong > @ { account . get ( 'acct' ) } < /strong> }} / > ,
confirm : intl . formatMessage ( messages . unfollowConfirm ) ,
onConfirm : ( ) => dispatch ( unfollowAccount ( account . get ( 'id' ) ) ) ,
} ) ) ;
} else {
dispatch ( unfollowAccount ( account . get ( 'id' ) ) ) ;
}
2017-01-30 20:40:55 +00:00
} else {
dispatch ( followAccount ( account . get ( 'id' ) ) ) ;
}
} ,
onBlock ( account ) {
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
dispatch ( unblockAccount ( account . get ( 'id' ) ) ) ;
} else {
2019-09-29 19:46:05 +00:00
dispatch ( initBlockModal ( account ) ) ;
2017-01-30 20:40:55 +00:00
}
} ,
onMention ( account , router ) {
dispatch ( mentionCompose ( account , router ) ) ;
2017-02-14 19:59:26 +00:00
} ,
2018-03-29 17:08:34 +00:00
onDirect ( account , router ) {
dispatch ( directCompose ( account , router ) ) ;
} ,
Allow hiding of reblogs from followed users (#5762)
* Allow hiding of reblogs from followed users
This adds a new entry to the account menu to allow users to hide
future reblogs from a user (and then if they've done that, to show
future reblogs instead).
This does not remove or add historical reblogs from/to the user's
timeline; it only affects new statuses.
The API for this operates by sending a "reblogs" key to the follow
endpoint. If this is sent when starting a new follow, it will be
respected from the beginning of the follow relationship (even if
the follow request must be approved by the followee). If this is
sent when a follow relationship already exists, it will simply
update the existing follow relationship. As with the notification
muting, this will now return an object ({reblogs: [true|false]}) or
false for each follow relationship when requesting relationship
information for an account. This should cause few issues due to an
object being truthy in many languages, but some modifications may
need to be made in pickier languages.
Database changes: adds a show_reblogs column (default true,
non-nullable) to the follows and follow_requests tables. Because
these are non-nullable, we use the existing MigrationHelpers to
perform this change without locking those tables, although the
tables are likely to be small anyway.
Tests included.
See also <https://github.com/glitch-soc/mastodon/pull/212>.
* Rubocop fixes
* Code review changes
* Test fixes
This patchset closes #648 and resolves #3271.
* Rubocop fix
* Revert reblogs defaulting in argument, fix tests
It turns out we needed this for the same reason we needed it in muting:
if nil gets passed in somehow (most usually by an API client not passing
any value), we need to detect and handle it.
We could specify a default in the parameter and then also catch nil, but
there's no great reason to duplicate the default value.
2017-11-28 14:00:35 +00:00
onReblogToggle ( account ) {
2017-12-07 02:37:31 +00:00
if ( account . getIn ( [ 'relationship' , 'showing_reblogs' ] ) ) {
Allow hiding of reblogs from followed users (#5762)
* Allow hiding of reblogs from followed users
This adds a new entry to the account menu to allow users to hide
future reblogs from a user (and then if they've done that, to show
future reblogs instead).
This does not remove or add historical reblogs from/to the user's
timeline; it only affects new statuses.
The API for this operates by sending a "reblogs" key to the follow
endpoint. If this is sent when starting a new follow, it will be
respected from the beginning of the follow relationship (even if
the follow request must be approved by the followee). If this is
sent when a follow relationship already exists, it will simply
update the existing follow relationship. As with the notification
muting, this will now return an object ({reblogs: [true|false]}) or
false for each follow relationship when requesting relationship
information for an account. This should cause few issues due to an
object being truthy in many languages, but some modifications may
need to be made in pickier languages.
Database changes: adds a show_reblogs column (default true,
non-nullable) to the follows and follow_requests tables. Because
these are non-nullable, we use the existing MigrationHelpers to
perform this change without locking those tables, although the
tables are likely to be small anyway.
Tests included.
See also <https://github.com/glitch-soc/mastodon/pull/212>.
* Rubocop fixes
* Code review changes
* Test fixes
This patchset closes #648 and resolves #3271.
* Rubocop fix
* Revert reblogs defaulting in argument, fix tests
It turns out we needed this for the same reason we needed it in muting:
if nil gets passed in somehow (most usually by an API client not passing
any value), we need to detect and handle it.
We could specify a default in the parameter and then also catch nil, but
there's no great reason to duplicate the default value.
2017-11-28 14:00:35 +00:00
dispatch ( followAccount ( account . get ( 'id' ) , false ) ) ;
} else {
dispatch ( followAccount ( account . get ( 'id' ) , true ) ) ;
}
} ,
2018-08-09 07:56:53 +00:00
onEndorseToggle ( account ) {
if ( account . getIn ( [ 'relationship' , 'endorsed' ] ) ) {
dispatch ( unpinAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( pinAccount ( account . get ( 'id' ) ) ) ;
}
} ,
2017-02-14 19:59:26 +00:00
onReport ( account ) {
dispatch ( initReport ( account ) ) ;
2017-02-06 01:51:56 +00:00
} ,
onMute ( account ) {
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
dispatch ( unmuteAccount ( account . get ( 'id' ) ) ) ;
} else {
2017-11-15 02:56:41 +00:00
dispatch ( initMuteModal ( account ) ) ;
2017-02-06 01:51:56 +00:00
}
2017-05-19 19:05:32 +00:00
} ,
2018-03-30 10:38:00 +00:00
onBlockDomain ( domain ) {
2017-05-19 19:05:32 +00:00
dispatch ( openModal ( 'CONFIRM' , {
2018-06-09 20:46:54 +00:00
message : < FormattedMessage id = 'confirmations.domain_block.message' defaultMessage = 'Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.' values = { { domain : < strong > { domain } < /strong> }} / > ,
2017-05-19 19:05:32 +00:00
confirm : intl . formatMessage ( messages . blockDomainConfirm ) ,
2018-03-30 10:38:00 +00:00
onConfirm : ( ) => dispatch ( blockDomain ( domain ) ) ,
2017-05-19 19:05:32 +00:00
} ) ) ;
} ,
2018-03-30 10:38:00 +00:00
onUnblockDomain ( domain ) {
dispatch ( unblockDomain ( domain ) ) ;
2017-05-20 15:31:47 +00:00
} ,
2017-07-18 15:14:43 +00:00
2018-11-05 17:52:38 +00:00
onAddToList ( account ) {
dispatch ( openModal ( 'LIST_ADDER' , {
accountId : account . get ( 'id' ) ,
} ) ) ;
} ,
2017-01-30 20:40:55 +00:00
} ) ;
2017-04-23 02:39:50 +00:00
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Header ) ) ;