Merge commit '55705d8191f31c1089095956fb4124f7505b4bd7' into glitch-soc/merge-upstream

pull/2789/head
Claire 2024-07-22 21:41:31 +02:00
commit dcfcfdcb14
8 changed files with 96 additions and 139 deletions

View File

@ -1,7 +1,11 @@
import { boostModal } from 'mastodon/initial_state';
import api, { getLinks } from '../api'; import api, { getLinks } from '../api';
import { fetchRelationships } from './accounts'; import { fetchRelationships } from './accounts';
import { importFetchedAccounts, importFetchedStatus } from './importer'; import { importFetchedAccounts, importFetchedStatus } from './importer';
import { unreblog, reblog } from './interactions_typed';
import { openModal } from './modal';
export const REBLOGS_EXPAND_REQUEST = 'REBLOGS_EXPAND_REQUEST'; export const REBLOGS_EXPAND_REQUEST = 'REBLOGS_EXPAND_REQUEST';
export const REBLOGS_EXPAND_SUCCESS = 'REBLOGS_EXPAND_SUCCESS'; export const REBLOGS_EXPAND_SUCCESS = 'REBLOGS_EXPAND_SUCCESS';
@ -432,3 +436,49 @@ export function unpinFail(status, error) {
skipLoading: true, skipLoading: true,
}; };
} }
function toggleReblogWithoutConfirmation(status, privacy) {
return (dispatch) => {
if (status.get('reblogged')) {
dispatch(unreblog({ statusId: status.get('id') }));
} else {
dispatch(reblog({ statusId: status.get('id'), privacy }));
}
};
}
export function toggleReblog(statusId, skipModal = false) {
return (dispatch, getState) => {
const state = getState();
let status = state.statuses.get(statusId);
if (!status)
return;
// The reblog modal expects a pre-filled account in status
// TODO: fix this by having the reblog modal get a statusId and do the work itself
status = status.set('account', state.accounts.get(status.get('account')));
if (boostModal && !skipModal) {
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: (status, privacy) => dispatch(toggleReblogWithoutConfirmation(status, privacy)) } }));
} else {
dispatch(toggleReblogWithoutConfirmation(status));
}
};
}
export function toggleFavourite(statusId) {
return (dispatch, getState) => {
const state = getState();
const status = state.statuses.get(statusId);
if (!status)
return;
if (status.get('favourited')) {
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
};
}

View File

@ -308,6 +308,21 @@ export function revealStatus(ids) {
}; };
} }
export function toggleStatusSpoilers(statusId) {
return (dispatch, getState) => {
const status = getState().statuses.get(statusId);
if (!status)
return;
if (status.get('hidden')) {
dispatch(revealStatus(statusId));
} else {
dispatch(hideStatus(statusId));
}
};
}
export function toggleStatusCollapse(id, isCollapsed) { export function toggleStatusCollapse(id, isCollapsed) {
return { return {
type: STATUS_COLLAPSE, type: STATUS_COLLAPSE,

View File

@ -21,11 +21,9 @@ import {
initAddFilter, initAddFilter,
} from '../actions/filters'; } from '../actions/filters';
import { import {
reblog, toggleReblog,
favourite, toggleFavourite,
bookmark, bookmark,
unreblog,
unfavourite,
unbookmark, unbookmark,
pin, pin,
unpin, unpin,
@ -38,15 +36,14 @@ import {
muteStatus, muteStatus,
unmuteStatus, unmuteStatus,
deleteStatus, deleteStatus,
hideStatus, toggleStatusSpoilers,
revealStatus,
toggleStatusCollapse, toggleStatusCollapse,
editStatus, editStatus,
translateStatus, translateStatus,
undoStatusTranslation, undoStatusTranslation,
} from '../actions/statuses'; } from '../actions/statuses';
import Status from '../components/status'; import Status from '../components/status';
import { boostModal, deleteModal } from '../initial_state'; import { deleteModal } from '../initial_state';
import { makeGetStatus, makeGetPictureInPicture } from '../selectors'; import { makeGetStatus, makeGetPictureInPicture } from '../selectors';
const messages = defineMessages({ const messages = defineMessages({
@ -94,28 +91,12 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
}); });
}, },
onModalReblog (status, privacy) {
if (status.get('reblogged')) {
dispatch(unreblog({ statusId: status.get('id') }));
} else {
dispatch(reblog({ statusId: status.get('id'), visibility: privacy }));
}
},
onReblog (status, e) { onReblog (status, e) {
if ((e && e.shiftKey) || !boostModal) { dispatch(toggleReblog(status.get('id'), e.shiftKey));
this.onModalReblog(status);
} else {
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.onModalReblog } }));
}
}, },
onFavourite (status) { onFavourite (status) {
if (status.get('favourited')) { dispatch(toggleFavourite(status.get('id')));
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
}, },
onBookmark (status) { onBookmark (status) {
@ -241,11 +222,7 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
}, },
onToggleHidden (status) { onToggleHidden (status) {
if (status.get('hidden')) { dispatch(toggleStatusSpoilers(status.get('id')));
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
}, },
onToggleCollapsed (status, isCollapsed) { onToggleCollapsed (status, isCollapsed) {

View File

@ -18,7 +18,7 @@ import ReplyIcon from '@/material-icons/400-24px/reply.svg?react';
import { replyCompose } from 'mastodon/actions/compose'; import { replyCompose } from 'mastodon/actions/compose';
import { markConversationRead, deleteConversation } from 'mastodon/actions/conversations'; import { markConversationRead, deleteConversation } from 'mastodon/actions/conversations';
import { openModal } from 'mastodon/actions/modal'; import { openModal } from 'mastodon/actions/modal';
import { muteStatus, unmuteStatus, revealStatus, hideStatus } from 'mastodon/actions/statuses'; import { muteStatus, unmuteStatus, toggleStatusSpoilers } from 'mastodon/actions/statuses';
import AttachmentList from 'mastodon/components/attachment_list'; import AttachmentList from 'mastodon/components/attachment_list';
import AvatarComposite from 'mastodon/components/avatar_composite'; import AvatarComposite from 'mastodon/components/avatar_composite';
import { IconButton } from 'mastodon/components/icon_button'; import { IconButton } from 'mastodon/components/icon_button';
@ -138,11 +138,7 @@ export const Conversation = ({ conversation, scrollKey, onMoveUp, onMoveDown })
}, [dispatch, lastStatus]); }, [dispatch, lastStatus]);
const handleShowMore = useCallback(() => { const handleShowMore = useCallback(() => {
if (lastStatus.get('hidden')) { dispatch(toggleStatusSpoilers(lastStatus.get('id')));
dispatch(revealStatus(lastStatus.get('id')));
} else {
dispatch(hideStatus(lastStatus.get('id')));
}
}, [dispatch, lastStatus]); }, [dispatch, lastStatus]);
if (!lastStatus) { if (!lastStatus) {

View File

@ -2,17 +2,12 @@ import { connect } from 'react-redux';
import { mentionCompose } from '../../../actions/compose'; import { mentionCompose } from '../../../actions/compose';
import { import {
reblog, toggleFavourite,
favourite, toggleReblog,
unreblog,
unfavourite,
} from '../../../actions/interactions'; } from '../../../actions/interactions';
import { openModal } from '../../../actions/modal';
import { import {
hideStatus, toggleStatusSpoilers,
revealStatus,
} from '../../../actions/statuses'; } from '../../../actions/statuses';
import { boostModal } from '../../../initial_state';
import { makeGetNotification, makeGetStatus, makeGetReport } from '../../../selectors'; import { makeGetNotification, makeGetStatus, makeGetReport } from '../../../selectors';
import Notification from '../components/notification'; import Notification from '../components/notification';
@ -38,36 +33,16 @@ const mapDispatchToProps = dispatch => ({
dispatch(mentionCompose(account)); dispatch(mentionCompose(account));
}, },
onModalReblog (status, privacy) {
dispatch(reblog({ statusId: status.get('id'), visibility: privacy }));
},
onReblog (status, e) { onReblog (status, e) {
if (status.get('reblogged')) { dispatch(toggleReblog(status.get('id'), e.shiftKey));
dispatch(unreblog({ statusId: status.get('id') }));
} else {
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.onModalReblog } }));
}
}
}, },
onFavourite (status) { onFavourite (status) {
if (status.get('favourited')) { dispatch(toggleFavourite(status.get('id')));
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
}, },
onToggleHidden (status) { onToggleHidden (status) {
if (status.get('hidden')) { dispatch(toggleStatusSpoilers(status.get('id')));
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
}, },
}); });

