|
|
@ -1,4 +1,6 @@ |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import Immutable from 'immutable'; |
|
|
|
import { createSelector } from 'reselect'; |
|
|
|
import Status from '../components/status'; |
|
|
|
import { makeGetStatus } from '../selectors'; |
|
|
|
import { |
|
|
@ -27,7 +29,7 @@ import { initBlockModal } from '../actions/blocks'; |
|
|
|
import { initReport } from '../actions/reports'; |
|
|
|
import { openModal } from '../actions/modal'; |
|
|
|
import { defineMessages, injectIntl } from 'react-intl'; |
|
|
|
import { boostModal, deleteModal } from '../initial_state'; |
|
|
|
import { boostModal, deleteModal, treeRoot } from '../initial_state'; |
|
|
|
import { showAlertForError } from '../actions/alerts'; |
|
|
|
|
|
|
|
const messages = defineMessages({ |
|
|
@ -41,20 +43,68 @@ const messages = defineMessages({ |
|
|
|
|
|
|
|
const makeMapStateToProps = () => { |
|
|
|
const getStatus = makeGetStatus(); |
|
|
|
|
|
|
|
const getAncestorsIds = createSelector([ |
|
|
|
(_, { id }) => id, |
|
|
|
state => state.getIn(['contexts', 'inReplyTos']), |
|
|
|
], (statusId, inReplyTos) => { |
|
|
|
let ancestorsIds = Immutable.List(); |
|
|
|
ancestorsIds = ancestorsIds.withMutations(mutable => { |
|
|
|
let id = statusId; |
|
|
|
|
|
|
|
while (id) { |
|
|
|
mutable.unshift(id); |
|
|
|
id = inReplyTos.get(id); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return ancestorsIds; |
|
|
|
}); |
|
|
|
|
|
|
|
const getAncestorsText = createSelector([ |
|
|
|
(_, {ids}) => ids, |
|
|
|
state => state.get('statuses'), |
|
|
|
], (ids, statuses) => ids.map(i => { |
|
|
|
let text = statuses.get(i) ? statuses.get(i).get('search_index') : i; |
|
|
|
if(text.length > 16) |
|
|
|
text = text.slice(0,13) + "..."; |
|
|
|
return text; |
|
|
|
}).join(' >> ') |
|
|
|
); |
|
|
|
|
|
|
|
const getSonsIds = createSelector([ |
|
|
|
(_, {id}) => id, |
|
|
|
state => state.getIn(['contexts', 'replies']), |
|
|
|
], (statusId, contextReplies) => { |
|
|
|
const sons = contextReplies.get(statusId); |
|
|
|
return sons ? sons.map(id => ({ |
|
|
|
'id': id, |
|
|
|
'sonsIds' : contextReplies.get(id), |
|
|
|
})) |
|
|
|
: null; |
|
|
|
}); |
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => { |
|
|
|
const status = getStatus(state, props); |
|
|
|
const sons = (props.showThread && status!==null) ? state.getIn(['contexts', 'replies', status.getIn(['reblog', 'id'], props.id)]) : null; |
|
|
|
return ({ |
|
|
|
'status': status, |
|
|
|
'sonsIds': (props.showThread && sons) ? sons.map(id => ({ |
|
|
|
'id': id, |
|
|
|
'sonsIds' : state.getIn(['contexts', 'replies', id]) |
|
|
|
})) |
|
|
|
: |
|
|
|
null, |
|
|
|
}) |
|
|
|
} |
|
|
|
let ancestorsIds = Immutable.List(); |
|
|
|
let ancestorsText; |
|
|
|
let sonsIds; |
|
|
|
|
|
|
|
if (props.showThread && status) { |
|
|
|
sonsIds = getSonsIds(state, { id : status.getIn(['reblog', 'id'], props.id)}); |
|
|
|
if(status.get('reblog')) { |
|
|
|
ancestorsIds = getAncestorsIds(state, { id: status.getIn(['reblog', 'in_reply_to_id']) }); |
|
|
|
if(ancestorsIds && ancestorsIds.first() == treeRoot.split('/').pop()) { |
|
|
|
ancestorsText = getAncestorsText(state, { ids: ancestorsIds.shift() }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return { |
|
|
|
status, |
|
|
|
ancestorsText, |
|
|
|
sonsIds, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
return mapStateToProps; |
|
|
|
}; |
|
|
|