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