View File

@ -15,11 +15,11 @@ import ReplyIcon from '@/material-icons/400-24px/reply.svg?react';
import ReplyAllIcon from '@/material-icons/400-24px/reply_all.svg?react'; import ReplyAllIcon from '@/material-icons/400-24px/reply_all.svg?react';
import StarIcon from '@/material-icons/400-24px/star.svg?react'; import StarIcon from '@/material-icons/400-24px/star.svg?react';
import { replyCompose } from 'mastodon/actions/compose'; import { replyCompose } from 'mastodon/actions/compose';
import { reblog, favourite, unreblog, unfavourite } from 'mastodon/actions/interactions'; import { toggleReblog, toggleFavourite } from 'mastodon/actions/interactions';
import { openModal } from 'mastodon/actions/modal'; import { openModal } from 'mastodon/actions/modal';
import { IconButton } from 'mastodon/components/icon_button'; import { IconButton } from 'mastodon/components/icon_button';
import { identityContextPropShape, withIdentity } from 'mastodon/identity_context'; import { identityContextPropShape, withIdentity } from 'mastodon/identity_context';
import { me, boostModal } from 'mastodon/initial_state'; import { me } from 'mastodon/initial_state';
import { makeGetStatus } from 'mastodon/selectors'; import { makeGetStatus } from 'mastodon/selectors';
import { WithRouterPropTypes } from 'mastodon/utils/react_router'; import { WithRouterPropTypes } from 'mastodon/utils/react_router';
@ -104,11 +104,7 @@ class Footer extends ImmutablePureComponent {
const { signedIn } = this.props.identity; const { signedIn } = this.props.identity;
if (signedIn) { if (signedIn) {
if (status.get('favourited')) { dispatch(toggleFavourite(status.get('id')));
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
} else { } else {
dispatch(openModal({ dispatch(openModal({
modalType: 'INTERACTION', modalType: 'INTERACTION',
@ -121,23 +117,12 @@ class Footer extends ImmutablePureComponent {
} }
}; };
_performReblog = (status, privacy) => {
const { dispatch } = this.props;
dispatch(reblog({ statusId: status.get('id'), visibility: privacy }));
};
handleReblogClick = e => { handleReblogClick = e => {
const { dispatch, status } = this.props; const { dispatch, status } = this.props;
const { signedIn } = this.props.identity; const { signedIn } = this.props.identity;
if (signedIn) { if (signedIn) {
if (status.get('reblogged')) { dispatch(toggleReblog(status.get('id'), e && e.shiftKey));
dispatch(unreblog({ statusId: status.get('id') }));
} else if ((e && e.shiftKey) || !boostModal) {
this._performReblog(status);
} else {
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this._performReblog } }));
}
} else { } else {
dispatch(openModal({ dispatch(openModal({
modalType: 'INTERACTION', modalType: 'INTERACTION',

View File

@ -10,10 +10,8 @@ import {
directCompose, directCompose,
} from '../../../actions/compose'; } from '../../../actions/compose';
import { import {
reblog, toggleReblog,
favourite, toggleFavourite,
unreblog,
unfavourite,
pin, pin,
unpin, unpin,
} from '../../../actions/interactions'; } from '../../../actions/interactions';
@ -24,10 +22,9 @@ import {
muteStatus, muteStatus,
unmuteStatus, unmuteStatus,
deleteStatus, deleteStatus,
hideStatus, toggleStatusSpoilers,
revealStatus,
} from '../../../actions/statuses'; } from '../../../actions/statuses';
import { boostModal, deleteModal } from '../../../initial_state'; import { deleteModal } from '../../../initial_state';
import { makeGetStatus, makeGetPictureInPicture } from '../../../selectors'; import { makeGetStatus, makeGetPictureInPicture } from '../../../selectors';
import DetailedStatus from '../components/detailed_status'; import DetailedStatus from '../components/detailed_status';
@ -73,28 +70,12 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}); });
}, },
onModalReblog (status, privacy) {
dispatch(reblog({ statusId: status.get('id'), visibility: privacy }));
},
onReblog (status, e) { onReblog (status, e) {
if (status.get('reblogged')) { dispatch(toggleReblog(status.get('id'), e.shiftKey));
dispatch(unreblog({ statusId: status.get('id') }));
} else {
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.onModalReblog } }));
}
}
}, },
onFavourite (status) { onFavourite (status) {
if (status.get('favourited')) { dispatch(toggleFavourite(status.get('id')));
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
}, },
onPin (status) { onPin (status) {
@ -174,11 +155,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}, },
onToggleHidden (status) { onToggleHidden (status) {
if (status.get('hidden')) { dispatch(toggleStatusSpoilers(status.get('id')));
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
}, },
}); });

