[Glitch] Introduce flat layout to contexts reducer
Port 023fe5181b
to glitch-soc
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import Immutable from 'immutable';
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
@ -57,13 +58,49 @@ const messages = defineMessages({
|
||||
const makeMapStateToProps = () => {
|
||||
const getStatus = makeGetStatus();
|
||||
|
||||
const mapStateToProps = (state, props) => ({
|
||||
status: getStatus(state, { id: props.params.statusId }),
|
||||
settings: state.get('local_settings'),
|
||||
ancestorsIds: state.getIn(['contexts', 'ancestors', props.params.statusId]),
|
||||
descendantsIds: state.getIn(['contexts', 'descendants', props.params.statusId]),
|
||||
askReplyConfirmation: state.getIn(['compose', 'text']).trim().length !== 0,
|
||||
});
|
||||
const mapStateToProps = (state, props) => {
|
||||
const status = getStatus(state, { id: props.params.statusId });
|
||||
let ancestorsIds = Immutable.List();
|
||||
let descendantsIds = Immutable.List();
|
||||
|
||||
if (status) {
|
||||
ancestorsIds = ancestorsIds.withMutations(mutable => {
|
||||
function addAncestor(id) {
|
||||
if (id) {
|
||||
const inReplyTo = state.getIn(['contexts', 'inReplyTos', id]);
|
||||
|
||||
mutable.unshift(id);
|
||||
addAncestor(inReplyTo);
|
||||
}
|
||||
}
|
||||
|
||||
addAncestor(status.get('in_reply_to_id'));
|
||||
});
|
||||
|
||||
descendantsIds = descendantsIds.withMutations(mutable => {
|
||||
function addDescendantOf(id) {
|
||||
const replies = state.getIn(['contexts', 'replies', id]);
|
||||
|
||||
if (replies) {
|
||||
replies.forEach(reply => {
|
||||
mutable.push(reply);
|
||||
addDescendantOf(reply);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addDescendantOf(status.get('id'));
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
status,
|
||||
ancestorsIds,
|
||||
descendantsIds,
|
||||
settings: state.get('local_settings'),
|
||||
askReplyConfirmation: state.getIn(['compose', 'text']).trim().length !== 0,
|
||||
};
|
||||
};
|
||||
|
||||
return mapStateToProps;
|
||||
};
|
||||
|
Reference in New Issue
Block a user