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