2016-11-23 21:57:57 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import Status from '../components/status';
|
2016-10-24 15:11:02 +00:00
|
|
|
import { makeGetStatus } from '../selectors';
|
|
|
|
import {
|
|
|
|
replyCompose,
|
|
|
|
mentionCompose
|
2016-11-23 21:57:57 +00:00
|
|
|
} from '../actions/compose';
|
2016-10-24 15:11:02 +00:00
|
|
|
import {
|
|
|
|
reblog,
|
|
|
|
favourite,
|
|
|
|
unreblog,
|
|
|
|
unfavourite
|
2016-11-23 21:57:57 +00:00
|
|
|
} from '../actions/interactions';
|
|
|
|
import { blockAccount } from '../actions/accounts';
|
|
|
|
import { deleteStatus } from '../actions/statuses';
|
|
|
|
import { openMedia } from '../actions/modal';
|
2016-11-04 11:48:53 +00:00
|
|
|
import { createSelector } from 'reselect'
|
2017-01-08 10:04:01 +00:00
|
|
|
import { isMobile } from '../is_mobile'
|
2016-10-24 15:11:02 +00:00
|
|
|
|
2016-11-04 11:48:53 +00:00
|
|
|
const mapStateToProps = (state, props) => ({
|
|
|
|
statusBase: state.getIn(['statuses', props.id]),
|
|
|
|
me: state.getIn(['meta', 'me'])
|
|
|
|
});
|
|
|
|
|
|
|
|
const makeMapStateToPropsInner = () => {
|
|
|
|
const getStatus = (() => {
|
|
|
|
return createSelector(
|
|
|
|
[
|
|
|
|
(_, base) => base,
|
|
|
|
(state, base) => (base ? state.getIn(['accounts', base.get('account')]) : null),
|
|
|
|
(state, base) => (base ? state.getIn(['statuses', base.get('reblog')], null) : null)
|
|
|
|
],
|
|
|
|
|
|
|
|
(base, account, reblog) => (base ? base.set('account', account).set('reblog', reblog) : null)
|
|
|
|
);
|
|
|
|
})();
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { statusBase }) => ({
|
|
|
|
status: getStatus(state, statusBase)
|
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeMapStateToPropsLast = () => {
|
|
|
|
const getStatus = (() => {
|
|
|
|
return createSelector(
|
|
|
|
[
|
|
|
|
(_, status) => status,
|
|
|
|
(state, status) => (status ? state.getIn(['accounts', status.getIn(['reblog', 'account'])], null) : null)
|
|
|
|
],
|
|
|
|
|
|
|
|
(status, reblogAccount) => (status && status.get('reblog') ? status.setIn(['reblog', 'account'], reblogAccount) : status)
|
|
|
|
);
|
|
|
|
})();
|
2016-10-24 15:11:02 +00:00
|
|
|
|
2016-11-04 11:48:53 +00:00
|
|
|
const mapStateToProps = (state, { status }) => ({
|
|
|
|
status: getStatus(state, status)
|
2016-10-24 15:11:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
2016-11-21 09:52:11 +00:00
|
|
|
onReply (status, router) {
|
|
|
|
dispatch(replyCompose(status, router));
|
2016-10-24 15:11:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onReblog (status) {
|
|
|
|
if (status.get('reblogged')) {
|
|
|
|
dispatch(unreblog(status));
|
|
|
|
} else {
|
|
|
|
dispatch(reblog(status));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onFavourite (status) {
|
|
|
|
if (status.get('favourited')) {
|
|
|
|
dispatch(unfavourite(status));
|
|
|
|
} else {
|
|
|
|
dispatch(favourite(status));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDelete (status) {
|
|
|
|
dispatch(deleteStatus(status.get('id')));
|
|
|
|
},
|
|
|
|
|
2017-01-08 10:04:01 +00:00
|
|
|
onMention (account, router) {
|
2017-01-30 20:40:55 +00:00
|
|
|
dispatch(mentionCompose(account, router));
|
2016-10-24 16:07:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onOpenMedia (url) {
|
|
|
|
dispatch(openMedia(url));
|
2016-11-23 21:57:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onBlock (account) {
|
|
|
|
dispatch(blockAccount(account.get('id')));
|
2016-10-24 15:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-11-04 11:48:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(
|
|
|
|
connect(makeMapStateToPropsInner)(
|
|
|
|
connect(makeMapStateToPropsLast)(Status)
|
|
|
|
)
|
|
|
|
);
|