2016-11-05 14:20:05 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-12-04 07:26:40 +00:00
|
|
|
import StatusList from 'flavours/glitch/components/status_list';
|
2019-07-16 04:30:47 +00:00
|
|
|
import { scrollTopTimeline, loadPending } from 'flavours/glitch/actions/timelines';
|
2017-07-10 23:00:14 +00:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
2017-01-10 16:25:10 +00:00
|
|
|
import { createSelector } from 'reselect';
|
2017-05-06 09:05:32 +00:00
|
|
|
import { debounce } from 'lodash';
|
2017-12-04 07:26:40 +00:00
|
|
|
import { me } from 'flavours/glitch/util/initial_state';
|
2017-01-10 16:25:10 +00:00
|
|
|
|
2019-06-29 13:24:44 +00:00
|
|
|
const getRegex = createSelector([
|
|
|
|
(state, { type }) => state.getIn(['settings', type, 'regex', 'body']),
|
|
|
|
], (rawRegex) => {
|
|
|
|
let regex = null;
|
2017-01-10 16:25:10 +00:00
|
|
|
|
2017-07-18 13:20:38 +00:00
|
|
|
try {
|
2019-06-29 13:24:44 +00:00
|
|
|
regex = rawRegex && new RegExp(rawRegex.trim(), 'i');
|
2017-07-18 13:20:38 +00:00
|
|
|
} catch (e) {
|
|
|
|
// Bad regex, don't affect filters
|
2017-01-10 16:25:10 +00:00
|
|
|
}
|
2019-06-29 13:24:44 +00:00
|
|
|
return regex;
|
|
|
|
});
|
|
|
|
|
|
|
|
const makeGetStatusIds = () => createSelector([
|
|
|
|
(state, { type }) => state.getIn(['settings', type], ImmutableMap()),
|
|
|
|
(state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()),
|
|
|
|
(state) => state.get('statuses'),
|
|
|
|
getRegex,
|
|
|
|
], (columnSettings, statusIds, statuses, regex) => {
|
|
|
|
const rawRegex = columnSettings.getIn(['regex', 'body'], '').trim();
|
2017-01-10 16:25:10 +00:00
|
|
|
|
2017-07-18 13:20:38 +00:00
|
|
|
return statusIds.filter(id => {
|
2018-05-27 17:35:27 +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
|
|
|
|
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-12-07 01:50:27 +00:00
|
|
|
if (columnSettings.getIn(['shows', 'direct']) === false) {
|
|
|
|
showStatus = showStatus && statusForId.get('visibility') !== 'direct';
|
|
|
|
}
|
|
|
|
|
2017-07-18 13:20:38 +00:00
|
|
|
if (showStatus && regex && statusForId.get('account') !== me) {
|
|
|
|
const searchIndex = statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index');
|
|
|
|
showStatus = !regex.test(searchIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return showStatus;
|
|
|
|
});
|
|
|
|
});
|
2016-09-04 12:04:26 +00:00
|
|
|
|
2017-02-20 23:10:49 +00:00
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getStatusIds = makeGetStatusIds();
|
|
|
|
|
2017-06-11 15:07:35 +00:00
|
|
|
const mapStateToProps = (state, { timelineId }) => ({
|
|
|
|
statusIds: getStatusIds(state, { type: timelineId }),
|
|
|
|
isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
|
2018-01-18 16:25:37 +00:00
|
|
|
isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
|
2018-05-27 17:10:37 +00:00
|
|
|
hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
|
2019-07-16 04:30:47 +00:00
|
|
|
numPending: state.getIn(['timelines', timelineId, 'pendingItems'], ImmutableList()).size,
|
2017-02-20 23:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
2016-08-24 15:56:44 +00:00
|
|
|
|
2018-05-27 17:10:37 +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);
|