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