2024-01-08 10:57:40 +00:00
|
|
|
import { createSelector } from '@reduxjs/toolkit';
|
2017-07-10 23:00:14 +00:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2017-05-06 09:05:32 +00:00
|
|
|
import { debounce } from 'lodash';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import { scrollTopTimeline, loadPending } from '../../../actions/timelines';
|
|
|
|
import StatusList from '../../../components/status_list';
|
2017-10-31 02:27:48 +00:00
|
|
|
import { me } from '../../../initial_state';
|
2017-01-10 16:25:10 +00:00
|
|
|
|
2019-11-04 12:02:16 +00:00
|
|
|
const makeGetStatusIds = (pending = false) => createSelector([
|
2017-07-10 23:00:14 +00:00
|
|
|
(state, { type }) => state.getIn(['settings', type], ImmutableMap()),
|
2019-11-04 12:02:16 +00:00
|
|
|
(state, { type }) => state.getIn(['timelines', type, pending ? 'pendingItems' : 'items'], ImmutableList()),
|
2017-02-05 01:02:46 +00:00
|
|
|
(state) => state.get('statuses'),
|
2017-10-31 02:27:48 +00:00
|
|
|
], (columnSettings, statusIds, statuses) => {
|
2017-07-18 13:20:38 +00:00
|
|
|
return statusIds.filter(id => {
|
2018-05-08 11:28:55 +00:00
|
|
|
if (id === null) return true;
|
|
|
|
|
2017-07-18 13:20:38 +00:00
|
|
|
const statusForId = statuses.get(id);
|
|
|
|
let showStatus = true;
|
2017-01-10 16:25:10 +00:00
|
|
|
|
2020-06-23 14:01:34 +00:00
|
|
|
if (statusForId.get('account') === me) return true;
|
|
|
|
|
2017-07-18 13:20:38 +00:00
|
|
|
if (columnSettings.getIn(['shows', 'reblog']) === false) {
|
|
|
|
showStatus = showStatus && statusForId.get('reblog') === null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (columnSettings.getIn(['shows', 'reply']) === false) {
|
|
|
|
showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
|
2017-01-10 16:25:10 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 13:20:38 +00:00
|
|
|
return showStatus;
|
|
|
|
});
|
|
|
|
});
|
2016-09-04 12:04:26 +00:00
|
|
|
|
2017-02-20 23:10:49 +00:00
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getStatusIds = makeGetStatusIds();
|
2019-11-04 12:02:16 +00:00
|
|
|
const getPendingStatusIds = makeGetStatusIds(true);
|
2017-02-20 23:10:49 +00:00
|
|
|
|
2017-06-11 15:07:35 +00:00
|
|
|
const mapStateToProps = (state, { timelineId }) => ({
|
|
|
|
statusIds: getStatusIds(state, { type: timelineId }),
|
2023-05-16 13:36:25 +00:00
|
|
|
lastId: state.getIn(['timelines', timelineId, 'items'])?.last(),
|
2017-06-11 15:07:35 +00:00
|
|
|
isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
|
2018-01-17 22:56:03 +00:00
|
|
|
isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
|
2018-03-24 14:25:15 +00:00
|
|
|
hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
|
2019-11-04 12:02:16 +00:00
|
|
|
numPending: getPendingStatusIds(state, { type: timelineId }).size,
|
2017-02-20 23:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
2016-08-24 15:56:44 +00:00
|
|
|
|
2018-03-24 14:25:15 +00:00
|
|
|
const mapDispatchToProps = (dispatch, { timelineId }) => ({
|
2016-12-03 20:04:57 +00:00
|
|
|
|
2017-05-06 09:05:32 +00:00
|
|
|
onScrollToTop: debounce(() => {
|
2017-06-11 15:07:35 +00:00
|
|
|
dispatch(scrollTopTimeline(timelineId, true));
|
2017-05-06 09:05:32 +00:00
|
|
|
}, 100),
|
2017-01-10 16:25:10 +00:00
|
|
|
|
2017-05-06 09:05:32 +00:00
|
|
|
onScroll: debounce(() => {
|
2017-06-11 15:07:35 +00:00
|
|
|
dispatch(scrollTopTimeline(timelineId, false));
|
2017-05-20 15:31:47 +00:00
|
|
|
}, 100),
|
2017-01-10 16:25:10 +00:00
|
|
|
|
2019-07-16 04:30:47 +00:00
|
|
|
onLoadPending: () => dispatch(loadPending(timelineId)),
|
|
|
|
|
2017-01-10 16:25:10 +00:00
|
|
|
});
|
2016-08-31 20:58:10 +00:00
|
|
|
|
2017-02-20 23:10:49 +00:00
|
|
|
export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);
|