2018-05-26 02:46:28 +10:00
import Immutable from 'immutable' ;
2017-05-03 10:04:16 +10:00
import React from 'react' ;
2017-02-18 12:37:59 +11:00
import { connect } from 'react-redux' ;
2017-04-22 04:05:35 +10:00
import PropTypes from 'prop-types' ;
2017-11-08 00:24:55 +11:00
import classNames from 'classnames' ;
2017-02-18 12:37:59 +11:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2019-07-03 00:03:54 +10:00
import { createSelector } from 'reselect' ;
2017-02-18 12:37:59 +11:00
import { fetchStatus } from '../../actions/statuses' ;
2017-02-27 09:06:27 +11:00
import MissingIndicator from '../../components/missing_indicator' ;
2017-02-18 12:37:59 +11:00
import DetailedStatus from './components/detailed_status' ;
import ActionBar from './components/action_bar' ;
import Column from '../ui/components/column' ;
import {
favourite ,
unfavourite ,
2019-11-14 09:02:10 +11:00
bookmark ,
unbookmark ,
2017-02-18 12:37:59 +11:00
reblog ,
2017-05-21 01:31:47 +10:00
unreblog ,
2017-08-25 09:41:18 +10:00
pin ,
unpin ,
2017-02-18 12:37:59 +11:00
} from '../../actions/interactions' ;
2016-10-25 02:11:02 +11:00
import {
replyCompose ,
2017-05-21 01:31:47 +10:00
mentionCompose ,
2018-04-10 01:09:11 +10:00
directCompose ,
2017-02-18 12:37:59 +11:00
} from '../../actions/compose' ;
2018-03-11 19:52:59 +11:00
import {
muteStatus ,
unmuteStatus ,
deleteStatus ,
hideStatus ,
revealStatus ,
} from '../../actions/statuses' ;
2019-11-20 07:24:16 +11:00
import {
unblockAccount ,
unmuteAccount ,
} from '../../actions/accounts' ;
import {
blockDomain ,
unblockDomain ,
} from '../../actions/domain_blocks' ;
2017-12-26 06:56:05 +11:00
import { initMuteModal } from '../../actions/mutes' ;
2019-09-30 05:46:05 +10:00
import { initBlockModal } from '../../actions/blocks' ;
2017-02-15 06:59:26 +11:00
import { initReport } from '../../actions/reports' ;
2017-06-24 00:05:04 +10:00
import { makeGetStatus } from '../../selectors' ;
2017-11-01 08:58:38 +11:00
import { ScrollContainer } from 'react-router-scroll-4' ;
2017-02-18 12:37:59 +11:00
import ColumnBackButton from '../../components/column_back_button' ;
2018-03-11 19:52:59 +11:00
import ColumnHeader from '../../components/column_header' ;
2017-02-18 12:37:59 +11:00
import StatusContainer from '../../containers/status_container' ;
2017-04-02 06:11:28 +10:00
import { openModal } from '../../actions/modal' ;
2019-11-20 07:24:16 +11:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2017-05-03 10:04:16 +10:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2017-10-06 10:07:59 +11:00
import { HotKeys } from 'react-hotkeys' ;
2019-05-26 21:48:16 +10:00
import { boostModal , deleteModal } from '../../initial_state' ;
2018-07-30 00:52:06 +10:00
import { attachFullscreenListener , detachFullscreenListener , isFullscreen } from '../ui/util/fullscreen' ;
2019-05-26 21:48:16 +10:00
import { textForScreenReader , defaultMediaVisibility } from '../../components/status' ;
2019-02-01 10:14:05 +11:00
import Icon from 'mastodon/components/icon' ;
2017-04-23 12:39:50 +10:00
const messages = defineMessages ( {
deleteConfirm : { id : 'confirmations.delete.confirm' , defaultMessage : 'Delete' } ,
2017-05-21 01:31:47 +10:00
deleteMessage : { id : 'confirmations.delete.message' , defaultMessage : 'Are you sure you want to delete this status?' } ,
2018-06-05 08:17:38 +10:00
redraftConfirm : { id : 'confirmations.redraft.confirm' , defaultMessage : 'Delete & redraft' } ,
2018-08-25 21:27:56 +10:00
redraftMessage : { id : 'confirmations.redraft.message' , defaultMessage : 'Are you sure you want to delete this status and re-draft it? Favourites and boosts will be lost, and replies to the original post will be orphaned.' } ,
2018-03-11 19:52:59 +11:00
revealAll : { id : 'status.show_more_all' , defaultMessage : 'Show more for all' } ,
hideAll : { id : 'status.show_less_all' , defaultMessage : 'Show less for all' } ,
2018-08-24 01:26:21 +10:00
detailedStatus : { id : 'status.detailed_status' , defaultMessage : 'Detailed conversation view' } ,
2018-10-06 02:44:44 +10:00
replyConfirm : { id : 'confirmations.reply.confirm' , defaultMessage : 'Reply' } ,
replyMessage : { id : 'confirmations.reply.message' , defaultMessage : 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' } ,
2019-11-20 07:24:16 +11:00
blockDomainConfirm : { id : 'confirmations.domain_block.confirm' , defaultMessage : 'Hide entire domain' } ,
2017-04-23 12:39:50 +10:00
} ) ;
2016-09-16 08:21:51 +10:00
2016-10-25 02:11:02 +11:00
const makeMapStateToProps = ( ) => {
const getStatus = makeGetStatus ( ) ;
2019-07-03 00:03:54 +10:00
const getAncestorsIds = createSelector ( [
( _ , { id } ) => id ,
state => state . getIn ( [ 'contexts' , 'inReplyTos' ] ) ,
] , ( statusId , inReplyTos ) => {
2018-05-26 02:46:28 +10:00
let ancestorsIds = Immutable . List ( ) ;
2019-07-03 00:03:54 +10:00
ancestorsIds = ancestorsIds . withMutations ( mutable => {
let id = statusId ;
while ( id ) {
mutable . unshift ( id ) ;
id = inReplyTos . get ( id ) ;
}
} ) ;
return ancestorsIds ;
} ) ;
const getDescendantsIds = createSelector ( [
( _ , { id } ) => id ,
state => state . getIn ( [ 'contexts' , 'replies' ] ) ,
2019-08-30 09:57:38 +10:00
state => state . get ( 'statuses' ) ,
] , ( statusId , contextReplies , statuses ) => {
let descendantsIds = [ ] ;
const ids = [ statusId ] ;
2018-05-26 02:46:28 +10:00
2019-08-30 09:57:38 +10:00
while ( ids . length > 0 ) {
let id = ids . shift ( ) ;
const replies = contextReplies . get ( id ) ;
2018-05-26 02:46:28 +10:00
2019-08-30 09:57:38 +10:00
if ( statusId !== id ) {
descendantsIds . push ( id ) ;
}
2018-05-26 02:46:28 +10:00
2019-08-30 09:57:38 +10:00
if ( replies ) {
replies . reverse ( ) . forEach ( reply => {
ids . unshift ( reply ) ;
} ) ;
2019-07-03 00:03:54 +10:00
}
2019-08-30 09:57:38 +10:00
}
let insertAt = descendantsIds . findIndex ( ( id ) => statuses . get ( id ) . get ( 'in_reply_to_account_id' ) !== statuses . get ( id ) . get ( 'account' ) ) ;
if ( insertAt !== - 1 ) {
descendantsIds . forEach ( ( id , idx ) => {
if ( idx > insertAt && statuses . get ( id ) . get ( 'in_reply_to_account_id' ) === statuses . get ( id ) . get ( 'account' ) ) {
descendantsIds . splice ( idx , 1 ) ;
descendantsIds . splice ( insertAt , 0 , id ) ;
insertAt += 1 ;
}
} ) ;
}
2018-05-28 10:42:06 +10:00
2019-08-30 09:57:38 +10:00
return Immutable . List ( descendantsIds ) ;
2019-07-03 00:03:54 +10:00
} ) ;
2018-05-26 02:46:28 +10:00
2019-07-03 00:03:54 +10:00
const mapStateToProps = ( state , props ) => {
const status = getStatus ( state , { id : props . params . statusId } ) ;
let ancestorsIds = Immutable . List ( ) ;
let descendantsIds = Immutable . List ( ) ;
2018-06-04 12:19:16 +10:00
2019-07-03 00:03:54 +10:00
if ( status ) {
ancestorsIds = getAncestorsIds ( state , { id : status . get ( 'in_reply_to_id' ) } ) ;
descendantsIds = getDescendantsIds ( state , { id : status . get ( 'id' ) } ) ;
2018-05-26 02:46:28 +10:00
}
return {
status ,
ancestorsIds ,
descendantsIds ,
2018-10-06 02:44:44 +10:00
askReplyConfirmation : state . getIn ( [ 'compose' , 'text' ] ) . trim ( ) . length !== 0 ,
2019-01-18 00:06:08 +11:00
domain : state . getIn ( [ 'meta' , 'domain' ] ) ,
2018-05-26 02:46:28 +10:00
} ;
} ;
2016-10-25 02:11:02 +11:00
return mapStateToProps ;
} ;
2016-09-16 08:21:51 +10:00
2018-09-15 01:59:48 +10:00
export default @ injectIntl
2017-06-24 03:36:54 +10:00
@ connect ( makeMapStateToProps )
2018-09-15 01:59:48 +10:00
class Status extends ImmutablePureComponent {
2017-04-22 04:05:35 +10:00
2017-05-12 22:44:10 +10:00
static contextTypes = {
2017-05-21 01:31:47 +10:00
router : PropTypes . object ,
2017-05-12 22:44:10 +10:00
} ;
static propTypes = {
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
status : ImmutablePropTypes . map ,
ancestorsIds : ImmutablePropTypes . list ,
descendantsIds : ImmutablePropTypes . list ,
2017-05-21 01:31:47 +10:00
intl : PropTypes . object . isRequired ,
2018-10-06 02:44:44 +10:00
askReplyConfirmation : PropTypes . bool ,
2019-08-01 20:26:58 +10:00
multiColumn : PropTypes . bool ,
2019-01-18 00:06:08 +11:00
domain : PropTypes . string . isRequired ,
2017-05-12 22:44:10 +10:00
} ;
2016-09-16 08:21:51 +10:00
2017-11-08 00:24:55 +11:00
state = {
fullscreen : false ,
2019-05-26 21:48:16 +10:00
showMedia : defaultMediaVisibility ( this . props . status ) ,
2019-05-30 00:33:15 +10:00
loadedStatusId : undefined ,
2017-11-08 00:24:55 +11:00
} ;
2016-09-16 08:21:51 +10:00
componentWillMount ( ) {
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
this . props . dispatch ( fetchStatus ( this . props . params . statusId ) ) ;
2017-04-22 04:05:35 +10:00
}
2016-09-16 08:21:51 +10:00
2017-11-08 00:24:55 +11:00
componentDidMount ( ) {
attachFullscreenListener ( this . onFullScreenChange ) ;
}
2016-09-16 08:21:51 +10:00
componentWillReceiveProps ( nextProps ) {
if ( nextProps . params . statusId !== this . props . params . statusId && nextProps . params . statusId ) {
2017-10-12 04:21:44 +11:00
this . _scrolledIntoView = false ;
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
this . props . dispatch ( fetchStatus ( nextProps . params . statusId ) ) ;
2016-09-16 08:21:51 +10:00
}
2019-05-26 21:48:16 +10:00
2019-05-30 00:33:15 +10:00
if ( nextProps . status && nextProps . status . get ( 'id' ) !== this . state . loadedStatusId ) {
this . setState ( { showMedia : defaultMediaVisibility ( nextProps . status ) , loadedStatusId : nextProps . status . get ( 'id' ) } ) ;
2019-05-26 07:20:51 +10:00
}
}
handleToggleMediaVisibility = ( ) => {
this . setState ( { showMedia : ! this . state . showMedia } ) ;
2017-04-22 04:05:35 +10:00
}
2016-09-16 08:21:51 +10:00
2017-05-12 22:44:10 +10:00
handleFavouriteClick = ( status ) => {
2017-02-17 12:33:10 +11:00
if ( status . get ( 'favourited' ) ) {
this . props . dispatch ( unfavourite ( status ) ) ;
} else {
this . props . dispatch ( favourite ( status ) ) ;
}
2017-04-22 04:05:35 +10:00
}
2016-09-18 01:47:26 +10:00
2017-08-25 09:41:18 +10:00
handlePin = ( status ) => {
if ( status . get ( 'pinned' ) ) {
this . props . dispatch ( unpin ( status ) ) ;
} else {
this . props . dispatch ( pin ( status ) ) ;
}
}
2017-05-12 22:44:10 +10:00
handleReplyClick = ( status ) => {
2018-10-06 02:44:44 +10:00
let { askReplyConfirmation , dispatch , intl } = this . props ;
if ( askReplyConfirmation ) {
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( messages . replyMessage ) ,
confirm : intl . formatMessage ( messages . replyConfirm ) ,
onConfirm : ( ) => dispatch ( replyCompose ( status , this . context . router . history ) ) ,
} ) ) ;
} else {
dispatch ( replyCompose ( status , this . context . router . history ) ) ;
}
2017-04-22 04:05:35 +10:00
}
2016-09-18 01:47:26 +10:00
2017-05-12 22:44:10 +10:00
handleModalReblog = ( status ) => {
2017-04-11 12:28:52 +10:00
this . props . dispatch ( reblog ( status ) ) ;
2017-04-22 04:05:35 +10:00
}
2017-04-11 12:28:52 +10:00
2017-05-12 22:44:10 +10:00
handleReblogClick = ( status , e ) => {
2017-02-17 12:33:10 +11:00
if ( status . get ( 'reblogged' ) ) {
this . props . dispatch ( unreblog ( status ) ) ;
} else {
2018-10-19 04:52:00 +11:00
if ( ( e && e . shiftKey ) || ! boostModal ) {
2017-04-11 22:34:14 +10:00
this . handleModalReblog ( status ) ;
} else {
this . props . dispatch ( openModal ( 'BOOST' , { status , onReblog : this . handleModalReblog } ) ) ;
}
2017-02-17 12:33:10 +11:00
}
2017-04-22 04:05:35 +10:00
}
2016-09-18 01:47:26 +10:00
2019-11-14 09:02:10 +11:00
handleBookmarkClick = ( status ) => {
if ( status . get ( 'bookmarked' ) ) {
this . props . dispatch ( unbookmark ( status ) ) ;
} else {
this . props . dispatch ( bookmark ( status ) ) ;
}
}
2018-08-19 11:17:01 +10:00
handleDeleteClick = ( status , history , withRedraft = false ) => {
2017-04-23 12:39:50 +10:00
const { dispatch , intl } = this . props ;
2017-10-30 02:10:15 +11:00
if ( ! deleteModal ) {
2018-08-19 11:17:01 +10:00
dispatch ( deleteStatus ( status . get ( 'id' ) , history , withRedraft ) ) ;
2017-05-30 01:56:13 +10:00
} else {
dispatch ( openModal ( 'CONFIRM' , {
2018-06-05 08:17:38 +10:00
message : intl . formatMessage ( withRedraft ? messages . redraftMessage : messages . deleteMessage ) ,
confirm : intl . formatMessage ( withRedraft ? messages . redraftConfirm : messages . deleteConfirm ) ,
2018-08-19 11:17:01 +10:00
onConfirm : ( ) => dispatch ( deleteStatus ( status . get ( 'id' ) , history , withRedraft ) ) ,
2017-05-30 01:56:13 +10:00
} ) ) ;
}
2017-04-22 04:05:35 +10:00
}
2016-10-10 07:19:15 +11:00
2018-04-10 01:09:11 +10:00
handleDirectClick = ( account , router ) => {
this . props . dispatch ( directCompose ( account , router ) ) ;
}
2017-05-12 22:44:10 +10:00
handleMentionClick = ( account , router ) => {
2017-01-31 07:40:55 +11:00
this . props . dispatch ( mentionCompose ( account , router ) ) ;
2017-04-22 04:05:35 +10:00
}
2016-10-25 02:11:02 +11:00
2017-05-12 22:44:10 +10:00
handleOpenMedia = ( media , index ) => {
2017-04-02 06:11:28 +10:00
this . props . dispatch ( openModal ( 'MEDIA' , { media , index } ) ) ;
2017-04-22 04:05:35 +10:00
}
2016-10-25 03:07:40 +11:00
2020-04-25 20:16:05 +10:00
handleOpenVideo = ( media , options ) => {
this . props . dispatch ( openModal ( 'VIDEO' , { media , options } ) ) ;
2017-04-22 04:05:35 +10:00
}
2017-04-13 23:04:18 +10:00
2019-11-30 03:02:36 +11:00
handleHotkeyOpenMedia = e => {
2019-12-05 10:50:51 +11:00
const status = this . _properStatus ( ) ;
2019-11-30 03:02:36 +11:00
e . preventDefault ( ) ;
if ( status . get ( 'media_attachments' ) . size > 0 ) {
if ( status . getIn ( [ 'media_attachments' , 0 , 'type' ] ) === 'audio' ) {
// TODO: toggle play/paused?
} else if ( status . getIn ( [ 'media_attachments' , 0 , 'type' ] ) === 'video' ) {
2020-04-25 20:16:05 +10:00
this . handleOpenVideo ( status . getIn ( [ 'media_attachments' , 0 ] ) , { startTime : 0 } ) ;
2019-11-30 03:02:36 +11:00
} else {
this . handleOpenMedia ( status . get ( 'media_attachments' ) , 0 ) ;
}
}
}
2017-12-26 06:56:05 +11:00
handleMuteClick = ( account ) => {
this . props . dispatch ( initMuteModal ( account ) ) ;
}
handleConversationMuteClick = ( status ) => {
if ( status . get ( 'muted' ) ) {
this . props . dispatch ( unmuteStatus ( status . get ( 'id' ) ) ) ;
} else {
this . props . dispatch ( muteStatus ( status . get ( 'id' ) ) ) ;
}
}
2018-03-11 19:52:59 +11:00
handleToggleHidden = ( status ) => {
if ( status . get ( 'hidden' ) ) {
this . props . dispatch ( revealStatus ( status . get ( 'id' ) ) ) ;
} else {
this . props . dispatch ( hideStatus ( status . get ( 'id' ) ) ) ;
}
}
handleToggleAll = ( ) => {
const { status , ancestorsIds , descendantsIds } = this . props ;
const statusIds = [ status . get ( 'id' ) ] . concat ( ancestorsIds . toJS ( ) , descendantsIds . toJS ( ) ) ;
if ( status . get ( 'hidden' ) ) {
this . props . dispatch ( revealStatus ( statusIds ) ) ;
} else {
this . props . dispatch ( hideStatus ( statusIds ) ) ;
}
}
2019-03-27 03:34:02 +11:00
handleBlockClick = ( status ) => {
2019-09-30 05:46:05 +10:00
const { dispatch } = this . props ;
2019-03-27 03:34:02 +11:00
const account = status . get ( 'account' ) ;
2019-09-30 05:46:05 +10:00
dispatch ( initBlockModal ( account ) ) ;
2017-12-26 06:56:05 +11:00
}
2017-05-12 22:44:10 +10:00
handleReport = ( status ) => {
2017-02-15 06:59:26 +11:00
this . props . dispatch ( initReport ( status . get ( 'account' ) , status ) ) ;
2017-04-22 04:05:35 +10:00
}
2017-02-15 06:59:26 +11:00
2017-08-31 11:38:35 +10:00
handleEmbed = ( status ) => {
this . props . dispatch ( openModal ( 'EMBED' , { url : status . get ( 'url' ) } ) ) ;
}
2019-11-20 07:24:16 +11:00
handleUnmuteClick = account => {
this . props . dispatch ( unmuteAccount ( account . get ( 'id' ) ) ) ;
}
handleUnblockClick = account => {
this . props . dispatch ( unblockAccount ( account . get ( 'id' ) ) ) ;
}
handleBlockDomainClick = domain => {
this . props . dispatch ( openModal ( 'CONFIRM' , {
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 : this . props . intl . formatMessage ( messages . blockDomainConfirm ) ,
onConfirm : ( ) => this . props . dispatch ( blockDomain ( domain ) ) ,
} ) ) ;
}
handleUnblockDomainClick = domain => {
this . props . dispatch ( unblockDomain ( domain ) ) ;
}
2017-10-06 10:07:59 +11:00
handleHotkeyMoveUp = ( ) => {
this . handleMoveUp ( this . props . status . get ( 'id' ) ) ;
}
handleHotkeyMoveDown = ( ) => {
this . handleMoveDown ( this . props . status . get ( 'id' ) ) ;
}
handleHotkeyReply = e => {
e . preventDefault ( ) ;
this . handleReplyClick ( this . props . status ) ;
}
handleHotkeyFavourite = ( ) => {
this . handleFavouriteClick ( this . props . status ) ;
}
handleHotkeyBoost = ( ) => {
this . handleReblogClick ( this . props . status ) ;
}
handleHotkeyMention = e => {
e . preventDefault ( ) ;
2018-07-03 10:17:18 +10:00
this . handleMentionClick ( this . props . status . get ( 'account' ) ) ;
2017-10-06 10:07:59 +11:00
}
handleHotkeyOpenProfile = ( ) => {
this . context . router . history . push ( ` /accounts/ ${ this . props . status . getIn ( [ 'account' , 'id' ] ) } ` ) ;
}
2018-04-18 11:33:59 +10:00
handleHotkeyToggleHidden = ( ) => {
this . handleToggleHidden ( this . props . status ) ;
}
2019-05-26 07:20:51 +10:00
handleHotkeyToggleSensitive = ( ) => {
this . handleToggleMediaVisibility ( ) ;
}
2017-10-06 10:07:59 +11:00
handleMoveUp = id => {
const { status , ancestorsIds , descendantsIds } = this . props ;
if ( id === status . get ( 'id' ) ) {
2019-05-03 14:20:36 +10:00
this . _selectChild ( ancestorsIds . size - 1 , true ) ;
2017-10-06 10:07:59 +11:00
} else {
let index = ancestorsIds . indexOf ( id ) ;
if ( index === - 1 ) {
index = descendantsIds . indexOf ( id ) ;
2019-05-03 14:20:36 +10:00
this . _selectChild ( ancestorsIds . size + index , true ) ;
2017-10-06 10:07:59 +11:00
} else {
2019-05-03 14:20:36 +10:00
this . _selectChild ( index - 1 , true ) ;
2017-10-06 10:07:59 +11:00
}
}
}
handleMoveDown = id => {
const { status , ancestorsIds , descendantsIds } = this . props ;
if ( id === status . get ( 'id' ) ) {
2019-05-03 14:20:36 +10:00
this . _selectChild ( ancestorsIds . size + 1 , false ) ;
2017-10-06 10:07:59 +11:00
} else {
let index = ancestorsIds . indexOf ( id ) ;
if ( index === - 1 ) {
index = descendantsIds . indexOf ( id ) ;
2019-05-03 14:20:36 +10:00
this . _selectChild ( ancestorsIds . size + index + 2 , false ) ;
2017-10-06 10:07:59 +11:00
} else {
2019-05-03 14:20:36 +10:00
this . _selectChild ( index + 1 , false ) ;
2017-10-06 10:07:59 +11:00
}
}
}
2019-05-03 14:20:36 +10:00
_selectChild ( index , align _top ) {
const container = this . node ;
const element = container . querySelectorAll ( '.focusable' ) [ index ] ;
2017-10-06 10:07:59 +11:00
if ( element ) {
2019-05-03 14:20:36 +10:00
if ( align _top && container . scrollTop > element . offsetTop ) {
element . scrollIntoView ( true ) ;
} else if ( ! align _top && container . scrollTop + container . clientHeight < element . offsetTop + element . offsetHeight ) {
element . scrollIntoView ( false ) ;
}
2017-10-06 10:07:59 +11:00
element . focus ( ) ;
}
}
2016-09-16 08:21:51 +10:00
renderChildren ( list ) {
2017-10-06 10:07:59 +11:00
return list . map ( id => (
< StatusContainer
key = { id }
id = { id }
onMoveUp = { this . handleMoveUp }
onMoveDown = { this . handleMoveDown }
2018-06-29 23:34:36 +10:00
contextType = 'thread'
2017-10-06 10:07:59 +11:00
/ >
) ) ;
}
setRef = c => {
this . node = c ;
}
componentDidUpdate ( ) {
2017-10-12 04:21:44 +11:00
if ( this . _scrolledIntoView ) {
return ;
}
2017-10-11 20:25:15 +11:00
const { status , ancestorsIds } = this . props ;
2017-10-06 10:07:59 +11:00
2017-10-11 20:25:15 +11:00
if ( status && ancestorsIds && ancestorsIds . size > 0 ) {
2017-10-12 04:21:44 +11:00
const element = this . node . querySelectorAll ( '.focusable' ) [ ancestorsIds . size - 1 ] ;
2018-08-17 22:07:38 +10:00
window . requestAnimationFrame ( ( ) => {
element . scrollIntoView ( true ) ;
} ) ;
2017-10-12 04:21:44 +11:00
this . _scrolledIntoView = true ;
2017-10-06 10:07:59 +11:00
}
2017-04-22 04:05:35 +10:00
}
2016-09-16 08:21:51 +10:00
2017-11-08 00:24:55 +11:00
componentWillUnmount ( ) {
detachFullscreenListener ( this . onFullScreenChange ) ;
}
onFullScreenChange = ( ) => {
this . setState ( { fullscreen : isFullscreen ( ) } ) ;
}
2016-09-16 08:21:51 +10:00
render ( ) {
2016-10-25 02:11:02 +11:00
let ancestors , descendants ;
2019-08-01 20:26:58 +10:00
const { shouldUpdateScroll , status , ancestorsIds , descendantsIds , intl , domain , multiColumn } = this . props ;
2017-11-08 00:24:55 +11:00
const { fullscreen } = this . state ;
2016-09-16 08:21:51 +10:00
if ( status === null ) {
2016-10-08 01:00:11 +11:00
return (
< Column >
2019-08-01 20:26:58 +10:00
< ColumnBackButton multiColumn = { multiColumn } / >
2017-02-27 09:06:27 +11:00
< MissingIndicator / >
2016-10-08 01:00:11 +11:00
< / C o l u m n >
) ;
2016-09-16 08:21:51 +10:00
}
2016-10-31 01:06:43 +11:00
if ( ancestorsIds && ancestorsIds . size > 0 ) {
2016-10-25 02:11:02 +11:00
ancestors = < div > { this . renderChildren ( ancestorsIds ) } < / d i v > ;
}
2016-10-31 01:06:43 +11:00
if ( descendantsIds && descendantsIds . size > 0 ) {
2016-10-25 02:11:02 +11:00
descendants = < div > { this . renderChildren ( descendantsIds ) } < / d i v > ;
}
2017-10-06 10:07:59 +11:00
const handlers = {
moveUp : this . handleHotkeyMoveUp ,
moveDown : this . handleHotkeyMoveDown ,
reply : this . handleHotkeyReply ,
favourite : this . handleHotkeyFavourite ,
boost : this . handleHotkeyBoost ,
mention : this . handleHotkeyMention ,
openProfile : this . handleHotkeyOpenProfile ,
2018-04-18 11:33:59 +10:00
toggleHidden : this . handleHotkeyToggleHidden ,
2019-05-26 07:20:51 +10:00
toggleSensitive : this . handleHotkeyToggleSensitive ,
2019-11-30 03:02:36 +11:00
openMedia : this . handleHotkeyOpenMedia ,
2017-10-06 10:07:59 +11:00
} ;
2016-09-16 08:21:51 +10:00
return (
2019-08-02 03:17:17 +10:00
< Column bindToDocument = { ! multiColumn } label = { intl . formatMessage ( messages . detailedStatus ) } >
2018-03-11 19:52:59 +11:00
< ColumnHeader
showBackButton
2019-08-01 20:26:58 +10:00
multiColumn = { multiColumn }
2018-03-11 19:52:59 +11:00
extraButton = { (
2019-02-01 10:14:05 +11:00
< button className = 'column-header__button' title = { intl . formatMessage ( status . get ( 'hidden' ) ? messages . revealAll : messages . hideAll ) } aria - label = { intl . formatMessage ( status . get ( 'hidden' ) ? messages . revealAll : messages . hideAll ) } onClick = { this . handleToggleAll } aria - pressed = { status . get ( 'hidden' ) ? 'false' : 'true' } > < Icon id = { status . get ( 'hidden' ) ? 'eye-slash' : 'eye' } / > < / b u t t o n >
2018-03-11 19:52:59 +11:00
) }
/ >
2016-09-18 21:03:37 +10:00
2018-07-30 00:52:06 +10:00
< ScrollContainer scrollKey = 'thread' shouldUpdateScroll = { shouldUpdateScroll } >
2018-10-30 16:33:02 +11:00
< div className = { classNames ( 'scrollable' , { fullscreen } ) } ref = { this . setRef } >
2016-10-25 02:11:02 +11:00
{ ancestors }
2016-09-18 21:03:37 +10:00
2017-10-06 10:07:59 +11:00
< HotKeys handlers = { handlers } >
2019-04-06 14:02:03 +11:00
< div className = { classNames ( 'focusable' , 'detailed-status__wrapper' ) } tabIndex = '0' aria - label = { textForScreenReader ( intl , status , false ) } >
2017-10-06 10:07:59 +11:00
< DetailedStatus
2020-01-07 04:22:17 +11:00
key = { ` details- ${ status . get ( 'id' ) } ` }
2017-10-06 10:07:59 +11:00
status = { status }
onOpenVideo = { this . handleOpenVideo }
onOpenMedia = { this . handleOpenMedia }
2018-03-11 19:52:59 +11:00
onToggleHidden = { this . handleToggleHidden }
2019-01-18 00:06:08 +11:00
domain = { domain }
2019-05-26 07:20:51 +10:00
showMedia = { this . state . showMedia }
onToggleMediaVisibility = { this . handleToggleMediaVisibility }
2017-10-06 10:07:59 +11:00
/ >
< ActionBar
2020-01-07 04:22:17 +11:00
key = { ` action-bar- ${ status . get ( 'id' ) } ` }
2017-10-06 10:07:59 +11:00
status = { status }
onReply = { this . handleReplyClick }
onFavourite = { this . handleFavouriteClick }
onReblog = { this . handleReblogClick }
2019-11-14 09:02:10 +11:00
onBookmark = { this . handleBookmarkClick }
2017-10-06 10:07:59 +11:00
onDelete = { this . handleDeleteClick }
2018-04-10 01:09:11 +10:00
onDirect = { this . handleDirectClick }
2017-10-06 10:07:59 +11:00
onMention = { this . handleMentionClick }
2017-12-26 06:56:05 +11:00
onMute = { this . handleMuteClick }
2019-11-20 07:24:16 +11:00
onUnmute = { this . handleUnmuteClick }
2017-12-26 06:56:05 +11:00
onMuteConversation = { this . handleConversationMuteClick }
onBlock = { this . handleBlockClick }
2019-11-20 07:24:16 +11:00
onUnblock = { this . handleUnblockClick }
onBlockDomain = { this . handleBlockDomainClick }
onUnblockDomain = { this . handleUnblockDomainClick }
2017-10-06 10:07:59 +11:00
onReport = { this . handleReport }
onPin = { this . handlePin }
onEmbed = { this . handleEmbed }
/ >
< / d i v >
< / H o t K e y s >
2016-10-20 03:20:19 +11:00
2016-10-25 02:11:02 +11:00
{ descendants }
2016-10-20 03:20:19 +11:00
< / d i v >
< / S c r o l l C o n t a i n e r >
2016-10-08 01:00:11 +11:00
< / C o l u m n >
2016-09-16 08:21:51 +10:00
) ;
}
2017-04-22 04:05:35 +10:00
}