2020-07-15 15:50:08 +02:00
|
|
|
// @flow
|
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2020-10-05 20:31:51 +02:00
|
|
|
import { selectPrefsReady } from 'redux/selectors/sync';
|
|
|
|
import { doAlertWaitingForSync } from 'redux/actions/app';
|
2021-06-11 22:49:18 +02:00
|
|
|
import { doToast } from 'redux/actions/notifications';
|
2020-07-15 15:50:08 +02:00
|
|
|
|
2021-06-11 22:49:18 +02:00
|
|
|
export function doToggleMuteChannel(uri: string, showLink: boolean, unmute: boolean = false) {
|
|
|
|
return async (dispatch: Dispatch, getState: GetState) => {
|
|
|
|
const state = getState();
|
|
|
|
const ready = selectPrefsReady(state);
|
2020-10-05 20:31:51 +02:00
|
|
|
|
2021-06-11 22:49:18 +02:00
|
|
|
if (!ready) {
|
|
|
|
return dispatch(doAlertWaitingForSync());
|
|
|
|
}
|
2020-10-05 20:31:51 +02:00
|
|
|
|
2021-06-11 22:49:18 +02:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.TOGGLE_BLOCK_CHANNEL,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch(doToast({
|
|
|
|
message: __(!unmute ? 'Channel muted. You will not see them again.' : 'Channel unmuted!'),
|
|
|
|
linkText: __(showLink ? 'See All' : ''),
|
|
|
|
linkTarget: '/settings/block_and_mute',
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doChannelMute(uri: string, showLink: boolean = true) {
|
|
|
|
return (dispatch: Dispatch) => {
|
|
|
|
return dispatch(doToggleMuteChannel(uri, showLink));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doChannelUnmute(uri: string, showLink: boolean = true) {
|
|
|
|
return (dispatch: Dispatch) => {
|
|
|
|
return dispatch(doToggleMuteChannel(uri, showLink, true));
|
|
|
|
};
|
|
|
|
}
|