--- /dev/null
+import { openModal } from './modal';
+
+export const BOOSTS_INIT_MODAL = 'BOOSTS_INIT_MODAL';
+export const BOOSTS_CHANGE_PRIVACY = 'BOOSTS_CHANGE_PRIVACY';
+
+export function initBoostModal(props) {
+ return (dispatch, getState) => {
+ const default_privacy = getState().getIn(['compose', 'default_privacy']);
+
+ const privacy = props.status.get('visibility') === 'private' ? 'private' : default_privacy;
+
+ dispatch({
+ type: BOOSTS_INIT_MODAL,
+ privacy
+ });
+
+ dispatch(openModal('BOOST', props));
+ };
+}
+
+
+export function changeBoostPrivacy(privacy) {
+ return dispatch => {
+ dispatch({
+ type: BOOSTS_CHANGE_PRIVACY,
+ privacy,
+ });
+ };
+}
export const UNBOOKMARK_SUCCESS = 'UNBOOKMARKED_SUCCESS';
export const UNBOOKMARK_FAIL = 'UNBOOKMARKED_FAIL';
-export function reblog(status) {
+export function reblog(status, visibility) {
return function (dispatch, getState) {
dispatch(reblogRequest(status));
- api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then(function (response) {
+ api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`, { visibility }).then(function (response) {
// The reblog API method returns a new status wrapped around the original. In this case we are only
// interested in how the original is modified, hence passing it skipping the wrapper
dispatch(importFetchedStatus(response.data.reblog));
disabled: PropTypes.bool,
status: ImmutablePropTypes.map,
isUserTouching: PropTypes.func,
- isModalOpen: PropTypes.bool.isRequired,
onOpen: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
dropdownPlacement: PropTypes.string,
import { isUserTouching } from '../is_mobile';
const mapStateToProps = state => ({
- isModalOpen: state.get('modal').modalType === 'ACTIONS',
dropdownPlacement: state.getIn(['dropdown_menu', 'placement']),
openDropdownId: state.getIn(['dropdown_menu', 'openId']),
openedViaKeyboard: state.getIn(['dropdown_menu', 'keyboard']),
} from '../actions/domain_blocks';
import { initMuteModal } from '../actions/mutes';
import { initBlockModal } from '../actions/blocks';
+import { initBoostModal } from '../actions/boosts';
import { initReport } from '../actions/reports';
import { openModal } from '../actions/modal';
import { deployPictureInPicture } from '../actions/picture_in_picture';
});
},
- onModalReblog (status) {
+ onModalReblog (status, privacy) {
if (status.get('reblogged')) {
dispatch(unreblog(status));
} else {
- dispatch(reblog(status));
+ dispatch(reblog(status, privacy));
}
},
if ((e && e.shiftKey) || !boostModal) {
this.onModalReblog(status);
} else {
- dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
+ dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
}
},
// It should not be transformed when mounting because the resulting
// size will be used to determine the coordinate of the menu by
// react-overlays
- <div className={`privacy-dropdown__dropdown ${placement}`} style={{ ...style, opacity: opacity, transform: mounted ? `scale(${scaleX}, ${scaleY})` : null, zIndex: 2 }} role='listbox' ref={this.setRef}>
+ <div className={`privacy-dropdown__dropdown ${placement}`} style={{ ...style, opacity: opacity, transform: mounted ? `scale(${scaleX}, ${scaleY})` : null }} role='listbox' ref={this.setRef}>
{items.map(item => (
<div role='option' tabIndex='0' key={item.value} data-index={item.value} onKeyDown={this.handleKeyDown} onClick={this.handleClick} className={classNames('privacy-dropdown__option', { active: item.value === value })} aria-selected={item.value === value} ref={item.value === value ? this.setFocusRef : null}>
<div className='privacy-dropdown__option__icon'>
static propTypes = {
isUserTouching: PropTypes.func,
- isModalOpen: PropTypes.bool.isRequired,
onModalOpen: PropTypes.func,
onModalClose: PropTypes.func,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
+ noDirect: PropTpes.bool,
+ container: PropTypes.func,
intl: PropTypes.object.isRequired,
};
};
handleToggle = ({ target }) => {
- if (this.props.isUserTouching()) {
+ if (this.props.isUserTouching && this.props.isUserTouching()) {
if (this.state.open) {
this.props.onModalClose();
} else {
{ icon: 'globe', value: 'public', text: formatMessage(messages.public_short), meta: formatMessage(messages.public_long) },
{ icon: 'unlock', value: 'unlisted', text: formatMessage(messages.unlisted_short), meta: formatMessage(messages.unlisted_long) },
{ icon: 'lock', value: 'private', text: formatMessage(messages.private_short), meta: formatMessage(messages.private_long) },
- { icon: 'envelope', value: 'direct', text: formatMessage(messages.direct_short), meta: formatMessage(messages.direct_long) },
];
+
+ if (!this.props.noDirect) {
+ this.options.push(
+ { icon: 'envelope', value: 'direct', text: formatMessage(messages.direct_short), meta: formatMessage(messages.direct_long) },
+ );
+ }
}
render () {
- const { value, intl } = this.props;
+ const { value, container, intl } = this.props;
const { open, placement } = this.state;
const valueOption = this.options.find(item => item.value === value);
/>
</div>
- <Overlay show={open} placement={placement} target={this}>
+ <Overlay show={open} placement={placement} target={this} container={container}>
<PrivacyDropdownMenu
items={this.options}
value={value}
import { isUserTouching } from '../../../is_mobile';
const mapStateToProps = state => ({
- isModalOpen: state.get('modal').modalType === 'ACTIONS',
value: state.getIn(['compose', 'privacy']),
});
import { connect } from 'react-redux';
import { makeGetNotification, makeGetStatus } from '../../../selectors';
import Notification from '../components/notification';
+import { initBoostModal } from '../../../actions/boosts';
import { openModal } from '../../../actions/modal';
import { mentionCompose } from '../../../actions/compose';
import {
dispatch(mentionCompose(account, router));
},
- onModalReblog (status) {
- dispatch(reblog(status));
+ onModalReblog (status, privacy) {
+ dispatch(reblog(status, privacy));
},
onReblog (status, e) {
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
- dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
+ dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
}
}
},
import { replyCompose } from 'mastodon/actions/compose';
import { reblog, favourite, unreblog, unfavourite } from 'mastodon/actions/interactions';
import { makeGetStatus } from 'mastodon/selectors';
+import { initBoostModal } from 'mastodon/actions/boosts';
import { openModal } from 'mastodon/actions/modal';
const messages = defineMessages({
}
};
- _performReblog = () => {
- const { dispatch, status } = this.props;
- dispatch(reblog(status));
+ _performReblog = (status, privacy) => {
+ const { dispatch } = this.props;
+ dispatch(reblog(status, privacy));
}
handleReblogClick = e => {
if (status.get('reblogged')) {
dispatch(unreblog(status));
} else if ((e && e.shiftKey) || !boostModal) {
- this._performReblog();
+ this._performReblog(status);
} else {
- dispatch(openModal('BOOST', { status, onReblog: this._performReblog }));
+ dispatch(initBoostModal({ status, onReblog: this._performReblog }));
}
};
} from '../../../actions/statuses';
import { initMuteModal } from '../../../actions/mutes';
import { initBlockModal } from '../../../actions/blocks';
+import { initBoostModal } from '../../../actions/boosts';
import { initReport } from '../../../actions/reports';
import { openModal } from '../../../actions/modal';
import { defineMessages, injectIntl } from 'react-intl';
});
},
- onModalReblog (status) {
- dispatch(reblog(status));
+ onModalReblog (status, privacy) {
+ dispatch(reblog(status, privacy));
},
onReblog (status, e) {
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
- dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
+ dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
}
}
},
} from '../../actions/domain_blocks';
import { initMuteModal } from '../../actions/mutes';
import { initBlockModal } from '../../actions/blocks';
+import { initBoostModal } from '../../actions/boosts';
import { initReport } from '../../actions/reports';
import { makeGetStatus, makeGetPictureInPicture } from '../../selectors';
import { ScrollContainer } from 'react-router-scroll-4';
}
}
- handleModalReblog = (status) => {
- this.props.dispatch(reblog(status));
+ handleModalReblog = (status, privacy) => {
+ this.props.dispatch(reblog(status, privacy));
}
handleReblogClick = (status, e) => {
if ((e && e.shiftKey) || !boostModal) {
this.handleModalReblog(status);
} else {
- this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
+ this.props.dispatch(initBoostModal({ status, onReblog: this.handleModalReblog }));
}
}
}
import React from 'react';
+import { connect } from 'react-redux';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import Icon from 'mastodon/components/icon';
import AttachmentList from 'mastodon/components/attachment_list';
+import PrivacyDropdown from 'mastodon/features/compose/components/privacy_dropdown';
import classNames from 'classnames';
+import { changeBoostPrivacy } from 'mastodon/actions/boosts';
const messages = defineMessages({
cancel_reblog: { id: 'status.cancel_reblog_private', defaultMessage: 'Unboost' },
direct_short: { id: 'privacy.direct.short', defaultMessage: 'Direct' },
});
-export default @injectIntl
+const mapStateToProps = state => {
+ return {
+ privacy: state.getIn(['boosts', 'new', 'privacy']),
+ };
+};
+
+const mapDispatchToProps = dispatch => {
+ return {
+ onChangeBoostPrivacy(value) {
+ dispatch(changeBoostPrivacy(value));
+ },
+ };
+};
+
+export default @connect(mapStateToProps, mapDispatchToProps)
+@injectIntl
class BoostModal extends ImmutablePureComponent {
static contextTypes = {
status: ImmutablePropTypes.map.isRequired,
onReblog: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
+ onChangeBoostPrivacy: PropTypes.func.isRequired,
+ privacy: PropTypes.string.isRequired,
intl: PropTypes.object.isRequired,
};
}
handleReblog = () => {
- this.props.onReblog(this.props.status);
+ this.props.onReblog(this.props.status, this.props.privacy);
this.props.onClose();
}
}
}
+ _findContainer = () => {
+ return document.getElementsByClassName('modal-root__container')[0];
+ };
+
setRef = (c) => {
this.button = c;
}
render () {
- const { status, intl } = this.props;
+ const { status, privacy, intl } = this.props;
const buttonText = status.get('reblogged') ? messages.cancel_reblog : messages.reblog;
const visibilityIconInfo = {
<div className='boost-modal__action-bar'>
<div><FormattedMessage id='boost_modal.combo' defaultMessage='You can press {combo} to skip this next time' values={{ combo: <span>Shift + <Icon id='retweet' /></span> }} /></div>
+ {status.get('visibility') !== 'private' && !status.get('reblogged') && (
+ <PrivacyDropdown
+ noDirect
+ value={privacy}
+ container={this._findContainer}
+ onChange={this.props.onChangeBoostPrivacy}
+ />
+ )}
<Button text={intl.formatMessage(buttonText)} onClick={this.handleReblog} ref={this.setRef} />
</div>
</div>
--- /dev/null
+import Immutable from 'immutable';
+
+import {
+ BOOSTS_INIT_MODAL,
+ BOOSTS_CHANGE_PRIVACY,
+} from 'mastodon/actions/boosts';
+
+const initialState = Immutable.Map({
+ new: Immutable.Map({
+ privacy: 'public',
+ }),
+});
+
+export default function mutes(state = initialState, action) {
+ switch (action.type) {
+ case BOOSTS_INIT_MODAL:
+ return state.withMutations((state) => {
+ state.setIn(['new', 'privacy'], action.privacy);
+ });
+ case BOOSTS_CHANGE_PRIVACY:
+ return state.setIn(['new', 'privacy'], action.privacy);
+ default:
+ return state;
+ }
+}
import status_lists from './status_lists';
import mutes from './mutes';
import blocks from './blocks';
+import boosts from './boosts';
import reports from './reports';
import contexts from './contexts';
import compose from './compose';
push_notifications,
mutes,
blocks,
+ boosts,
reports,
contexts,
compose,
border-radius: 4px;
margin-left: 40px;
overflow: hidden;
+ z-index: 2;
&.top {
transform-origin: 50% 100%;
}
}
+.modal-root__container .privacy-dropdown {
+ flex-grow: 0;
+}
+
+.modal-root__container .privacy-dropdown__dropdown {
+ pointer-events: auto;
+ z-index: 9999;
+}
+
.privacy-dropdown__option {
color: $inverted-text-color;
padding: 10px;