2017-07-13 18:40:16 +09:00
|
|
|
// THIS FILE EXISTS FOR UPSTREAM COMPATIBILITY & SHOULDN'T BE USED !!
|
|
|
|
// SEE INSTEAD : glitch/components/status
|
|
|
|
|
2017-07-12 17:10:17 +09:00
|
|
|
import React from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Avatar from './avatar';
|
|
|
|
import AvatarOverlay from './avatar_overlay';
|
|
|
|
import RelativeTimestamp from './relative_timestamp';
|
|
|
|
import DisplayName from './display_name';
|
|
|
|
import StatusContent from './status_content';
|
|
|
|
import StatusActionBar from './status_action_bar';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-09-14 10:39:10 +09:00
|
|
|
import { MediaGallery, Video } from '../features/ui/util/async-components';
|
2017-10-06 08:07:59 +09:00
|
|
|
import { HotKeys } from 'react-hotkeys';
|
|
|
|
import classNames from 'classnames';
|
2017-07-12 17:10:17 +09:00
|
|
|
|
|
|
|
// We use the component (and not the container) since we do not want
|
|
|
|
// to use the progress bar to show download progress
|
|
|
|
import Bundle from '../features/ui/components/bundle';
|
|
|
|
|
|
|
|
export default class Status extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
status: ImmutablePropTypes.map,
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
onReply: PropTypes.func,
|
|
|
|
onFavourite: PropTypes.func,
|
|
|
|
onReblog: PropTypes.func,
|
|
|
|
onDelete: PropTypes.func,
|
2017-08-25 08:41:18 +09:00
|
|
|
onPin: PropTypes.func,
|
2017-07-12 17:10:17 +09:00
|
|
|
onOpenMedia: PropTypes.func,
|
|
|
|
onOpenVideo: PropTypes.func,
|
|
|
|
onBlock: PropTypes.func,
|
2017-09-02 04:30:13 +09:00
|
|
|
onEmbed: PropTypes.func,
|
2017-08-08 03:32:03 +09:00
|
|
|
onHeightChange: PropTypes.func,
|
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
|
|
|
me: PropTypes.string,
|
2017-07-12 17:10:17 +09:00
|
|
|
boostModal: PropTypes.bool,
|
|
|
|
autoPlayGif: PropTypes.bool,
|
|
|
|
muted: PropTypes.bool,
|
2017-08-29 05:23:44 +09:00
|
|
|
hidden: PropTypes.bool,
|
2017-10-06 08:07:59 +09:00
|
|
|
onMoveUp: PropTypes.func,
|
|
|
|
onMoveDown: PropTypes.func,
|
2017-07-12 17:10:17 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
isExpanded: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid checking props that are functions (and whose equality will always
|
|
|
|
// evaluate to false. See react-immutable-pure-component for usage.
|
|
|
|
updateOnProps = [
|
|
|
|
'status',
|
|
|
|
'account',
|
|
|
|
'me',
|
|
|
|
'boostModal',
|
|
|
|
'autoPlayGif',
|
|
|
|
'muted',
|
2017-08-29 05:23:44 +09:00
|
|
|
'hidden',
|
2017-07-12 17:10:17 +09:00
|
|
|
]
|
|
|
|
|
|
|
|
updateOnStates = ['isExpanded']
|
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
if (!this.context.router) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { status } = this.props;
|
|
|
|
this.context.router.history.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAccountClick = (e) => {
|
|
|
|
if (this.context.router && e.button === 0) {
|
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
|
|
|
const id = e.currentTarget.getAttribute('data-id');
|
2017-07-12 17:10:17 +09:00
|
|
|
e.preventDefault();
|
|
|
|
this.context.router.history.push(`/accounts/${id}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleExpandedToggle = () => {
|
|
|
|
this.setState({ isExpanded: !this.state.isExpanded });
|
|
|
|
};
|
|
|
|
|
|
|
|
renderLoadingMediaGallery () {
|
|
|
|
return <div className='media_gallery' style={{ height: '110px' }} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLoadingVideoPlayer () {
|
|
|
|
return <div className='media-spoiler-video' style={{ height: '110px' }} />;
|
|
|
|
}
|
|
|
|
|
2017-09-14 10:39:10 +09:00
|
|
|
handleOpenVideo = startTime => {
|
2017-10-06 08:07:59 +09:00
|
|
|
this.props.onOpenVideo(this._properStatus().getIn(['media_attachments', 0]), startTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyReply = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onReply(this._properStatus(), this.context.router.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyFavourite = () => {
|
|
|
|
this.props.onFavourite(this._properStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyBoost = e => {
|
|
|
|
this.props.onReblog(this._properStatus(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMention = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onMention(this._properStatus().get('account'), this.context.router.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyOpen = () => {
|
|
|
|
this.context.router.history.push(`/statuses/${this._properStatus().get('id')}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyOpenProfile = () => {
|
|
|
|
this.context.router.history.push(`/accounts/${this._properStatus().getIn(['account', 'id'])}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveUp = () => {
|
|
|
|
this.props.onMoveUp(this.props.status.get('id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveDown = () => {
|
|
|
|
this.props.onMoveDown(this.props.status.get('id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
_properStatus () {
|
|
|
|
const { status } = this.props;
|
|
|
|
|
|
|
|
if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
|
|
|
|
return status.get('reblog');
|
|
|
|
} else {
|
|
|
|
return status;
|
|
|
|
}
|
2017-09-14 10:39:10 +09:00
|
|
|
}
|
|
|
|
|
2017-07-12 17:10:17 +09:00
|
|
|
render () {
|
|
|
|
let media = null;
|
2017-10-06 08:07:59 +09:00
|
|
|
let statusAvatar, prepend;
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
const { hidden } = this.props;
|
2017-08-29 05:23:44 +09:00
|
|
|
const { isExpanded } = this.state;
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
let { status, account, ...other } = this.props;
|
|
|
|
|
2017-07-12 17:10:17 +09:00
|
|
|
if (status === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:23:44 +09:00
|
|
|
if (hidden) {
|
2017-07-12 17:10:17 +09:00
|
|
|
return (
|
2017-08-29 05:23:44 +09:00
|
|
|
<div>
|
2017-07-12 17:10:17 +09:00
|
|
|
{status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])}
|
|
|
|
{status.get('content')}
|
2017-08-29 05:23:44 +09:00
|
|
|
</div>
|
2017-07-12 17:10:17 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
|
2017-08-08 03:32:03 +09:00
|
|
|
const display_name_html = { __html: status.getIn(['account', 'display_name_html']) };
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
prepend = (
|
|
|
|
<div className='status__prepend'>
|
|
|
|
<div className='status__prepend-icon-wrapper'><i className='fa fa-fw fa-retweet status__prepend-icon' /></div>
|
|
|
|
<FormattedMessage id='status.reblogged_by' defaultMessage='{name} boosted' values={{ name: <a onClick={this.handleAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name muted'><strong dangerouslySetInnerHTML={display_name_html} /></a> }} />
|
2017-08-29 05:23:44 +09:00
|
|
|
</div>
|
2017-07-12 17:10:17 +09:00
|
|
|
);
|
2017-10-06 08:07:59 +09:00
|
|
|
|
|
|
|
account = status.get('account');
|
|
|
|
status = status.get('reblog');
|
2017-07-12 17:10:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status.get('media_attachments').size > 0 && !this.props.muted) {
|
|
|
|
if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
|
|
|
|
|
|
|
|
} else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
|
2017-09-14 10:39:10 +09:00
|
|
|
const video = status.getIn(['media_attachments', 0]);
|
|
|
|
|
2017-07-12 17:10:17 +09:00
|
|
|
media = (
|
2017-09-14 10:39:10 +09:00
|
|
|
<Bundle fetchComponent={Video} loading={this.renderLoadingVideoPlayer} >
|
|
|
|
{Component => <Component
|
|
|
|
preview={video.get('preview_url')}
|
|
|
|
src={video.get('url')}
|
|
|
|
width={239}
|
|
|
|
height={110}
|
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
onOpenVideo={this.handleOpenVideo}
|
|
|
|
/>}
|
2017-07-12 17:10:17 +09:00
|
|
|
</Bundle>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
media = (
|
|
|
|
<Bundle fetchComponent={MediaGallery} loading={this.renderLoadingMediaGallery} >
|
|
|
|
{Component => <Component media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} autoPlayGif={this.props.autoPlayGif} />}
|
|
|
|
</Bundle>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (account === undefined || account === null) {
|
2017-08-07 03:59:19 +09:00
|
|
|
statusAvatar = <Avatar account={status.get('account')} size={48} />;
|
2017-07-12 17:10:17 +09:00
|
|
|
}else{
|
2017-08-07 03:59:19 +09:00
|
|
|
statusAvatar = <AvatarOverlay account={status.get('account')} friend={account} />;
|
2017-07-12 17:10:17 +09:00
|
|
|
}
|
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
const handlers = this.props.muted ? {} : {
|
|
|
|
reply: this.handleHotkeyReply,
|
|
|
|
favourite: this.handleHotkeyFavourite,
|
|
|
|
boost: this.handleHotkeyBoost,
|
|
|
|
mention: this.handleHotkeyMention,
|
|
|
|
open: this.handleHotkeyOpen,
|
|
|
|
openProfile: this.handleHotkeyOpenProfile,
|
|
|
|
moveUp: this.handleHotkeyMoveUp,
|
|
|
|
moveDown: this.handleHotkeyMoveDown,
|
|
|
|
};
|
|
|
|
|
2017-07-12 17:10:17 +09:00
|
|
|
return (
|
2017-10-06 08:07:59 +09:00
|
|
|
<HotKeys handlers={handlers}>
|
|
|
|
<div className={classNames('status__wrapper', `status__wrapper-${status.get('visibility')}`, { focusable: !this.props.muted })} tabIndex={this.props.muted ? null : 0}>
|
|
|
|
{prepend}
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
<div className={classNames('status', `status-${status.get('visibility')}`, { muted: this.props.muted })} data-id={status.get('id')}>
|
|
|
|
<div className='status__info'>
|
|
|
|
<a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
<a onClick={this.handleAccountClick} target='_blank' data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} title={status.getIn(['account', 'acct'])} className='status__display-name'>
|
|
|
|
<div className='status__avatar'>
|
|
|
|
{statusAvatar}
|
|
|
|
</div>
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
<DisplayName account={status.get('account')} />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<StatusContent status={status} onClick={this.handleClick} expanded={isExpanded} onExpandedToggle={this.handleExpandedToggle} />
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
{media}
|
2017-07-12 17:10:17 +09:00
|
|
|
|
2017-10-06 08:07:59 +09:00
|
|
|
<StatusActionBar status={status} account={account} {...other} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</HotKeys>
|
2017-07-12 17:10:17 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|