View File

@ -38,12 +38,10 @@ import {
unblockDomain, unblockDomain,
} from '../../actions/domain_blocks'; } from '../../actions/domain_blocks';
import { import {
favourite, toggleFavourite,
unfavourite,
bookmark, bookmark,
unbookmark, unbookmark,
reblog, toggleReblog,
unreblog,
pin, pin,
unpin, unpin,
} from '../../actions/interactions'; } from '../../actions/interactions';
@ -64,7 +62,7 @@ import {
import ColumnHeader from '../../components/column_header'; import ColumnHeader from '../../components/column_header';
import { textForScreenReader, defaultMediaVisibility } from '../../components/status'; import { textForScreenReader, defaultMediaVisibility } from '../../components/status';
import StatusContainer from '../../containers/status_container'; import StatusContainer from '../../containers/status_container';
import { boostModal, deleteModal } from '../../initial_state'; import { deleteModal } from '../../initial_state';
import { makeGetStatus, makeGetPictureInPicture } from '../../selectors'; import { makeGetStatus, makeGetPictureInPicture } from '../../selectors';
import Column from '../ui/components/column'; import Column from '../ui/components/column';
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen'; import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen';
@ -244,11 +242,7 @@ class Status extends ImmutablePureComponent {
const { signedIn } = this.props.identity; const { signedIn } = this.props.identity;
if (signedIn) { if (signedIn) {
if (status.get('favourited')) { dispatch(toggleFavourite(status.get('id')));
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
} else { } else {
dispatch(openModal({ dispatch(openModal({
modalType: 'INTERACTION', modalType: 'INTERACTION',
@ -298,24 +292,12 @@ class Status extends ImmutablePureComponent {
} }
}; };
handleModalReblog = (status, privacy) => {
this.props.dispatch(reblog({ statusId: status.get('id'), visibility: privacy }));
};
handleReblogClick = (status, e) => { handleReblogClick = (status, e) => {
const { dispatch } = this.props; const { dispatch } = this.props;
const { signedIn } = this.props.identity; const { signedIn } = this.props.identity;
if (signedIn) { if (signedIn) {
if (status.get('reblogged')) { dispatch(toggleReblog(status.get('id'), e && e.shiftKey));
dispatch(unreblog({ statusId: status.get('id') }));
} else {
if ((e && e.shiftKey) || !boostModal) {
this.handleModalReblog(status);
} else {
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: this.handleModalReblog } }));
}
}
} else { } else {
dispatch(openModal({ dispatch(openModal({
modalType: 'INTERACTION', modalType: 'INTERACTION',