mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 00:38:27 +00:00
[Glitch] Refactor code for reblogging and favouriting
Port 03dea64b79 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { boostModal, favouriteModal } from 'flavours/glitch/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,61 @@ 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')));
|
||||
|
||||
const missing_description_setting = state.getIn(['local_settings', 'confirm_boost_missing_media_description']);
|
||||
const missing_description = status.get('media_attachments').some(item => !item.get('description'));
|
||||
if (missing_description_setting && missing_description && !status.get('reblogged')) {
|
||||
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: toggleReblogWithoutConfirmation, missingMediaDescription: true } }));
|
||||
} else if (boostModal && !skipModal) {
|
||||
dispatch(openModal({ modalType: 'BOOST', modalProps: { status, onReblog: toggleReblogWithoutConfirmation } }));
|
||||
} else {
|
||||
toggleReblogWithoutConfirmation(status);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleFavourite(statusId, skipModal = false) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
let status = state.statuses.get(statusId);
|
||||
|
||||
if (!status)
|
||||
return;
|
||||
|
||||
// The favourite 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 (status.get('favourited')) {
|
||||
dispatch(unfavourite(status));
|
||||
} else {
|
||||
if (favouriteModal && !skipModal) {
|
||||
dispatch(openModal({ modalType: 'FAVOURITE', modalProps: { status, onFavourite: (status) => dispatch(favourite(status)) } }));
|
||||
} else {
|
||||
dispatch(favourite(status));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user