Skip to content

Commit

Permalink
Fix a change to limited-visibility-bearcaps replies
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo committed Aug 31, 2020
1 parent ed36140 commit b64adf1
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 59 deletions.
12 changes: 1 addition & 11 deletions app/controllers/api/v1/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,7 @@ def set_thread
end

def set_circle
@circle = begin
if status_params[:circle_id].blank?
nil
elsif status_params[:circle_id] == 'thread' && @thread.present?
Account.where(id: (@thread.ancestors(CONTEXT_LIMIT, current_account).pluck(:account_id) + [@thread.account_id]).uniq - [current_user.account_id])
elsif status_params[:circle_id] == 'reply' && @thread.present?
Account.where(id: [@thread.account_id] - [current_user.account_id])
else
current_account.owned_circles.find(status_params[:circle_id])
end
end
@circle = status_params[:circle_id].blank? ? nil : current_account.owned_circles.find(status_params[:circle_id])
rescue ActiveRecord::RecordNotFound
render json: { error: I18n.t('statuses.errors.circle_not_found') }, status: 404
end
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function submitCompose(routerHistory) {
sensitive: getState().getIn(['compose', 'sensitive']),
spoiler_text: getState().getIn(['compose', 'spoiler']) ? getState().getIn(['compose', 'spoiler_text'], '') : '',
visibility: getState().getIn(['compose', 'privacy']),
circle_id: getState().getIn(['compose', 'privacy']) === 'limited' ? getState().getIn(['compose', 'circle_id']) : null,
circle_id: getState().getIn(['compose', 'circle_id']),
poll: getState().getIn(['compose', 'poll'], null),
}, {
headers: {
Expand Down
6 changes: 4 additions & 2 deletions app/javascript/mastodon/actions/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ export function fetchStatusFail(id, error, skipLoading) {
};
};

export function redraft(status, raw_text) {
export function redraft(status, replyStatus, raw_text) {
return {
type: REDRAFT,
status,
replyStatus,
raw_text,
};
};

export function deleteStatus(id, routerHistory, withRedraft = false) {
return (dispatch, getState) => {
let status = getState().getIn(['statuses', id]);
const replyStatus = status.get('in_reply_to_id') ? getState().getIn(['statuses', status.get('in_reply_to_id')]) : null;

if (status.get('poll')) {
status = status.set('poll', getState().getIn(['polls', status.get('poll')]));
Expand All @@ -158,7 +160,7 @@ export function deleteStatus(id, routerHistory, withRedraft = false) {
dispatch(importFetchedAccount(response.data.account));

if (withRedraft) {
dispatch(redraft(status, response.data.text));
dispatch(redraft(status, replyStatus, response.data.text));
ensureComposeIsVisible(getState, routerHistory);
}
}).catch(error => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import IconButton from 'mastodon/components/icon_button';
import { createSelector } from 'reselect';

const messages = defineMessages({
circle_system: { id: 'circle.system_definition', defaultMessage: 'System definition' },
circle_user: { id: 'circle.user_definition', defaultMessage: 'User definition' },
circle_unselect: { id: 'circle.unselect', defaultMessage: '(Select circle)' },
circle_reply_to_poster: { id: 'circle.reply-to_poster', defaultMessage: 'Reply-to poster' },
circle_thread_posters: { id: 'circle.thread_posters', defaultMessage: 'Thread posters' },
circle_open_circle_column: { id: 'circle.open_circle_column', defaultMessage: 'Open circle column' },
circle_select: { id: 'circle.select', defaultMessage: 'Select circle' },
});
Expand Down Expand Up @@ -43,7 +39,6 @@ class CircleDropdown extends React.PureComponent {
circles: ImmutablePropTypes.list,
value: PropTypes.string.isRequired,
visible: PropTypes.bool.isRequired,
reply: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired,
onOpenCircleColumn: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
Expand All @@ -58,7 +53,7 @@ class CircleDropdown extends React.PureComponent {
};

render () {
const { circles, value, visible, reply, intl } = this.props;
const { circles, value, visible, intl } = this.props;

return (
<div className={classNames('circle-dropdown', { 'circle-dropdown--visible': visible })}>
Expand All @@ -67,16 +62,9 @@ class CircleDropdown extends React.PureComponent {
{/* eslint-disable-next-line jsx-a11y/no-onchange */}
<select className='circle-dropdown__menu' title={intl.formatMessage(messages.circle_select)} value={value} onChange={this.handleChange}>
<option value='' key='unselect'>{intl.formatMessage(messages.circle_unselect)}</option>
{reply &&
<optgroup label={intl.formatMessage(messages.circle_system)}>
<option value='reply' key='reply'>{intl.formatMessage(messages.circle_reply_to_poster)}</option>
<option value='thread' key='thread'>{intl.formatMessage(messages.circle_thread_posters)}</option>
</optgroup>}
<optgroup label={intl.formatMessage(messages.circle_user)}>
{circles.map(circle =>
<option value={circle.get('id')} key={circle.get('id')}>{circle.get('title')}</option>,
)}
</optgroup>
{circles.map(circle =>
<option value={circle.get('id')} key={circle.get('id')}>{circle.get('title')}</option>,
)}
</select>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PrivacyDropdownMenu extends React.PureComponent {
style: PropTypes.object,
items: PropTypes.array.isRequired,
value: PropTypes.string.isRequired,
enableValues: PropTypes.array.isRequired,
placement: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
Expand Down Expand Up @@ -121,7 +122,7 @@ class PrivacyDropdownMenu extends React.PureComponent {

render () {
const { mounted } = this.state;
const { style, items, placement, value } = this.props;
const { style, items, placement, value, enableValues } = this.props;

return (
<Motion defaultStyle={{ opacity: 0, scaleX: 0.85, scaleY: 0.75 }} style={{ opacity: spring(1, { damping: 35, stiffness: 400 }), scaleX: spring(1, { damping: 35, stiffness: 400 }), scaleY: spring(1, { damping: 35, stiffness: 400 }) }}>
Expand All @@ -131,6 +132,7 @@ class PrivacyDropdownMenu extends React.PureComponent {
// 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}>
{items.map(item => (
enableValues.includes(item.value) &&
<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'>
<Icon id={item.icon} fixedWidth />
Expand Down Expand Up @@ -159,6 +161,7 @@ class PrivacyDropdown extends React.PureComponent {
onModalOpen: PropTypes.func,
onModalClose: PropTypes.func,
value: PropTypes.string.isRequired,
limitedReply: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
Expand Down Expand Up @@ -244,10 +247,11 @@ class PrivacyDropdown extends React.PureComponent {
}

render () {
const { value, intl } = this.props;
const { value, limitedReply, intl } = this.props;
const { open, placement } = this.state;

const valueOption = this.options.find(item => item.value === value);
const enableValues = limitedReply ? ['limited', 'direct'] : ['public', 'unlisted', 'private', 'limited', 'direct'];

return (
<div className={classNames('privacy-dropdown', placement, { active: open })} onKeyDown={this.handleKeyDown}>
Expand All @@ -271,6 +275,7 @@ class PrivacyDropdown extends React.PureComponent {
<PrivacyDropdownMenu
items={this.options}
value={value}
enableValues={enableValues}
onClose={this.handleClose}
onChange={this.handleChange}
placement={placement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const mapStateToProps = state => {

return {
value: value,
visible: state.getIn(['compose', 'privacy']) === 'limited',
reply: state.getIn(['compose', 'in_reply_to']) !== null,
visible: state.getIn(['compose', 'privacy']) === 'limited' && state.getIn(['compose', 'reply_status', 'visibility']) !== 'limited',
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const mapStateToProps = state => ({
isSubmitting: state.getIn(['compose', 'is_submitting']),
isChangingUpload: state.getIn(['compose', 'is_changing_upload']),
isUploading: state.getIn(['compose', 'is_uploading']),
isCircleUnselected: state.getIn(['compose', 'privacy']) === 'limited' && !state.getIn(['compose', 'circle_id']),
isCircleUnselected: state.getIn(['compose', 'privacy']) === 'limited' && state.getIn(['compose', 'reply_status', 'visibility']) !== 'limited' && !state.getIn(['compose', 'circle_id']),
showSearch: state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']),
anyMedia: state.getIn(['compose', 'media_attachments']).size > 0,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isUserTouching } from '../../../is_mobile';
const mapStateToProps = state => ({
isModalOpen: state.get('modal').modalType === 'ACTIONS',
value: state.getIn(['compose', 'privacy']),
limitedReply: state.getIn(['compose', 'reply_status', 'visibility']) === 'limited',
});

const mapDispatchToProps = dispatch => ({
Expand Down
4 changes: 0 additions & 4 deletions app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@
"bundle_modal_error.message": "Something went wrong while loading this component.",
"bundle_modal_error.retry": "Try again",
"circle.open_circle_column": "Open circle column",
"circle.reply-to_poster": "Reply-to poster",
"circle.thread_posters": "Thread posters",
"circle.select": "Select circle",
"circle.system_definition": "System definition",
"circle.unselect": "(Select circle)",
"circle.user_definition": "User definition",
"column.blocks": "Blocked users",
"column.bookmarks": "Bookmarks",
"column.community": "Local timeline",
Expand Down
16 changes: 3 additions & 13 deletions app/javascript/mastodon/reducers/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,7 @@ export default function compose(state = initialState, action) {
map.set('text', statusToTextMentions(state.get('text'), action.value, state.get('reply_status')));
map.set('privacy', action.value);
map.set('idempotencyKey', uuid());
if(action.value === 'limited' && map.get('in_reply_to')) {
map.set('circle_id', state.getIn(['reply_status', 'in_reply_to_id']) ? 'thread' : 'reply');
} else {
map.set('circle_id', null);
}
map.set('circle_id', null);
});
case COMPOSE_CIRCLE_CHANGE:
return state
Expand All @@ -327,13 +323,7 @@ export default function compose(state = initialState, action) {
map.set('reply_status', action.status);
map.set('text', statusToTextMentions('', privacy, action.status));
map.set('privacy', privacy);
if(action.status.get('circle_id')) {
map.set('circle_id', action.status.get('circle_id'));
} else if(action.status.get('visibility') === 'limited'){
map.set('circle_id', action.status.get('in_reply_to_id') ? 'thread' : 'reply');
} else {
map.set('circle_id', null);
}
map.set('circle_id', null);
map.set('focusDate', new Date());
map.set('caretPosition', null);
map.set('preselectDate', new Date());
Expand Down Expand Up @@ -444,7 +434,7 @@ export default function compose(state = initialState, action) {
return state.withMutations(map => {
map.set('text', action.raw_text || unescapeHTML(expandMentions(action.status)));
map.set('in_reply_to', action.status.get('in_reply_to_id'));
map.set('reply_status', action.status);
map.set('reply_status', action.replyStatus);
map.set('privacy', action.status.get('visibility'));
map.set('circle_id', action.status.get('circle_id'));
map.set('media_attachments', action.status.get('media_attachments'));
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/rest/status_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def limited
end

def limited_owned_status?
object.limited_visibility? && owned_status?
object.limited_visibility? && owned_status? && object.in_reply_to_id.nil?
end

def circle_id
Expand Down
2 changes: 1 addition & 1 deletion app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def process_status!

process_hashtags_service.call(@status)
process_mentions_service.call(@status)
redis.setex(circle_id_key, 3.days.seconds, @circle.id) if @circle.present? && @circle.respond_to?(:id)
redis.setex(circle_id_key, 3.days.seconds, @circle.id) if @circle.present?
end

def schedule_status!
Expand Down
7 changes: 2 additions & 5 deletions app/services/process_mentions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ def call(status)
end

if circle.present?
accounts = circle.respond_to?(:accounts) ? circle.accounts : circle

accounts.find_each do |target_account|
mention = target_account.mentions.new(status: status, silent: true)
mentions << mention if mention.save!
circle.accounts.find_each do |target_account|
status.mentions.create(silent: true, account: target_account)
end
end

Expand Down

0 comments on commit b64adf1

Please sign in to comment.