2017-04-21 18:05:35 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2023-08-07 07:46:11 +00:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import { Helmet } from 'react-helmet';
|
|
|
|
|
2022-07-22 13:52:06 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import { isEqual } from 'lodash';
|
|
|
|
|
2024-01-16 10:27:26 +00:00
|
|
|
import TagIcon from '@/material-icons/400-24px/tag.svg?react';
|
2022-07-22 13:52:06 +00:00
|
|
|
import { addColumn, removeColumn, moveColumn } from 'mastodon/actions/columns';
|
|
|
|
import { connectHashtagStream } from 'mastodon/actions/streaming';
|
|
|
|
import { fetchHashtag, followHashtag, unfollowHashtag } from 'mastodon/actions/tags';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { expandHashtagTimeline, clearTimeline } from 'mastodon/actions/timelines';
|
|
|
|
import Column from 'mastodon/components/column';
|
|
|
|
import ColumnHeader from 'mastodon/components/column_header';
|
2024-05-19 17:07:32 +00:00
|
|
|
import { identityContextPropShape, withIdentity } from 'mastodon/identity_context';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import StatusListContainer from '../ui/containers/status_list_container';
|
|
|
|
|
2023-08-07 07:46:11 +00:00
|
|
|
import { HashtagHeader } from './components/hashtag_header';
|
2023-05-23 15:15:17 +00:00
|
|
|
import ColumnSettingsContainer from './containers/column_settings_container';
|
2022-07-22 13:52:06 +00:00
|
|
|
|
2017-08-20 15:12:06 +00:00
|
|
|
const mapStateToProps = (state, props) => ({
|
2020-05-23 03:46:29 +00:00
|
|
|
hasUnread: state.getIn(['timelines', `hashtag:${props.params.id}${props.params.local ? ':local' : ''}`, 'unread']) > 0,
|
2022-07-22 13:52:06 +00:00
|
|
|
tag: state.getIn(['tags', props.params.id]),
|
2017-02-03 23:34:31 +00:00
|
|
|
});
|
2016-11-05 14:20:05 +00:00
|
|
|
|
2023-05-23 08:52:27 +00:00
|
|
|
class HashtagTimeline extends PureComponent {
|
2018-11-05 17:53:25 +00:00
|
|
|
disconnects = [];
|
|
|
|
|
2017-05-12 12:44:10 +00:00
|
|
|
static propTypes = {
|
2024-05-19 17:07:32 +00:00
|
|
|
identity: identityContextPropShape,
|
2017-05-12 12:44:10 +00:00
|
|
|
params: PropTypes.object.isRequired,
|
2017-06-03 23:39:38 +00:00
|
|
|
columnId: PropTypes.string,
|
2017-05-12 12:44:10 +00:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-05-20 15:31:47 +00:00
|
|
|
hasUnread: PropTypes.bool,
|
2022-07-22 13:52:06 +00:00
|
|
|
tag: ImmutablePropTypes.map,
|
2017-06-03 23:39:38 +00:00
|
|
|
multiColumn: PropTypes.bool,
|
2017-05-12 12:44:10 +00:00
|
|
|
};
|
|
|
|
|
2017-06-03 23:39:38 +00:00
|
|
|
handlePin = () => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (columnId) {
|
|
|
|
dispatch(removeColumn(columnId));
|
|
|
|
} else {
|
|
|
|
dispatch(addColumn('HASHTAG', { id: this.props.params.id }));
|
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-06-03 23:39:38 +00:00
|
|
|
|
2018-11-05 17:53:25 +00:00
|
|
|
title = () => {
|
2022-07-22 13:52:06 +00:00
|
|
|
const { id } = this.props.params;
|
|
|
|
const title = [id];
|
2019-02-14 14:46:42 +00:00
|
|
|
|
2018-11-05 17:53:25 +00:00
|
|
|
if (this.additionalFor('any')) {
|
2019-02-14 14:46:42 +00:00
|
|
|
title.push(' ', <FormattedMessage key='any' id='hashtag.column_header.tag_mode.any' values={{ additional: this.additionalFor('any') }} defaultMessage='or {additional}' />);
|
2018-11-05 17:53:25 +00:00
|
|
|
}
|
2019-02-14 14:46:42 +00:00
|
|
|
|
2018-11-05 17:53:25 +00:00
|
|
|
if (this.additionalFor('all')) {
|
2019-02-14 14:46:42 +00:00
|
|
|
title.push(' ', <FormattedMessage key='all' id='hashtag.column_header.tag_mode.all' values={{ additional: this.additionalFor('all') }} defaultMessage='and {additional}' />);
|
2018-11-05 17:53:25 +00:00
|
|
|
}
|
2019-02-14 14:46:42 +00:00
|
|
|
|
2018-11-05 17:53:25 +00:00
|
|
|
if (this.additionalFor('none')) {
|
2019-02-14 14:46:42 +00:00
|
|
|
title.push(' ', <FormattedMessage key='none' id='hashtag.column_header.tag_mode.none' values={{ additional: this.additionalFor('none') }} defaultMessage='without {additional}' />);
|
2018-11-05 17:53:25 +00:00
|
|
|
}
|
2019-02-14 14:46:42 +00:00
|
|
|
|
2018-11-05 17:53:25 +00:00
|
|
|
return title;
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2018-11-05 17:53:25 +00:00
|
|
|
|
|
|
|
additionalFor = (mode) => {
|
|
|
|
const { tags } = this.props.params;
|
|
|
|
|
|
|
|
if (tags && (tags[mode] || []).length > 0) {
|
|
|
|
return tags[mode].map(tag => tag.value).join('/');
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2018-11-05 17:53:25 +00:00
|
|
|
|
2017-06-03 23:39:38 +00:00
|
|
|
handleMove = (dir) => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
dispatch(moveColumn(columnId, dir));
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-06-03 23:39:38 +00:00
|
|
|
|
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-06-03 23:39:38 +00:00
|
|
|
|
2020-05-23 03:46:29 +00:00
|
|
|
_subscribe (dispatch, id, tags = {}, local) {
|
2024-05-19 17:07:32 +00:00
|
|
|
const { signedIn } = this.props.identity;
|
2022-10-08 05:15:50 +00:00
|
|
|
|
|
|
|
if (!signedIn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-05 17:53:25 +00:00
|
|
|
let any = (tags.any || []).map(tag => tag.value);
|
|
|
|
let all = (tags.all || []).map(tag => tag.value);
|
|
|
|
let none = (tags.none || []).map(tag => tag.value);
|
|
|
|
|
2019-02-14 14:46:42 +00:00
|
|
|
[id, ...any].map(tag => {
|
2020-05-23 03:46:29 +00:00
|
|
|
this.disconnects.push(dispatch(connectHashtagStream(id, tag, local, status => {
|
2018-11-05 17:53:25 +00:00
|
|
|
let tags = status.tags.map(tag => tag.name);
|
2019-02-14 14:46:42 +00:00
|
|
|
|
2018-11-05 17:53:25 +00:00
|
|
|
return all.filter(tag => tags.includes(tag)).length === all.length &&
|
|
|
|
none.filter(tag => tags.includes(tag)).length === 0;
|
|
|
|
})));
|
|
|
|
});
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-11-05 14:20:05 +00:00
|
|
|
|
|
|
|
_unsubscribe () {
|
2018-11-05 17:53:25 +00:00
|
|
|
this.disconnects.map(disconnect => disconnect());
|
|
|
|
this.disconnects = [];
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-11-05 14:20:05 +00:00
|
|
|
|
2022-07-22 13:52:06 +00:00
|
|
|
_unload () {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
const { id, local } = this.props.params;
|
|
|
|
|
|
|
|
this._unsubscribe();
|
|
|
|
dispatch(clearTimeline(`hashtag:${id}${local ? ':local' : ''}`));
|
|
|
|
}
|
|
|
|
|
|
|
|
_load() {
|
2016-11-05 14:20:05 +00:00
|
|
|
const { dispatch } = this.props;
|
2020-04-18 19:52:39 +00:00
|
|
|
const { id, tags, local } = this.props.params;
|
2016-11-05 14:20:05 +00:00
|
|
|
|
2020-05-23 03:46:29 +00:00
|
|
|
this._subscribe(dispatch, id, tags, local);
|
2020-04-18 19:52:39 +00:00
|
|
|
dispatch(expandHashtagTimeline(id, { tags, local }));
|
2022-07-22 13:52:06 +00:00
|
|
|
dispatch(fetchHashtag(id));
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-11-05 14:20:05 +00:00
|
|
|
|
2022-07-22 13:52:06 +00:00
|
|
|
componentDidMount () {
|
|
|
|
this._load();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
const { params } = this.props;
|
|
|
|
const { id, tags, local } = prevProps.params;
|
2019-02-14 14:46:42 +00:00
|
|
|
|
2020-04-18 19:52:39 +00:00
|
|
|
if (id !== params.id || !isEqual(tags, params.tags) || !isEqual(local, params.local)) {
|
2022-07-22 13:52:06 +00:00
|
|
|
this._unload();
|
|
|
|
this._load();
|
2016-11-05 14:20:05 +00:00
|
|
|
}
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-11-05 14:20:05 +00:00
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this._unsubscribe();
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-11-05 14:20:05 +00:00
|
|
|
|
2017-06-03 23:39:38 +00:00
|
|
|
setRef = c => {
|
|
|
|
this.column = c;
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-06-03 23:39:38 +00:00
|
|
|
|
2018-03-24 14:25:15 +00:00
|
|
|
handleLoadMore = maxId => {
|
2022-07-22 13:52:06 +00:00
|
|
|
const { dispatch, params } = this.props;
|
|
|
|
const { id, tags, local } = params;
|
|
|
|
|
|
|
|
dispatch(expandHashtagTimeline(id, { maxId, tags, local }));
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2022-07-22 13:52:06 +00:00
|
|
|
|
|
|
|
handleFollow = () => {
|
|
|
|
const { dispatch, params, tag } = this.props;
|
|
|
|
const { id } = params;
|
2024-05-19 17:07:32 +00:00
|
|
|
const { signedIn } = this.props.identity;
|
2022-09-29 02:39:33 +00:00
|
|
|
|
|
|
|
if (!signedIn) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-22 13:52:06 +00:00
|
|
|
|
|
|
|
if (tag.get('following')) {
|
|
|
|
dispatch(unfollowHashtag(id));
|
|
|
|
} else {
|
|
|
|
dispatch(followHashtag(id));
|
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-06-11 15:07:35 +00:00
|
|
|
|
2016-11-05 14:20:05 +00:00
|
|
|
render () {
|
2023-08-07 07:46:11 +00:00
|
|
|
const { hasUnread, columnId, multiColumn, tag } = this.props;
|
2020-05-23 03:46:29 +00:00
|
|
|
const { id, local } = this.props.params;
|
2017-06-03 23:39:38 +00:00
|
|
|
const pinned = !!columnId;
|
2024-05-19 17:07:32 +00:00
|
|
|
const { signedIn } = this.props.identity;
|
2016-11-05 14:20:05 +00:00
|
|
|
|
|
|
|
return (
|
2019-08-01 17:17:17 +00:00
|
|
|
<Column bindToDocument={!multiColumn} ref={this.setRef} label={`#${id}`}>
|
2017-06-03 23:39:38 +00:00
|
|
|
<ColumnHeader
|
|
|
|
icon='hashtag'
|
2023-10-24 17:45:08 +00:00
|
|
|
iconComponent={TagIcon}
|
2017-06-03 23:39:38 +00:00
|
|
|
active={hasUnread}
|
2018-11-05 17:53:25 +00:00
|
|
|
title={this.title()}
|
2017-06-03 23:39:38 +00:00
|
|
|
onPin={this.handlePin}
|
|
|
|
onMove={this.handleMove}
|
|
|
|
onClick={this.handleHeaderClick}
|
|
|
|
pinned={pinned}
|
|
|
|
multiColumn={multiColumn}
|
2017-06-06 11:20:07 +00:00
|
|
|
showBackButton
|
2018-11-05 17:53:25 +00:00
|
|
|
>
|
|
|
|
{columnId && <ColumnSettingsContainer columnId={columnId} />}
|
|
|
|
</ColumnHeader>
|
2017-06-03 23:39:38 +00:00
|
|
|
|
|
|
|
<StatusListContainer
|
2023-08-09 14:32:40 +00:00
|
|
|
prepend={pinned ? null : <HashtagHeader tag={tag} disabled={!signedIn} onClick={this.handleFollow} />}
|
2023-08-07 07:46:11 +00:00
|
|
|
alwaysPrepend
|
2017-06-05 13:20:46 +00:00
|
|
|
trackScroll={!pinned}
|
2017-06-03 23:39:38 +00:00
|
|
|
scrollKey={`hashtag_timeline-${columnId}`}
|
2020-05-23 03:46:29 +00:00
|
|
|
timelineId={`hashtag:${id}${local ? ':local' : ''}`}
|
2018-03-24 14:25:15 +00:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2017-06-03 23:39:38 +00:00
|
|
|
emptyMessage={<FormattedMessage id='empty_column.hashtag' defaultMessage='There is nothing in this hashtag yet.' />}
|
2019-07-19 07:25:22 +00:00
|
|
|
bindToDocument={!multiColumn}
|
2017-06-03 23:39:38 +00:00
|
|
|
/>
|
2022-09-29 02:39:33 +00:00
|
|
|
|
|
|
|
<Helmet>
|
2022-10-09 01:55:09 +00:00
|
|
|
<title>#{id}</title>
|
2022-10-20 12:35:29 +00:00
|
|
|
<meta name='robots' content='noindex' />
|
2022-09-29 02:39:33 +00:00
|
|
|
</Helmet>
|
2016-11-05 14:20:05 +00:00
|
|
|
</Column>
|
|
|
|
);
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-11-05 14:20:05 +00:00
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2023-03-24 02:17:53 +00:00
|
|
|
|
2024-05-19 17:07:32 +00:00
|
|
|
export default connect(mapStateToProps)(withIdentity(HashtagTimeline));
|