2017-05-03 09:04:16 +09:00
import React from 'react' ;
2017-02-18 10:37:59 +09:00
import { connect } from 'react-redux' ;
2017-04-22 03:05:35 +09:00
import PropTypes from 'prop-types' ;
2017-11-07 22:24:55 +09:00
import classNames from 'classnames' ;
2017-02-18 10:37:59 +09:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2017-12-04 16:26:40 +09:00
import { fetchStatus } from 'flavours/glitch/actions/statuses' ;
import MissingIndicator from 'flavours/glitch/components/missing_indicator' ;
2017-02-18 10:37:59 +09:00
import DetailedStatus from './components/detailed_status' ;
import ActionBar from './components/action_bar' ;
2017-12-04 16:26:40 +09:00
import Column from 'flavours/glitch/features/ui/components/column' ;
2017-02-18 10:37:59 +09:00
import {
favourite ,
unfavourite ,
2018-04-12 02:42:25 +09:00
bookmark ,
unbookmark ,
2017-02-18 10:37:59 +09:00
reblog ,
2017-05-21 00:31:47 +09:00
unreblog ,
2017-08-25 08:41:18 +09:00
pin ,
unpin ,
2017-12-04 16:26:40 +09:00
} from 'flavours/glitch/actions/interactions' ;
2016-10-25 00:11:02 +09:00
import {
replyCompose ,
2017-05-21 00:31:47 +09:00
mentionCompose ,
2018-04-11 04:38:02 +09:00
directCompose ,
2017-12-04 16:26:40 +09:00
} from 'flavours/glitch/actions/compose' ;
2017-12-27 01:41:44 +09:00
import { blockAccount } from 'flavours/glitch/actions/accounts' ;
import { muteStatus , unmuteStatus , deleteStatus } from 'flavours/glitch/actions/statuses' ;
import { initMuteModal } from 'flavours/glitch/actions/mutes' ;
2017-12-04 16:26:40 +09:00
import { initReport } from 'flavours/glitch/actions/reports' ;
import { makeGetStatus } from 'flavours/glitch/selectors' ;
2017-11-01 06:58:38 +09:00
import { ScrollContainer } from 'react-router-scroll-4' ;
2017-12-04 16:26:40 +09:00
import ColumnBackButton from 'flavours/glitch/components/column_back_button' ;
2018-03-29 02:56:46 +09:00
import ColumnHeader from '../../components/column_header' ;
2017-12-04 16:26:40 +09:00
import StatusContainer from 'flavours/glitch/containers/status_container' ;
import { openModal } from 'flavours/glitch/actions/modal' ;
2017-12-27 01:13:38 +09:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2017-05-03 09:04:16 +09:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2017-10-06 08:07:59 +09:00
import { HotKeys } from 'react-hotkeys' ;
2017-12-10 01:26:22 +09:00
import { boostModal , favouriteModal , deleteModal } from 'flavours/glitch/util/initial_state' ;
2017-12-04 16:26:40 +09:00
import { attachFullscreenListener , detachFullscreenListener , isFullscreen } from 'flavours/glitch/util/fullscreen' ;
2018-08-29 00:16:30 +09:00
import { autoUnfoldCW } from 'flavours/glitch/util/content_warning' ;
2017-04-23 11:39:50 +09:00
const messages = defineMessages ( {
deleteConfirm : { id : 'confirmations.delete.confirm' , defaultMessage : 'Delete' } ,
2017-05-21 00:31:47 +09:00
deleteMessage : { id : 'confirmations.delete.message' , defaultMessage : 'Are you sure you want to delete this status?' } ,
2018-06-16 04:29:04 +09:00
redraftConfirm : { id : 'confirmations.redraft.confirm' , defaultMessage : 'Delete & redraft' } ,
redraftMessage : { id : 'confirmations.redraft.message' , defaultMessage : 'Are you sure you want to delete this status and re-draft it? You will lose all replies, boosts and favourites to it.' } ,
2017-12-27 01:13:38 +09:00
blockConfirm : { id : 'confirmations.block.confirm' , defaultMessage : 'Block' } ,
2018-03-29 02:56:46 +09: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-28 19:01:04 +09:00
detailedStatus : { id : 'status.detailed_status' , defaultMessage : 'Detailed conversation view' } ,
2017-04-23 11:39:50 +09:00
} ) ;
2016-09-16 07:21:51 +09:00
2016-10-25 00:11:02 +09:00
const makeMapStateToProps = ( ) => {
const getStatus = makeGetStatus ( ) ;
const mapStateToProps = ( state , props ) => ( {
2018-07-09 03:04:53 +09:00
status : getStatus ( state , { id : props . params . statusId } ) ,
2017-06-30 18:15:18 +09:00
settings : state . get ( 'local_settings' ) ,
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
ancestorsIds : state . getIn ( [ 'contexts' , 'ancestors' , props . params . statusId ] ) ,
descendantsIds : state . getIn ( [ 'contexts' , 'descendants' , props . params . statusId ] ) ,
2016-10-25 00:11:02 +09:00
} ) ;
return mapStateToProps ;
} ;
2016-09-16 07:21:51 +09:00
2017-06-24 02:36:54 +09:00
@ injectIntl
@ connect ( makeMapStateToProps )
export default class Status extends ImmutablePureComponent {
2017-04-22 03:05:35 +09:00
2017-05-12 21:44:10 +09:00
static contextTypes = {
2017-05-21 00:31:47 +09:00
router : PropTypes . object ,
2017-05-12 21:44:10 +09:00
} ;
static propTypes = {
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
status : ImmutablePropTypes . map ,
2017-06-30 18:15:18 +09:00
settings : ImmutablePropTypes . map . isRequired ,
2017-05-12 21:44:10 +09:00
ancestorsIds : ImmutablePropTypes . list ,
descendantsIds : ImmutablePropTypes . list ,
2017-05-21 00:31:47 +09:00
intl : PropTypes . object . isRequired ,
2017-05-12 21:44:10 +09:00
} ;
2016-09-16 07:21:51 +09:00
2017-11-07 22:24:55 +09:00
state = {
fullscreen : false ,
2018-08-29 00:16:30 +09:00
isExpanded : undefined ,
2018-08-28 21:10:26 +09:00
threadExpanded : undefined ,
2017-11-07 22:24:55 +09:00
} ;
2016-09-16 07:21:51 +09: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 21:53:48 +09:00
this . props . dispatch ( fetchStatus ( this . props . params . statusId ) ) ;
2017-04-22 03:05:35 +09:00
}
2016-09-16 07:21:51 +09:00
2017-11-07 22:24:55 +09:00
componentDidMount ( ) {
attachFullscreenListener ( this . onFullScreenChange ) ;
}
2016-09-16 07:21:51 +09:00
componentWillReceiveProps ( nextProps ) {
2018-08-29 00:16:30 +09:00
if ( this . state . isExpanded === undefined ) {
const isExpanded = autoUnfoldCW ( nextProps . settings , nextProps . status ) ;
if ( isExpanded !== undefined ) this . setState ( { isExpanded : isExpanded } ) ;
}
2016-09-16 07:21:51 +09:00
if ( nextProps . params . statusId !== this . props . params . statusId && nextProps . params . statusId ) {
2017-10-12 02:21:44 +09: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 21:53:48 +09:00
this . props . dispatch ( fetchStatus ( nextProps . params . statusId ) ) ;
2018-08-29 00:16:30 +09:00
this . setState ( { isExpanded : autoUnfoldCW ( nextProps . settings , nextProps . status ) } ) ;
2016-09-16 07:21:51 +09:00
}
2017-04-22 03:05:35 +09:00
}
2016-09-16 07:21:51 +09:00
2017-11-28 07:05:03 +09:00
handleExpandedToggle = ( ) => {
if ( this . props . status . get ( 'spoiler_text' ) ) {
2018-03-28 22:40:34 +09:00
this . setExpansion ( ! this . state . isExpanded ) ;
2017-11-28 07:05:03 +09:00
}
} ;
2017-12-10 01:26:22 +09:00
handleModalFavourite = ( status ) => {
this . props . dispatch ( favourite ( status ) ) ;
}
handleFavouriteClick = ( status , e ) => {
2017-02-17 10:33:10 +09:00
if ( status . get ( 'favourited' ) ) {
this . props . dispatch ( unfavourite ( status ) ) ;
} else {
2017-12-10 03:06:00 +09:00
if ( e . shiftKey || ! favouriteModal ) {
2017-12-10 01:26:22 +09:00
this . handleModalFavourite ( status ) ;
} else {
this . props . dispatch ( openModal ( 'FAVOURITE' , { status , onFavourite : this . handleModalFavourite } ) ) ;
}
2017-02-17 10:33:10 +09:00
}
2017-04-22 03:05:35 +09:00
}
2016-09-18 00:47:26 +09:00
2017-08-25 08:41:18 +09:00
handlePin = ( status ) => {
if ( status . get ( 'pinned' ) ) {
this . props . dispatch ( unpin ( status ) ) ;
} else {
this . props . dispatch ( pin ( status ) ) ;
}
}
2017-05-12 21:44:10 +09:00
handleReplyClick = ( status ) => {
2017-06-21 03:40:03 +09:00
this . props . dispatch ( replyCompose ( status , this . context . router . history ) ) ;
2017-04-22 03:05:35 +09:00
}
2016-09-18 00:47:26 +09:00
2017-05-12 21:44:10 +09:00
handleModalReblog = ( status ) => {
2017-04-11 11:28:52 +09:00
this . props . dispatch ( reblog ( status ) ) ;
2017-04-22 03:05:35 +09:00
}
2017-12-10 03:41:24 +09:00
2017-05-12 21:44:10 +09:00
handleReblogClick = ( status , e ) => {
2017-02-17 10:33:10 +09:00
if ( status . get ( 'reblogged' ) ) {
this . props . dispatch ( unreblog ( status ) ) ;
} else {
2017-10-30 00:10:15 +09:00
if ( e . shiftKey || ! boostModal ) {
2017-04-11 21:34:14 +09:00
this . handleModalReblog ( status ) ;
} else {
this . props . dispatch ( openModal ( 'BOOST' , { status , onReblog : this . handleModalReblog } ) ) ;
}
2017-02-17 10:33:10 +09:00
}
2017-04-22 03:05:35 +09:00
}
2016-09-18 00:47:26 +09:00
2018-04-12 02:42:25 +09:00
handleBookmarkClick = ( status ) => {
if ( status . get ( 'bookmarked' ) ) {
this . props . dispatch ( unbookmark ( status ) ) ;
} else {
this . props . dispatch ( bookmark ( status ) ) ;
}
}
2018-08-31 23:41:58 +09:00
handleDeleteClick = ( status , history , withRedraft = false ) => {
2017-04-23 11:39:50 +09:00
const { dispatch , intl } = this . props ;
2017-10-30 00:10:15 +09:00
if ( ! deleteModal ) {
2018-08-31 23:41:58 +09:00
dispatch ( deleteStatus ( status . get ( 'id' ) , history , withRedraft ) ) ;
2017-05-30 00:56:13 +09:00
} else {
dispatch ( openModal ( 'CONFIRM' , {
2018-06-16 04:29:04 +09:00
message : intl . formatMessage ( withRedraft ? messages . redraftMessage : messages . deleteMessage ) ,
confirm : intl . formatMessage ( withRedraft ? messages . redraftConfirm : messages . deleteConfirm ) ,
2018-08-31 23:41:58 +09:00
onConfirm : ( ) => dispatch ( deleteStatus ( status . get ( 'id' ) , history , withRedraft ) ) ,
2017-05-30 00:56:13 +09:00
} ) ) ;
}
2017-04-22 03:05:35 +09:00
}
2016-10-10 05:19:15 +09:00
2018-04-11 04:38:02 +09:00
handleDirectClick = ( account , router ) => {
this . props . dispatch ( directCompose ( account , router ) ) ;
}
2017-05-12 21:44:10 +09:00
handleMentionClick = ( account , router ) => {
2017-01-31 05:40:55 +09:00
this . props . dispatch ( mentionCompose ( account , router ) ) ;
2017-04-22 03:05:35 +09:00
}
2016-10-25 00:11:02 +09:00
2017-05-12 21:44:10 +09:00
handleOpenMedia = ( media , index ) => {
2017-04-02 05:11:28 +09:00
this . props . dispatch ( openModal ( 'MEDIA' , { media , index } ) ) ;
2017-04-22 03:05:35 +09:00
}
2016-10-25 01:07:40 +09:00
2017-05-12 21:44:10 +09:00
handleOpenVideo = ( media , time ) => {
2017-04-14 00:01:09 +09:00
this . props . dispatch ( openModal ( 'VIDEO' , { media , time } ) ) ;
2017-04-22 03:05:35 +09:00
}
2017-04-13 22:04:18 +09:00
2017-12-27 01:13:38 +09: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-29 02:56:46 +09:00
handleToggleAll = ( ) => {
const { isExpanded } = this . state ;
this . setState ( { isExpanded : ! isExpanded , threadExpanded : ! isExpanded } ) ;
}
2017-12-27 01:13:38 +09:00
handleBlockClick = ( account ) => {
const { dispatch , intl } = this . props ;
dispatch ( openModal ( 'CONFIRM' , {
message : < FormattedMessage id = 'confirmations.block.message' defaultMessage = 'Are you sure you want to block {name}?' values = { { name : < strong > @ { account . get ( 'acct' ) } < /strong> }} / > ,
confirm : intl . formatMessage ( messages . blockConfirm ) ,
onConfirm : ( ) => dispatch ( blockAccount ( account . get ( 'id' ) ) ) ,
} ) ) ;
}
2017-05-12 21:44:10 +09:00
handleReport = ( status ) => {
2017-02-15 04:59:26 +09:00
this . props . dispatch ( initReport ( status . get ( 'account' ) , status ) ) ;
2017-04-22 03:05:35 +09:00
}
2017-02-15 04:59:26 +09:00
2017-08-31 10:38:35 +09:00
handleEmbed = ( status ) => {
this . props . dispatch ( openModal ( 'EMBED' , { url : status . get ( 'url' ) } ) ) ;
}
2017-10-06 08:07:59 +09: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 ( ) ;
this . handleMentionClick ( this . props . status ) ;
}
handleHotkeyOpenProfile = ( ) => {
this . context . router . history . push ( ` /accounts/ ${ this . props . status . getIn ( [ 'account' , 'id' ] ) } ` ) ;
}
handleMoveUp = id => {
const { status , ancestorsIds , descendantsIds } = this . props ;
if ( id === status . get ( 'id' ) ) {
this . _selectChild ( ancestorsIds . size - 1 ) ;
} else {
let index = ancestorsIds . indexOf ( id ) ;
if ( index === - 1 ) {
index = descendantsIds . indexOf ( id ) ;
this . _selectChild ( ancestorsIds . size + index ) ;
} else {
this . _selectChild ( index - 1 ) ;
}
}
}
handleMoveDown = id => {
const { status , ancestorsIds , descendantsIds } = this . props ;
if ( id === status . get ( 'id' ) ) {
this . _selectChild ( ancestorsIds . size + 1 ) ;
} else {
let index = ancestorsIds . indexOf ( id ) ;
if ( index === - 1 ) {
index = descendantsIds . indexOf ( id ) ;
this . _selectChild ( ancestorsIds . size + index + 2 ) ;
} else {
this . _selectChild ( index + 1 ) ;
}
}
}
_selectChild ( index ) {
const element = this . node . querySelectorAll ( '.focusable' ) [ index ] ;
if ( element ) {
element . focus ( ) ;
}
}
2016-09-16 07:21:51 +09:00
renderChildren ( list ) {
2017-10-06 08:07:59 +09:00
return list . map ( id => (
< StatusContainer
key = { id }
id = { id }
2018-03-29 02:56:46 +09:00
expanded = { this . state . threadExpanded }
2017-10-06 08:07:59 +09:00
onMoveUp = { this . handleMoveUp }
onMoveDown = { this . handleMoveDown }
2018-07-09 03:04:53 +09:00
contextType = 'thread'
2017-10-06 08:07:59 +09:00
/ >
) ) ;
}
2017-11-28 07:05:03 +09:00
setExpansion = value => {
2018-03-28 22:40:34 +09:00
this . setState ( { isExpanded : value } ) ;
2017-11-28 07:05:03 +09:00
}
2017-10-06 08:07:59 +09:00
setRef = c => {
this . node = c ;
}
componentDidUpdate ( ) {
2017-10-12 02:21:44 +09:00
if ( this . _scrolledIntoView ) {
return ;
}
2017-10-11 18:25:15 +09:00
const { status , ancestorsIds } = this . props ;
2017-10-06 08:07:59 +09:00
2017-10-11 18:25:15 +09:00
if ( status && ancestorsIds && ancestorsIds . size > 0 ) {
2017-10-12 02:21:44 +09:00
const element = this . node . querySelectorAll ( '.focusable' ) [ ancestorsIds . size - 1 ] ;
2018-08-17 20:39:06 +09:00
window . requestAnimationFrame ( ( ) => {
2017-10-12 04:49:22 +09:00
element . scrollIntoView ( true ) ;
2018-08-17 20:39:06 +09:00
} ) ;
this . _scrolledIntoView = true ;
2017-10-06 08:07:59 +09:00
}
2017-04-22 03:05:35 +09:00
}
2016-09-16 07:21:51 +09:00
2017-11-07 22:24:55 +09:00
componentWillUnmount ( ) {
detachFullscreenListener ( this . onFullScreenChange ) ;
}
onFullScreenChange = ( ) => {
this . setState ( { fullscreen : isFullscreen ( ) } ) ;
}
2018-07-28 00:59:52 +09:00
shouldUpdateScroll = ( prevRouterProps , { location } ) => {
return ! ( location . state && location . state . mastodonModalOpen )
}
2016-09-16 07:21:51 +09:00
render ( ) {
2016-10-25 00:11:02 +09:00
let ancestors , descendants ;
2017-11-28 07:05:03 +09:00
const { setExpansion } = this ;
2018-03-29 02:56:46 +09:00
const { status , settings , ancestorsIds , descendantsIds , intl } = this . props ;
2017-11-28 07:05:03 +09:00
const { fullscreen , isExpanded } = this . state ;
2016-09-16 07:21:51 +09:00
if ( status === null ) {
2016-10-07 23:00:11 +09:00
return (
< Column >
2017-02-19 16:32:35 +09:00
< ColumnBackButton / >
2017-02-27 07:06:27 +09:00
< MissingIndicator / >
2016-10-07 23:00:11 +09:00
< / C o l u m n >
) ;
2016-09-16 07:21:51 +09:00
}
2016-10-30 23:06:43 +09:00
if ( ancestorsIds && ancestorsIds . size > 0 ) {
2016-10-25 00:11:02 +09:00
ancestors = < div > { this . renderChildren ( ancestorsIds ) } < / d i v > ;
}
2016-10-30 23:06:43 +09:00
if ( descendantsIds && descendantsIds . size > 0 ) {
2016-10-25 00:11:02 +09:00
descendants = < div > { this . renderChildren ( descendantsIds ) } < / d i v > ;
}
2017-10-06 08:07:59 +09:00
const handlers = {
moveUp : this . handleHotkeyMoveUp ,
moveDown : this . handleHotkeyMoveDown ,
reply : this . handleHotkeyReply ,
favourite : this . handleHotkeyFavourite ,
boost : this . handleHotkeyBoost ,
mention : this . handleHotkeyMention ,
openProfile : this . handleHotkeyOpenProfile ,
2017-11-28 07:05:03 +09:00
toggleSpoiler : this . handleExpandedToggle ,
2017-10-06 08:07:59 +09:00
} ;
2016-09-16 07:21:51 +09:00
return (
2018-08-28 19:01:04 +09:00
< Column label = { intl . formatMessage ( messages . detailedStatus ) } >
2018-03-29 02:56:46 +09:00
< ColumnHeader
showBackButton
extraButton = { (
< button className = 'column-header__button' title = { intl . formatMessage ( ! isExpanded ? messages . revealAll : messages . hideAll ) } aria - label = { intl . formatMessage ( ! isExpanded ? messages . revealAll : messages . hideAll ) } onClick = { this . handleToggleAll } aria - pressed = { ! isExpanded ? 'false' : 'true' } > < i className = { ` fa fa- ${ ! isExpanded ? 'eye-slash' : 'eye' } ` } / > < / b u t t o n >
) }
/ >
2016-09-18 20:03:37 +09:00
2018-07-28 00:59:52 +09:00
< ScrollContainer scrollKey = 'thread' shouldUpdateScroll = { this . shouldUpdateScroll } >
2017-11-07 22:24:55 +09:00
< div className = { classNames ( 'scrollable' , 'detailed-status__wrapper' , { fullscreen } ) } ref = { this . setRef } >
2016-10-25 00:11:02 +09:00
{ ancestors }
2016-09-18 20:03:37 +09:00
2017-10-06 08:07:59 +09:00
< HotKeys handlers = { handlers } >
< div className = 'focusable' tabIndex = '0' >
< DetailedStatus
status = { status }
2017-10-12 02:43:10 +09:00
settings = { settings }
2017-10-06 08:07:59 +09:00
onOpenVideo = { this . handleOpenVideo }
onOpenMedia = { this . handleOpenMedia }
2017-11-28 07:05:03 +09:00
expanded = { isExpanded }
2018-03-29 02:56:46 +09:00
onToggleHidden = { this . handleExpandedToggle }
2017-10-06 08:07:59 +09:00
/ >
< ActionBar
status = { status }
onReply = { this . handleReplyClick }
onFavourite = { this . handleFavouriteClick }
onReblog = { this . handleReblogClick }
2018-04-12 02:42:25 +09:00
onBookmark = { this . handleBookmarkClick }
2017-10-06 08:07:59 +09:00
onDelete = { this . handleDeleteClick }
2018-04-11 04:38:02 +09:00
onDirect = { this . handleDirectClick }
2017-10-06 08:07:59 +09:00
onMention = { this . handleMentionClick }
2017-12-27 01:13:38 +09:00
onMute = { this . handleMuteClick }
onMuteConversation = { this . handleConversationMuteClick }
onBlock = { this . handleBlockClick }
2017-10-06 08:07:59 +09:00
onReport = { this . handleReport }
onPin = { this . handlePin }
onEmbed = { this . handleEmbed }
/ >
< / d i v >
< / H o t K e y s >
2016-10-20 01:20:19 +09:00
2016-10-25 00:11:02 +09:00
{ descendants }
2016-10-20 01:20:19 +09:00
< / d i v >
< / S c r o l l C o n t a i n e r >
2016-10-07 23:00:11 +09:00
< / C o l u m n >
2016-09-16 07:21:51 +09:00
) ;
}
2017-04-22 03:05:35 +09:00
}