2023-05-24 01:15:17 +10:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2017-01-31 07:40:55 +11:00
import { connect } from 'react-redux' ;
2023-05-24 01:15:17 +10:00
import { openURL } from 'mastodon/actions/search' ;
2017-01-31 07:40:55 +11:00
import {
followAccount ,
unfollowAccount ,
2017-02-06 12:51:56 +11:00
unblockAccount ,
2017-05-21 01:31:47 +10:00
unmuteAccount ,
2018-08-09 17:56:53 +10:00
pinAccount ,
unpinAccount ,
2017-01-31 07:40:55 +11:00
} from '../../../actions/accounts' ;
2023-05-24 01:15:17 +10:00
import { initBlockModal } from '../../../actions/blocks' ;
2018-03-30 04:08:34 +11:00
import {
mentionCompose ,
directCompose ,
} from '../../../actions/compose' ;
2023-05-24 01:15:17 +10:00
import { blockDomain , unblockDomain } from '../../../actions/domain_blocks' ;
import { openModal } from '../../../actions/modal' ;
2017-11-15 13:56:41 +11:00
import { initMuteModal } from '../../../actions/mutes' ;
2017-02-15 06:59:26 +11:00
import { initReport } from '../../../actions/reports' ;
2017-10-30 02:10:15 +11:00
import { unfollowModal } from '../../../initial_state' ;
2023-05-24 01:15:17 +10:00
import { makeGetAccount , getAccountHidden } from '../../../selectors' ;
import Header from '../components/header' ;
2017-04-23 12:39:50 +10:00
const messages = defineMessages ( {
2022-10-19 09:12:55 +11:00
cancelFollowRequestConfirm : { id : 'confirmations.cancel_follow_request.confirm' , defaultMessage : 'Withdraw request' } ,
2017-07-19 01:14:43 +10:00
unfollowConfirm : { id : 'confirmations.unfollow.confirm' , defaultMessage : 'Unfollow' } ,
2023-05-24 20:38:50 +10:00
blockDomainConfirm : { id : 'confirmations.domain_block.confirm' , defaultMessage : 'Block entire domain' } ,
2017-04-23 12:39:50 +10:00
} ) ;
2017-01-31 07:40:55 +11: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 22:53:48 +10:00
account : getAccount ( state , accountId ) ,
2019-03-26 10:36:25 +11:00
domain : state . getIn ( [ 'meta' , 'domain' ] ) ,
2022-05-10 17:44:35 +10:00
hidden : getAccountHidden ( state , accountId ) ,
2017-01-31 07:40:55 +11:00
} ) ;
return mapStateToProps ;
} ;
2017-04-23 12:39:50 +10:00
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
2017-07-19 01:14:43 +10:00
2017-01-31 07:40:55 +11:00
onFollow ( account ) {
2022-10-19 09:12:55 +11:00
if ( account . getIn ( [ 'relationship' , 'following' ] ) ) {
2017-10-30 02:10:15 +11:00
if ( unfollowModal ) {
2023-05-25 23:42:37 +10:00
dispatch ( openModal ( {
modalType : 'CONFIRM' ,
modalProps : {
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' ) ) ) ,
} ,
2017-07-19 01:14:43 +10:00
} ) ) ;
} else {
dispatch ( unfollowAccount ( account . get ( 'id' ) ) ) ;
}
2022-10-19 09:12:55 +11:00
} else if ( account . getIn ( [ 'relationship' , 'requested' ] ) ) {
if ( unfollowModal ) {
2023-05-25 23:42:37 +10:00
dispatch ( openModal ( {
modalType : 'CONFIRM' ,
modalProps : {
message : < FormattedMessage id = 'confirmations.cancel_follow_request.message' defaultMessage = 'Are you sure you want to withdraw your request to follow {name}?' values = { { name : < strong > @ { account . get ( 'acct' ) } < / strong > } } / > ,
confirm : intl . formatMessage ( messages . cancelFollowRequestConfirm ) ,
onConfirm : ( ) => dispatch ( unfollowAccount ( account . get ( 'id' ) ) ) ,
} ,
2022-10-19 09:12:55 +11:00
} ) ) ;
2022-11-04 02:05:39 +11:00
} else {
dispatch ( unfollowAccount ( account . get ( 'id' ) ) ) ;
2022-10-19 09:12:55 +11:00
}
2017-01-31 07:40:55 +11:00
} else {
dispatch ( followAccount ( account . get ( 'id' ) ) ) ;
}
} ,
2022-10-07 19:14:31 +11:00
onInteractionModal ( account ) {
2023-05-25 23:42:37 +10:00
dispatch ( openModal ( {
modalType : 'INTERACTION' ,
modalProps : {
type : 'follow' ,
accountId : account . get ( 'id' ) ,
url : account . get ( 'url' ) ,
} ,
2022-10-07 19:14:31 +11:00
} ) ) ;
} ,
2017-01-31 07:40:55 +11:00
onBlock ( account ) {
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
dispatch ( unblockAccount ( account . get ( 'id' ) ) ) ;
} else {
2019-09-30 05:46:05 +10:00
dispatch ( initBlockModal ( account ) ) ;
2017-01-31 07:40:55 +11:00
}
} ,
onMention ( account , router ) {
dispatch ( mentionCompose ( account , router ) ) ;
2017-02-15 06:59:26 +11:00
} ,
2018-03-30 04:08:34 +11: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-29 01:00:35 +11:00
onReblogToggle ( account ) {
2017-12-07 13:37:31 +11:00
if ( account . getIn ( [ 'relationship' , 'showing_reblogs' ] ) ) {
2020-09-19 01:26:45 +10: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-29 01:00:35 +11:00
} else {
2020-09-19 01:26:45 +10: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-29 01:00:35 +11:00
}
} ,
2018-08-09 17:56:53 +10:00
onEndorseToggle ( account ) {
if ( account . getIn ( [ 'relationship' , 'endorsed' ] ) ) {
dispatch ( unpinAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( pinAccount ( account . get ( 'id' ) ) ) ;
}
} ,
2020-09-19 01:26:45 +10: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 06:59:26 +11:00
onReport ( account ) {
dispatch ( initReport ( account ) ) ;
2017-02-06 12:51:56 +11:00
} ,
onMute ( account ) {
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
dispatch ( unmuteAccount ( account . get ( 'id' ) ) ) ;
} else {
2017-11-15 13:56:41 +11:00
dispatch ( initMuteModal ( account ) ) ;
2017-02-06 12:51:56 +11:00
}
2017-05-20 05:05:32 +10:00
} ,
2018-03-30 21:38:00 +11:00
onBlockDomain ( domain ) {
2023-05-25 23:42:37 +10:00
dispatch ( openModal ( {
modalType : 'CONFIRM' ,
modalProps : {
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 > } } / > ,
confirm : intl . formatMessage ( messages . blockDomainConfirm ) ,
onConfirm : ( ) => dispatch ( blockDomain ( domain ) ) ,
} ,
2017-05-20 05:05:32 +10:00
} ) ) ;
} ,
2018-03-30 21:38:00 +11:00
onUnblockDomain ( domain ) {
dispatch ( unblockDomain ( domain ) ) ;
2017-05-21 01:31:47 +10:00
} ,
2017-07-19 01:14:43 +10:00
2022-09-21 07:51:21 +10:00
onAddToList ( account ) {
2023-05-25 23:42:37 +10:00
dispatch ( openModal ( {
modalType : 'LIST_ADDER' ,
modalProps : {
accountId : account . get ( 'id' ) ,
} ,
2018-11-06 04:52:38 +11:00
} ) ) ;
} ,
2022-09-21 07:51:21 +10:00
onChangeLanguages ( account ) {
2023-05-25 23:42:37 +10:00
dispatch ( openModal ( {
modalType : 'SUBSCRIBED_LANGUAGES' ,
modalProps : {
accountId : account . get ( 'id' ) ,
} ,
2022-09-21 07:51:21 +10:00
} ) ) ;
} ,
2022-11-10 18:49:35 +11:00
onOpenAvatar ( account ) {
2023-05-25 23:42:37 +10:00
dispatch ( openModal ( {
modalType : 'IMAGE' ,
modalProps : {
src : account . get ( 'avatar' ) ,
alt : account . get ( 'acct' ) ,
} ,
2022-11-10 18:49:35 +11:00
} ) ) ;
} ,
2023-04-25 14:33:21 +10:00
onOpenURL ( url , routerHistory , onFailure ) {
dispatch ( openURL ( url , routerHistory , onFailure ) ) ;
} ,
2017-01-31 07:40:55 +11:00
} ) ;
2017-04-23 12:39:50 +10:00
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Header ) ) ;