2017-05-03 09:04:16 +09:00
import React from 'react' ;
2017-01-31 05:40:55 +09:00
import { connect } from 'react-redux' ;
2022-05-10 16:44:35 +09:00
import { makeGetAccount , getAccountHidden } from '../../../selectors' ;
2017-01-31 05:40:55 +09:00
import Header from '../components/header' ;
import {
followAccount ,
unfollowAccount ,
2017-02-06 10:51:56 +09:00
unblockAccount ,
2017-05-21 00:31:47 +09:00
unmuteAccount ,
2018-08-09 16:56:53 +09:00
pinAccount ,
unpinAccount ,
2017-01-31 05:40:55 +09:00
} from '../../../actions/accounts' ;
2018-03-30 02:08:34 +09:00
import {
mentionCompose ,
directCompose ,
} from '../../../actions/compose' ;
2017-11-15 11:56:41 +09:00
import { initMuteModal } from '../../../actions/mutes' ;
2019-09-30 04:46:05 +09:00
import { initBlockModal } from '../../../actions/blocks' ;
2017-02-15 04:59:26 +09:00
import { initReport } from '../../../actions/reports' ;
2017-04-23 11:39:50 +09:00
import { openModal } from '../../../actions/modal' ;
2017-05-20 04:05:32 +09:00
import { blockDomain , unblockDomain } from '../../../actions/domain_blocks' ;
2017-04-23 11:39:50 +09:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2017-10-30 00:10:15 +09:00
import { unfollowModal } from '../../../initial_state' ;
2017-04-23 11:39:50 +09:00
const messages = defineMessages ( {
2017-07-19 00:14:43 +09:00
unfollowConfirm : { id : 'confirmations.unfollow.confirm' , defaultMessage : 'Unfollow' } ,
2017-05-20 04:05:32 +09:00
blockDomainConfirm : { id : 'confirmations.domain_block.confirm' , defaultMessage : 'Hide entire domain' } ,
2017-04-23 11:39:50 +09:00
} ) ;
2017-01-31 05:40:55 +09: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 21:53:48 +09:00
account : getAccount ( state , accountId ) ,
2019-03-26 08:36:25 +09:00
domain : state . getIn ( [ 'meta' , 'domain' ] ) ,
2022-05-10 16:44:35 +09:00
hidden : getAccountHidden ( state , accountId ) ,
2017-01-31 05:40:55 +09:00
} ) ;
return mapStateToProps ;
} ;
2017-04-23 11:39:50 +09:00
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
2017-07-19 00:14:43 +09:00
2017-01-31 05:40:55 +09:00
onFollow ( account ) {
2017-09-03 03:44:41 +09:00
if ( account . getIn ( [ 'relationship' , 'following' ] ) || account . getIn ( [ 'relationship' , 'requested' ] ) ) {
2017-10-30 00:10:15 +09:00
if ( unfollowModal ) {
2017-07-19 00:14:43 +09: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-31 05:40:55 +09:00
} else {
dispatch ( followAccount ( account . get ( 'id' ) ) ) ;
}
} ,
2022-10-07 17:14:31 +09:00
onInteractionModal ( account ) {
dispatch ( openModal ( 'INTERACTION' , {
type : 'follow' ,
accountId : account . get ( 'id' ) ,
url : account . get ( 'url' ) ,
} ) ) ;
} ,
2017-01-31 05:40:55 +09:00
onBlock ( account ) {
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
dispatch ( unblockAccount ( account . get ( 'id' ) ) ) ;
} else {
2019-09-30 04:46:05 +09:00
dispatch ( initBlockModal ( account ) ) ;
2017-01-31 05:40:55 +09:00
}
} ,
onMention ( account , router ) {
dispatch ( mentionCompose ( account , router ) ) ;
2017-02-15 04:59:26 +09:00
} ,
2018-03-30 02:08:34 +09: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 23:00:35 +09:00
onReblogToggle ( account ) {
2017-12-07 11:37:31 +09:00
if ( account . getIn ( [ 'relationship' , 'showing_reblogs' ] ) ) {
2020-09-19 00:26:45 +09:00
dispatch ( followAccount ( account . get ( 'id' ) , { reblogs : false } ) ) ;
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 23:00:35 +09:00
} else {
2020-09-19 00:26:45 +09:00
dispatch ( followAccount ( account . get ( 'id' ) , { reblogs : true } ) ) ;
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 23:00:35 +09:00
}
} ,
2018-08-09 16:56:53 +09:00
onEndorseToggle ( account ) {
if ( account . getIn ( [ 'relationship' , 'endorsed' ] ) ) {
dispatch ( unpinAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( pinAccount ( account . get ( 'id' ) ) ) ;
}
} ,
2020-09-19 00:26:45 +09:00
onNotifyToggle ( account ) {
if ( account . getIn ( [ 'relationship' , 'notifying' ] ) ) {
dispatch ( followAccount ( account . get ( 'id' ) , { notify : false } ) ) ;
} else {
dispatch ( followAccount ( account . get ( 'id' ) , { notify : true } ) ) ;
}
} ,
2017-02-15 04:59:26 +09:00
onReport ( account ) {
dispatch ( initReport ( account ) ) ;
2017-02-06 10:51:56 +09:00
} ,
onMute ( account ) {
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
dispatch ( unmuteAccount ( account . get ( 'id' ) ) ) ;
} else {
2017-11-15 11:56:41 +09:00
dispatch ( initMuteModal ( account ) ) ;
2017-02-06 10:51:56 +09:00
}
2017-05-20 04:05:32 +09:00
} ,
2018-03-30 19:38:00 +09:00
onBlockDomain ( domain ) {
2017-05-20 04:05:32 +09:00
dispatch ( openModal ( 'CONFIRM' , {
2018-06-10 05:46:54 +09: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-20 04:05:32 +09:00
confirm : intl . formatMessage ( messages . blockDomainConfirm ) ,
2018-03-30 19:38:00 +09:00
onConfirm : ( ) => dispatch ( blockDomain ( domain ) ) ,
2017-05-20 04:05:32 +09:00
} ) ) ;
} ,
2018-03-30 19:38:00 +09:00
onUnblockDomain ( domain ) {
dispatch ( unblockDomain ( domain ) ) ;
2017-05-21 00:31:47 +09:00
} ,
2017-07-19 00:14:43 +09:00
2022-09-21 06:51:21 +09:00
onAddToList ( account ) {
2018-11-06 02:52:38 +09:00
dispatch ( openModal ( 'LIST_ADDER' , {
accountId : account . get ( 'id' ) ,
} ) ) ;
} ,
2022-09-21 06:51:21 +09:00
onChangeLanguages ( account ) {
dispatch ( openModal ( 'SUBSCRIBED_LANGUAGES' , {
accountId : account . get ( 'id' ) ,
} ) ) ;
} ,
2017-01-31 05:40:55 +09:00
} ) ;
2017-04-23 11:39:50 +09:00
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Header ) ) ;