Refactor code for reblogging and favouriting (#31102)
This commit is contained in:
parent
80d9bff6df
commit
03dea64b79
6 changed files with 73 additions and 112 deletions
|
@ -1,7 +1,11 @@
|
|||
import { boostModal } from 'mastodon/initial_state';
|
||||
|
||||
import api, { getLinks } from '../api';
|
||||
|
||||
import { fetchRelationships } from './accounts';
|
||||
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_SUCCESS = 'REBLOGS_EXPAND_SUCCESS';
|
||||
|
@ -432,3 +436,49 @@ export function unpinFail(status, error) {
|
|||
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: toggleReblogWithoutConfirmation } }));
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue