2017-05-02 20:04:16 -04:00
|
|
|
import React from 'react';
|
2016-11-16 11:20:52 -05:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-21 14:05:35 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-11 11:07:35 -04:00
|
|
|
import { fetchAccount } from '../../actions/accounts';
|
2018-03-24 10:25:15 -04:00
|
|
|
import { expandAccountFeaturedTimeline, expandAccountTimeline } from '../../actions/timelines';
|
2016-11-16 11:20:52 -05:00
|
|
|
import StatusList from '../../components/status_list';
|
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
2017-01-30 15:40:55 -05:00
|
|
|
import Column from '../ui/components/column';
|
|
|
|
import HeaderContainer from './containers/header_container';
|
|
|
|
import ColumnBackButton from '../../components/column_back_button';
|
2017-07-10 19:00:14 -04:00
|
|
|
import { List as ImmutableList } from 'immutable';
|
2017-05-02 20:04:16 -04:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2018-11-08 15:35:06 -05:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2019-03-28 13:01:09 -04:00
|
|
|
import { fetchAccountIdentityProofs } from '../../actions/identity_proofs';
|
2019-04-08 23:02:48 -04:00
|
|
|
import MissingIndicator from 'mastodon/components/missing_indicator';
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2019-04-06 22:59:13 -04:00
|
|
|
const emptyList = ImmutableList();
|
|
|
|
|
2018-02-28 20:48:44 -05:00
|
|
|
const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
|
|
|
|
const path = withReplies ? `${accountId}:with_replies` : accountId;
|
|
|
|
|
|
|
|
return {
|
2019-04-08 23:02:48 -04:00
|
|
|
isAccount: !!state.getIn(['accounts', accountId]),
|
2019-04-06 22:59:13 -04:00
|
|
|
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], emptyList),
|
|
|
|
featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], emptyList),
|
2018-02-28 20:48:44 -05:00
|
|
|
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
|
2019-04-06 22:59:13 -04:00
|
|
|
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
|
|
|
|
blockedBy: state.getIn(['relationships', accountId, 'blocked_by'], false),
|
2018-02-28 20:48:44 -05:00
|
|
|
};
|
|
|
|
};
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2018-09-14 11:59:48 -04:00
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
class AccountTimeline extends ImmutablePureComponent {
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
static propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2018-07-29 10:52:06 -04:00
|
|
|
shouldUpdateScroll: PropTypes.func,
|
2017-05-12 08:44:10 -04:00
|
|
|
statusIds: ImmutablePropTypes.list,
|
2018-03-04 03:19:11 -05:00
|
|
|
featuredStatusIds: ImmutablePropTypes.list,
|
2017-05-12 08:44:10 -04:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
2018-02-28 20:48:44 -05:00
|
|
|
withReplies: PropTypes.bool,
|
2019-04-06 22:59:13 -04:00
|
|
|
blockedBy: PropTypes.bool,
|
2019-04-08 23:02:48 -04:00
|
|
|
isAccount: PropTypes.bool,
|
2019-07-19 03:25:22 -04:00
|
|
|
multiColumn: PropTypes.bool,
|
2017-05-12 08:44:10 -04:00
|
|
|
};
|
2016-10-09 14:18:54 -04:00
|
|
|
|
|
|
|
componentWillMount () {
|
2018-03-04 03:19:11 -05:00
|
|
|
const { params: { accountId }, withReplies } = this.props;
|
|
|
|
|
|
|
|
this.props.dispatch(fetchAccount(accountId));
|
2019-03-28 13:01:09 -04:00
|
|
|
this.props.dispatch(fetchAccountIdentityProofs(accountId));
|
2019-04-06 22:59:13 -04:00
|
|
|
|
2018-03-12 07:47:18 -04:00
|
|
|
if (!withReplies) {
|
2018-03-24 10:25:15 -04:00
|
|
|
this.props.dispatch(expandAccountFeaturedTimeline(accountId));
|
2018-03-12 07:47:18 -04:00
|
|
|
}
|
2019-04-06 22:59:13 -04:00
|
|
|
|
2018-03-24 10:25:15 -04:00
|
|
|
this.props.dispatch(expandAccountTimeline(accountId, { withReplies }));
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2018-02-28 20:48:44 -05:00
|
|
|
if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
|
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 08:53:48 -04:00
|
|
|
this.props.dispatch(fetchAccount(nextProps.params.accountId));
|
2019-03-28 13:01:09 -04:00
|
|
|
this.props.dispatch(fetchAccountIdentityProofs(nextProps.params.accountId));
|
2019-04-06 22:59:13 -04:00
|
|
|
|
2018-03-12 07:47:18 -04:00
|
|
|
if (!nextProps.withReplies) {
|
2018-03-24 10:25:15 -04:00
|
|
|
this.props.dispatch(expandAccountFeaturedTimeline(nextProps.params.accountId));
|
2018-03-12 07:47:18 -04:00
|
|
|
}
|
2019-04-06 22:59:13 -04:00
|
|
|
|
2018-03-24 10:25:15 -04:00
|
|
|
this.props.dispatch(expandAccountTimeline(nextProps.params.accountId, { withReplies: nextProps.params.withReplies }));
|
2016-10-09 14:18:54 -04:00
|
|
|
}
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2018-03-24 10:25:15 -04:00
|
|
|
handleLoadMore = maxId => {
|
|
|
|
this.props.dispatch(expandAccountTimeline(this.props.params.accountId, { maxId, withReplies: this.props.withReplies }));
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-10-09 14:18:54 -04:00
|
|
|
|
|
|
|
render () {
|
2019-07-19 03:25:22 -04:00
|
|
|
const { shouldUpdateScroll, statusIds, featuredStatusIds, isLoading, hasMore, blockedBy, isAccount, multiColumn } = this.props;
|
2019-04-08 23:02:48 -04:00
|
|
|
|
|
|
|
if (!isAccount) {
|
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<MissingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
2016-10-24 11:11:02 -04:00
|
|
|
|
2017-01-31 16:34:33 -05:00
|
|
|
if (!statusIds && isLoading) {
|
2017-01-30 15:40:55 -05:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-24 11:11:02 -04:00
|
|
|
}
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2019-04-06 22:59:13 -04:00
|
|
|
const emptyMessage = blockedBy ? <FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' /> : <FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />;
|
|
|
|
|
2017-01-30 15:40:55 -05:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<ColumnBackButton />
|
|
|
|
|
|
|
|
<StatusList
|
|
|
|
prepend={<HeaderContainer accountId={this.props.params.accountId} />}
|
2018-11-08 15:35:06 -05:00
|
|
|
alwaysPrepend
|
2017-04-23 22:49:08 -04:00
|
|
|
scrollKey='account_timeline'
|
2019-04-06 22:59:13 -04:00
|
|
|
statusIds={blockedBy ? emptyList : statusIds}
|
2018-03-04 03:19:11 -05:00
|
|
|
featuredStatusIds={featuredStatusIds}
|
2017-01-30 15:40:55 -05:00
|
|
|
isLoading={isLoading}
|
2017-02-22 10:30:09 -05:00
|
|
|
hasMore={hasMore}
|
2018-03-05 13:31:40 -05:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2018-07-29 10:52:06 -04:00
|
|
|
shouldUpdateScroll={shouldUpdateScroll}
|
2019-04-06 22:59:13 -04:00
|
|
|
emptyMessage={emptyMessage}
|
2019-07-19 03:25:22 -04:00
|
|
|
bindToDocument={!multiColumn}
|
2017-01-30 15:40:55 -05:00
|
|
|
/>
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-09 14:18:54 -04:00
|
|
|
}
|
|
|
|
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|