2019-07-02 08:10:25 +01:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
|
|
|
import { createSelector } from 'reselect';
|
2020-01-29 20:08:56 +00:00
|
|
|
import { debounce, sample } from 'lodash';
|
|
|
|
import { dequeueTimeline } from '../actions/timelines';
|
2019-08-07 06:02:36 +01:00
|
|
|
import { scrollTopTimeline } from '../actions/timelines';
|
2020-01-28 16:29:26 +00:00
|
|
|
import { fetchStatus } from '../actions/statuses';
|
2020-01-29 21:53:33 +00:00
|
|
|
import { me, promotions } from '../initial_state';
|
2020-01-29 16:45:17 +00:00
|
|
|
import StatusList from '../components/status_list';
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
const makeGetStatusIds = () => createSelector([
|
2019-08-09 01:41:56 +01:00
|
|
|
(state, { type, id }) => state.getIn(['settings', type], ImmutableMap()),
|
|
|
|
(state, { type, id }) => state.getIn(['timelines', id, 'items'], ImmutableList()),
|
2019-07-02 08:10:25 +01:00
|
|
|
(state) => state.get('statuses'),
|
|
|
|
], (columnSettings, statusIds, statuses) => {
|
|
|
|
return statusIds.filter(id => {
|
|
|
|
if (id === null) return true;
|
|
|
|
|
|
|
|
const statusForId = statuses.get(id);
|
|
|
|
let showStatus = true;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return showStatus;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-11 17:13:32 +01:00
|
|
|
const mapStateToProps = (state, {timelineId}) => {
|
2019-07-02 08:10:25 +01:00
|
|
|
const getStatusIds = makeGetStatusIds();
|
2019-08-31 12:54:03 +01:00
|
|
|
const promotion = promotions.length > 0 && sample(promotions.filter(p => p.timeline_id === timelineId));
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2019-07-11 17:13:32 +01:00
|
|
|
return {
|
2019-08-09 01:41:56 +01:00
|
|
|
statusIds: getStatusIds(state, { type: timelineId.substring(0,5) === 'group' ? 'group' : timelineId, id: timelineId }),
|
2019-07-02 08:10:25 +01:00
|
|
|
isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
|
|
|
|
isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
|
|
|
|
hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
|
2019-07-11 17:13:32 +01:00
|
|
|
totalQueuedItemsCount: state.getIn(['timelines', timelineId, 'totalQueuedItemsCount']),
|
2019-08-31 12:54:03 +01:00
|
|
|
promotion: promotion,
|
|
|
|
promotedStatus: promotion && state.getIn(['statuses', promotion.status_id])
|
2019-07-11 17:13:32 +01:00
|
|
|
};
|
2019-07-02 08:10:25 +01:00
|
|
|
};
|
|
|
|
|
2019-07-11 17:13:32 +01:00
|
|
|
const mapDispatchToProps = (dispatch, ownProps) => ({
|
|
|
|
onDequeueTimeline(timelineId) {
|
|
|
|
dispatch(dequeueTimeline(timelineId, ownProps.onLoadMore));
|
|
|
|
},
|
2019-07-17 23:59:50 +01:00
|
|
|
onScrollToTop: debounce(() => {
|
|
|
|
dispatch(scrollTopTimeline(ownProps.timelineId, true));
|
|
|
|
}, 100),
|
|
|
|
onScroll: debounce(() => {
|
|
|
|
dispatch(scrollTopTimeline(ownProps.timelineId, false));
|
|
|
|
}, 100),
|
2019-08-31 12:54:03 +01:00
|
|
|
fetchStatus(id) {
|
|
|
|
dispatch(fetchStatus(id));
|
|
|
|
}
|
2019-07-11 17:13:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(StatusList);
|