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';
|
2021-09-25 23:46:13 -04:00
|
|
|
import { lookupAccount, fetchAccount } from 'flavours/glitch/actions/accounts';
|
2018-05-27 13:10:37 -04:00
|
|
|
import { expandAccountFeaturedTimeline, expandAccountTimeline } from 'flavours/glitch/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';
|
2019-02-27 07:36:40 -05:00
|
|
|
import ProfileColumnHeader from 'flavours/glitch/features/account/components/profile_column_header';
|
2017-01-30 15:40:55 -05:00
|
|
|
import HeaderContainer from './containers/header_container';
|
2019-10-06 22:33:31 -04:00
|
|
|
import ColumnBackButton from 'flavours/glitch/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-09 10:47:50 -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 'flavours/glitch/components/missing_indicator';
|
2020-06-14 16:29:40 -04:00
|
|
|
import TimelineHint from 'flavours/glitch/components/timeline_hint';
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2020-09-09 18:07:19 -04:00
|
|
|
const emptyList = ImmutableList();
|
|
|
|
|
2021-09-25 23:46:13 -04:00
|
|
|
const mapStateToProps = (state, { params: { acct }, withReplies = false }) => {
|
|
|
|
const accountId = state.getIn(['accounts_map', acct]);
|
|
|
|
|
|
|
|
if (!accountId) {
|
|
|
|
return {
|
|
|
|
isLoading: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-16 14:54:00 -04:00
|
|
|
const path = withReplies ? `${accountId}:with_replies` : accountId;
|
|
|
|
|
|
|
|
return {
|
2021-09-25 23:46:13 -04:00
|
|
|
accountId,
|
2020-07-01 17:38:44 -04:00
|
|
|
remote: !!(state.getIn(['accounts', accountId, 'acct']) !== state.getIn(['accounts', accountId, 'username'])),
|
2020-06-14 16:29:40 -04:00
|
|
|
remoteUrl: state.getIn(['accounts', accountId, 'url']),
|
2019-04-08 23:02:48 -04:00
|
|
|
isAccount: !!state.getIn(['accounts', accountId]),
|
2018-03-16 14:54:00 -04:00
|
|
|
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableList()),
|
2018-03-16 15:29:42 -04:00
|
|
|
featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], ImmutableList()),
|
2018-03-16 14:54:00 -04:00
|
|
|
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
|
2018-05-27 13:10:37 -04:00
|
|
|
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
|
2020-09-09 18:07:19 -04:00
|
|
|
suspended: state.getIn(['accounts', accountId, 'suspended'], false),
|
2018-03-16 14:54:00 -04:00
|
|
|
};
|
|
|
|
};
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2020-06-14 16:29:40 -04:00
|
|
|
const RemoteHint = ({ url }) => (
|
|
|
|
<TimelineHint url={url} resource={<FormattedMessage id='timeline_hint.resources.statuses' defaultMessage='Older toots' />} />
|
|
|
|
);
|
|
|
|
|
|
|
|
RemoteHint.propTypes = {
|
|
|
|
url: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2019-09-09 09:16:08 -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 = {
|
2021-09-25 23:46:13 -04:00
|
|
|
params: PropTypes.shape({
|
|
|
|
acct: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
accountId: PropTypes.string,
|
2017-05-12 08:44:10 -04:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
statusIds: ImmutablePropTypes.list,
|
2018-03-16 15:29:42 -04:00
|
|
|
featuredStatusIds: ImmutablePropTypes.list,
|
2017-05-12 08:44:10 -04:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
2018-03-16 14:54:00 -04:00
|
|
|
withReplies: PropTypes.bool,
|
2019-04-08 23:02:48 -04:00
|
|
|
isAccount: PropTypes.bool,
|
2020-09-09 18:07:19 -04:00
|
|
|
suspended: PropTypes.bool,
|
2020-06-14 16:29:40 -04:00
|
|
|
remote: PropTypes.bool,
|
|
|
|
remoteUrl: PropTypes.string,
|
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
|
|
|
|
2021-09-25 23:46:13 -04:00
|
|
|
_load () {
|
|
|
|
const { accountId, withReplies, dispatch } = this.props;
|
2018-03-16 15:29:42 -04:00
|
|
|
|
2021-09-25 23:46:13 -04:00
|
|
|
dispatch(fetchAccount(accountId));
|
|
|
|
dispatch(fetchAccountIdentityProofs(accountId));
|
2018-05-27 11:42:54 -04:00
|
|
|
if (!withReplies) {
|
2021-09-25 23:46:13 -04:00
|
|
|
dispatch(expandAccountFeaturedTimeline(accountId));
|
|
|
|
}
|
|
|
|
dispatch(expandAccountTimeline(accountId, { withReplies }));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (accountId) {
|
|
|
|
this._load();
|
|
|
|
} else {
|
|
|
|
dispatch(lookupAccount(acct));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (prevProps.accountId !== accountId && accountId) {
|
|
|
|
this._load();
|
|
|
|
} else if (prevProps.params.acct !== acct) {
|
|
|
|
dispatch(lookupAccount(acct));
|
2018-05-27 11:42:54 -04:00
|
|
|
}
|
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) {
|
2021-09-25 23:46:13 -04:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
2018-03-16 14:54:00 -04:00
|
|
|
if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
|
2021-09-25 23:46:13 -04:00
|
|
|
dispatch(fetchAccount(nextProps.params.accountId));
|
|
|
|
dispatch(fetchAccountIdentityProofs(nextProps.params.accountId));
|
2018-05-27 11:42:54 -04:00
|
|
|
if (!nextProps.withReplies) {
|
2021-09-25 23:46:13 -04:00
|
|
|
dispatch(expandAccountFeaturedTimeline(nextProps.params.accountId));
|
2018-05-27 11:42:54 -04:00
|
|
|
}
|
2021-09-25 23:46:13 -04:00
|
|
|
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
|
|
|
|
2019-03-08 14:34:31 -05:00
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
|
|
|
}
|
|
|
|
|
2018-05-27 13:10:37 -04:00
|
|
|
handleLoadMore = maxId => {
|
2021-09-25 23:46:13 -04:00
|
|
|
this.props.dispatch(expandAccountTimeline(this.props.accountId, { maxId, withReplies: this.props.withReplies }));
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-10-09 14:18:54 -04:00
|
|
|
|
2019-03-08 14:34:31 -05:00
|
|
|
setRef = c => {
|
|
|
|
this.column = c;
|
|
|
|
}
|
|
|
|
|
2016-10-09 14:18:54 -04:00
|
|
|
render () {
|
2020-09-09 18:07:19 -04:00
|
|
|
const { statusIds, featuredStatusIds, isLoading, hasMore, suspended, isAccount, multiColumn, remote, remoteUrl } = this.props;
|
2019-04-08 23:02:48 -04:00
|
|
|
|
|
|
|
if (!isAccount) {
|
|
|
|
return (
|
|
|
|
<Column>
|
2019-10-06 22:33:31 -04:00
|
|
|
<ColumnBackButton multiColumn={multiColumn} />
|
2019-04-08 23:02:48 -04:00
|
|
|
<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
|
|
|
|
2020-06-14 16:29:40 -04:00
|
|
|
let emptyMessage;
|
|
|
|
|
2020-09-09 18:07:19 -04:00
|
|
|
if (suspended) {
|
2020-12-14 03:08:09 -05:00
|
|
|
emptyMessage = <FormattedMessage id='empty_column.account_suspended' defaultMessage='Account suspended' />;
|
2020-09-09 18:07:19 -04:00
|
|
|
} else if (remote && statusIds.isEmpty()) {
|
2020-06-14 16:29:40 -04:00
|
|
|
emptyMessage = <RemoteHint url={remoteUrl} />;
|
|
|
|
} else {
|
|
|
|
emptyMessage = <FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />;
|
|
|
|
}
|
|
|
|
|
|
|
|
const remoteMessage = remote ? <RemoteHint url={remoteUrl} /> : null;
|
|
|
|
|
2017-01-30 15:40:55 -05:00
|
|
|
return (
|
2019-03-08 14:34:31 -05:00
|
|
|
<Column ref={this.setRef} name='account'>
|
2019-08-01 13:17:17 -04:00
|
|
|
<ProfileColumnHeader onClick={this.handleHeaderClick} multiColumn={multiColumn} />
|
2017-01-30 15:40:55 -05:00
|
|
|
|
|
|
|
<StatusList
|
2021-09-25 23:46:13 -04:00
|
|
|
prepend={<HeaderContainer accountId={this.props.accountId} />}
|
2018-11-09 10:47:50 -05:00
|
|
|
alwaysPrepend
|
2020-06-14 16:29:40 -04:00
|
|
|
append={remoteMessage}
|
2017-04-23 22:49:08 -04:00
|
|
|
scrollKey='account_timeline'
|
2020-09-09 18:07:19 -04:00
|
|
|
statusIds={suspended ? emptyList : statusIds}
|
2018-03-16 15:29:42 -04:00
|
|
|
featuredStatusIds={featuredStatusIds}
|
2017-01-30 15:40:55 -05:00
|
|
|
isLoading={isLoading}
|
2017-02-22 10:30:09 -05:00
|
|
|
hasMore={hasMore}
|
2018-05-27 11:46:48 -04:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2020-06-14 16:29:40 -04:00
|
|
|
emptyMessage={emptyMessage}
|
2019-07-19 03:25:22 -04:00
|
|
|
bindToDocument={!multiColumn}
|
2020-01-23 15:32:00 -05:00
|
|
|
timelineId='account'
|
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
|
|
|
}
|