2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
2017-07-11 08:00:14 +09:00
|
|
|
import { List as ImmutableList } from 'immutable';
|
2023-05-28 23:38:10 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-05-03 09:04:16 +09:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-28 23:38:10 +09:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2023-05-23 17:04:10 +09:00
|
|
|
import { TimelineHint } from 'flavours/glitch/components/timeline_hint';
|
2023-05-28 23:38:10 +09:00
|
|
|
import ProfileColumnHeader from 'flavours/glitch/features/account/components/profile_column_header';
|
|
|
|
import BundleColumnError from 'flavours/glitch/features/ui/components/bundle_column_error';
|
|
|
|
import { normalizeForLookup } from 'flavours/glitch/reducers/accounts_map';
|
2022-05-10 16:44:35 +09:00
|
|
|
import { getAccountHidden } from 'flavours/glitch/selectors';
|
2024-08-21 16:08:58 +09:00
|
|
|
import { useAppSelector } from 'flavours/glitch/store';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
2023-11-15 20:01:51 +09:00
|
|
|
import { lookupAccount, fetchAccount } from '../../actions/accounts';
|
2022-10-16 15:43:59 +09:00
|
|
|
import { fetchFeaturedTags } from '../../actions/featured_tags';
|
2023-05-28 23:38:10 +09:00
|
|
|
import { expandAccountFeaturedTimeline, expandAccountTimeline } from '../../actions/timelines';
|
2023-06-14 02:26:25 +09:00
|
|
|
import { LoadingIndicator } from '../../components/loading_indicator';
|
2023-05-28 23:38:10 +09:00
|
|
|
import StatusList from '../../components/status_list';
|
|
|
|
import Column from '../ui/components/column';
|
|
|
|
|
2023-11-04 00:00:03 +09:00
|
|
|
import { LimitedAccountHint } from './components/limited_account_hint';
|
2023-05-28 23:38:10 +09:00
|
|
|
import HeaderContainer from './containers/header_container';
|
|
|
|
|
2020-09-10 07:07:19 +09:00
|
|
|
const emptyList = ImmutableList();
|
|
|
|
|
2022-10-16 15:43:59 +09:00
|
|
|
const mapStateToProps = (state, { params: { acct, id, tagged }, withReplies = false }) => {
|
2022-10-21 17:06:03 +09:00
|
|
|
const accountId = id || state.getIn(['accounts_map', normalizeForLookup(acct)]);
|
2021-09-26 12:46:13 +09:00
|
|
|
|
2022-11-28 04:48:12 +09:00
|
|
|
if (accountId === null) {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
|
|
|
isAccount: false,
|
|
|
|
statusIds: emptyList,
|
|
|
|
};
|
|
|
|
} else if (!accountId) {
|
2021-09-26 12:46:13 +09:00
|
|
|
return {
|
|
|
|
isLoading: true,
|
2022-10-20 21:47:42 +09:00
|
|
|
statusIds: emptyList,
|
2021-09-26 12:46:13 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-16 15:43:59 +09:00
|
|
|
const path = withReplies ? `${accountId}:with_replies` : `${accountId}${tagged ? `:${tagged}` : ''}`;
|
2018-03-17 03:54:00 +09:00
|
|
|
|
|
|
|
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]),
|
2018-03-17 03:54:00 +09:00
|
|
|
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableList()),
|
2022-10-16 15:43:59 +09:00
|
|
|
featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned${tagged ? `:${tagged}` : ''}`, 'items'], ImmutableList()),
|
2018-03-17 03:54:00 +09:00
|
|
|
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
|
2018-05-28 02:10:37 +09:00
|
|
|
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
|
2020-09-10 07:07:19 +09:00
|
|
|
suspended: state.getIn(['accounts', accountId, 'suspended'], false),
|
2022-05-10 16:44:35 +09:00
|
|
|
hidden: getAccountHidden(state, accountId),
|
2018-03-17 03:54:00 +09:00
|
|
|
};
|
|
|
|
};
|
2016-10-10 03:18:54 +09:00
|
|
|
|
2024-08-21 16:08:58 +09:00
|
|
|
const RemoteHint = ({ accountId, url }) => {
|
|
|
|
const acct = useAppSelector(state => state.accounts.get(accountId)?.acct);
|
|
|
|
const domain = acct ? acct.split('@')[1] : undefined;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TimelineHint
|
|
|
|
url={url}
|
|
|
|
message={<FormattedMessage id='hints.profiles.posts_may_be_missing' defaultMessage='Some posts from this profile may be missing.' />}
|
|
|
|
label={<FormattedMessage id='hints.profiles.see_more_posts' defaultMessage='See more posts on {domain}' values={{ domain: <strong>{domain}</strong> }} />}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2020-06-15 05:29:40 +09:00
|
|
|
|
|
|
|
RemoteHint.propTypes = {
|
|
|
|
url: PropTypes.string.isRequired,
|
2024-08-21 16:08:58 +09:00
|
|
|
accountId: PropTypes.string.isRequired,
|
2020-06-15 05:29:40 +09:00
|
|
|
};
|
|
|
|
|
2019-09-09 22:16:08 +09:00
|
|
|
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({
|
2021-09-27 14:23:48 +09:00
|
|
|
acct: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
2022-10-16 15:43:59 +09:00
|
|
|
tagged: PropTypes.string,
|
2021-09-26 12:46:13 +09:00
|
|
|
}).isRequired,
|
|
|
|
accountId: PropTypes.string,
|
2017-05-12 21:44:10 +09:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
statusIds: ImmutablePropTypes.list,
|
2018-03-17 04:29:42 +09:00
|
|
|
featuredStatusIds: ImmutablePropTypes.list,
|
2017-05-12 21:44:10 +09:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
2018-03-17 03:54:00 +09:00
|
|
|
withReplies: PropTypes.bool,
|
2019-04-09 12:02:48 +09:00
|
|
|
isAccount: PropTypes.bool,
|
2020-09-10 07:07:19 +09:00
|
|
|
suspended: PropTypes.bool,
|
2022-05-10 16:44:35 +09:00
|
|
|
hidden: 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 () {
|
2022-10-16 15:43:59 +09:00
|
|
|
const { accountId, withReplies, params: { tagged }, dispatch } = this.props;
|
2018-03-17 04:29:42 +09:00
|
|
|
|
2021-09-26 12:46:13 +09:00
|
|
|
dispatch(fetchAccount(accountId));
|
2021-11-26 13:58:18 +09:00
|
|
|
|
2018-05-28 00:42:54 +09:00
|
|
|
if (!withReplies) {
|
2022-10-16 15:43:59 +09:00
|
|
|
dispatch(expandAccountFeaturedTimeline(accountId, { tagged }));
|
2021-09-26 12:46:13 +09:00
|
|
|
}
|
2022-10-16 15:43:59 +09:00
|
|
|
|
|
|
|
dispatch(fetchFeaturedTags(accountId));
|
|
|
|
dispatch(expandAccountTimeline(accountId, { withReplies, tagged }));
|
2021-09-26 12:46:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
2021-09-28 20:24:34 +09:00
|
|
|
|
2021-09-26 12:46:13 +09:00
|
|
|
if (accountId) {
|
|
|
|
this._load();
|
|
|
|
} else {
|
|
|
|
dispatch(lookupAccount(acct));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
2022-10-16 15:43:59 +09:00
|
|
|
const { params: { acct, tagged }, accountId, withReplies, dispatch } = this.props;
|
2021-09-26 12:46:13 +09:00
|
|
|
|
|
|
|
if (prevProps.accountId !== accountId && accountId) {
|
|
|
|
this._load();
|
|
|
|
} else if (prevProps.params.acct !== acct) {
|
|
|
|
dispatch(lookupAccount(acct));
|
2022-10-16 15:43:59 +09:00
|
|
|
} else if (prevProps.params.tagged !== tagged) {
|
|
|
|
if (!withReplies) {
|
|
|
|
dispatch(expandAccountFeaturedTimeline(accountId, { tagged }));
|
|
|
|
}
|
|
|
|
dispatch(expandAccountTimeline(accountId, { withReplies, tagged }));
|
2018-05-28 00:42:54 +09:00
|
|
|
}
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2016-10-10 03:18:54 +09:00
|
|
|
|
2023-05-10 16:05:32 +09:00
|
|
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
2021-09-26 12:46:13 +09:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
2018-03-17 03:54:00 +09:00
|
|
|
if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
|
2021-09-26 12:46:13 +09:00
|
|
|
dispatch(fetchAccount(nextProps.params.accountId));
|
2021-11-26 13:58:18 +09:00
|
|
|
|
2018-05-28 00:42:54 +09:00
|
|
|
if (!nextProps.withReplies) {
|
2021-09-26 12:46:13 +09:00
|
|
|
dispatch(expandAccountFeaturedTimeline(nextProps.params.accountId));
|
2018-05-28 00:42:54 +09:00
|
|
|
}
|
2021-11-26 13:58:18 +09:00
|
|
|
|
2021-09-26 12:46:13 +09:00
|
|
|
dispatch(expandAccountTimeline(nextProps.params.accountId, { withReplies: nextProps.params.withReplies }));
|
2016-10-10 03:18:54 +09:00
|
|
|
}
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2016-10-10 03:18:54 +09:00
|
|
|
|
2019-03-09 04:34:31 +09:00
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2019-03-09 04:34:31 +09:00
|
|
|
|
2018-05-28 02:10:37 +09:00
|
|
|
handleLoadMore = maxId => {
|
2022-10-16 15:43:59 +09:00
|
|
|
this.props.dispatch(expandAccountTimeline(this.props.accountId, { maxId, withReplies: this.props.withReplies, tagged: this.props.params.tagged }));
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2016-10-10 03:18:54 +09:00
|
|
|
|
2019-03-09 04:34:31 +09:00
|
|
|
setRef = c => {
|
|
|
|
this.column = c;
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2019-03-09 04:34:31 +09:00
|
|
|
|
2016-10-10 03:18:54 +09:00
|
|
|
render () {
|
2022-05-10 16:44:35 +09:00
|
|
|
const { accountId, statusIds, featuredStatusIds, isLoading, hasMore, suspended, isAccount, hidden, multiColumn, remote, remoteUrl } = this.props;
|
2019-04-09 12:02:48 +09:00
|
|
|
|
2022-10-20 21:35:29 +09:00
|
|
|
if (isLoading && statusIds.isEmpty()) {
|
2019-04-09 12:02:48 +09:00
|
|
|
return (
|
|
|
|
<Column>
|
2022-10-20 21:35:29 +09:00
|
|
|
<LoadingIndicator />
|
2019-04-09 12:02:48 +09:00
|
|
|
</Column>
|
|
|
|
);
|
2022-10-20 21:35:29 +09:00
|
|
|
} else if (!isLoading && !isAccount) {
|
2017-01-31 05:40:55 +09:00
|
|
|
return (
|
2023-04-12 19:44:58 +09:00
|
|
|
<BundleColumnError multiColumn={multiColumn} errorType='routing' />
|
2017-01-31 05:40:55 +09:00
|
|
|
);
|
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;
|
|
|
|
|
2022-05-10 16:44:35 +09:00
|
|
|
const forceEmptyState = suspended || hidden;
|
|
|
|
|
2020-09-10 07:07:19 +09:00
|
|
|
if (suspended) {
|
2020-12-14 17:08:09 +09:00
|
|
|
emptyMessage = <FormattedMessage id='empty_column.account_suspended' defaultMessage='Account suspended' />;
|
2022-05-10 16:44:35 +09:00
|
|
|
} else if (hidden) {
|
|
|
|
emptyMessage = <LimitedAccountHint accountId={accountId} />;
|
2020-09-10 07:07:19 +09:00
|
|
|
} else if (remote && statusIds.isEmpty()) {
|
2024-08-21 16:08:58 +09:00
|
|
|
emptyMessage = <RemoteHint accountId={accountId} url={remoteUrl} />;
|
2020-06-15 05:29:40 +09:00
|
|
|
} else {
|
2022-05-03 17:59:23 +09:00
|
|
|
emptyMessage = <FormattedMessage id='empty_column.account_timeline' defaultMessage='No posts found' />;
|
2020-06-15 05:29:40 +09:00
|
|
|
}
|
|
|
|
|
2024-08-21 16:08:58 +09:00
|
|
|
const remoteMessage = remote ? <RemoteHint accountId={accountId} url={remoteUrl} /> : null;
|
2020-06-15 05:29:40 +09:00
|
|
|
|
2017-01-31 05:40:55 +09:00
|
|
|
return (
|
2023-12-10 04:26:57 +09:00
|
|
|
<Column ref={this.setRef}>
|
2019-08-02 02:17:17 +09:00
|
|
|
<ProfileColumnHeader onClick={this.handleHeaderClick} multiColumn={multiColumn} />
|
2017-01-31 05:40:55 +09:00
|
|
|
|
|
|
|
<StatusList
|
2022-10-16 15:43:59 +09:00
|
|
|
prepend={<HeaderContainer accountId={this.props.accountId} hideTabs={forceEmptyState} tagged={this.props.params.tagged} />}
|
2018-11-10 00:47:50 +09:00
|
|
|
alwaysPrepend
|
2020-06-15 05:29:40 +09:00
|
|
|
append={remoteMessage}
|
2017-04-24 11:49:08 +09:00
|
|
|
scrollKey='account_timeline'
|
2022-05-10 16:44:35 +09:00
|
|
|
statusIds={forceEmptyState ? emptyList : statusIds}
|
2018-03-17 04:29:42 +09:00
|
|
|
featuredStatusIds={featuredStatusIds}
|
2017-01-31 05:40:55 +09:00
|
|
|
isLoading={isLoading}
|
2022-05-10 16:44:35 +09:00
|
|
|
hasMore={!forceEmptyState && hasMore}
|
2018-05-28 00:46:48 +09:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2020-06-15 05:29:40 +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
|
|
|
}
|
2023-03-25 07:15:25 +09:00
|
|
|
|
|
|
|
export default connect(mapStateToProps)(AccountTimeline);
|