Support blocking notifications from strangers

merge-requests/519/head
Alex Gleason 2021-06-06 22:43:18 -05:00
rodzic f62afb6ccb
commit 421069bfd1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 50 dodań i 11 usunięć

Wyświetl plik

@ -84,6 +84,10 @@ export const FOLLOW_REQUEST_REJECT_REQUEST = 'FOLLOW_REQUEST_REJECT_REQUEST';
export const FOLLOW_REQUEST_REJECT_SUCCESS = 'FOLLOW_REQUEST_REJECT_SUCCESS';
export const FOLLOW_REQUEST_REJECT_FAIL = 'FOLLOW_REQUEST_REJECT_FAIL';
export const NOTIFICATION_SETTINGS_REQUEST = 'NOTIFICATION_SETTINGS_REQUEST';
export const NOTIFICATION_SETTINGS_SUCCESS = 'NOTIFICATION_SETTINGS_SUCCESS';
export const NOTIFICATION_SETTINGS_FAIL = 'NOTIFICATION_SETTINGS_FAIL';
function getFromDB(dispatch, getState, index, id) {
return new Promise((resolve, reject) => {
const request = index.get(id);
@ -806,6 +810,17 @@ export function unpinAccount(id) {
};
};
export function updateNotificationSettings(params) {
return (dispatch, getState) => {
dispatch({ type: NOTIFICATION_SETTINGS_REQUEST, params });
return api(getState).put('/api/pleroma/notification_settings', params).then(({ data }) => {
dispatch({ type: NOTIFICATION_SETTINGS_SUCCESS, params, data });
}).catch(error => {
dispatch({ type: NOTIFICATION_SETTINGS_FAIL, params, error });
});
};
};
export function pinAccountRequest(id) {
return {
type: ACCOUNT_PIN_REQUEST,

Wyświetl plik

@ -20,6 +20,7 @@ import {
List as ImmutableList,
} from 'immutable';
import { patchMe } from 'soapbox/actions/me';
import { updateNotificationSettings } from 'soapbox/actions/accounts';
import { unescape } from 'lodash';
import { isVerified } from 'soapbox/utils/accounts';
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
@ -34,8 +35,10 @@ const messages = defineMessages({
const mapStateToProps = state => {
const me = state.get('me');
const soapbox = getSoapboxConfig(state);
const meta = state.getIn(['meta', 'pleroma']);
const account = state.getIn(['accounts', me]).set('pleroma', meta);
return {
account: state.getIn(['accounts', me]),
account,
maxFields: state.getIn(['instance', 'pleroma', 'metadata', 'fields_limits', 'max_fields'], 4),
verifiedCanEditName: soapbox.get('verifiedCanEditName'),
};
@ -73,10 +76,13 @@ class EditProfile extends ImmutablePureComponent {
constructor(props) {
super(props);
const initialState = props.account.withMutations(map => {
const { account } = this.props;
const strangerNotifications = account.getIn(['pleroma', 'notification_settings', 'block_from_strangers']);
const initialState = account.withMutations(map => {
map.merge(map.get('source'));
map.delete('source');
map.set('fields', normalizeFields(map.get('fields'), props.maxFields));
map.set('stranger_notifications', strangerNotifications);
unescapeParams(map, ['display_name', 'bio']);
});
this.state = initialState.toObject();
@ -127,13 +133,21 @@ class EditProfile extends ImmutablePureComponent {
handleSubmit = (event) => {
const { dispatch } = this.props;
dispatch(patchMe(this.getFormdata())).then(() => {
const credentials = dispatch(patchMe(this.getFormdata()));
const notifications = dispatch(updateNotificationSettings({
block_from_strangers: this.state.stranger_notifications || false,
}));
this.setState({ isLoading: true });
Promise.all([credentials, notifications]).then(() => {
this.setState({ isLoading: false });
dispatch(snackbar.success('Profile saved!'));
}).catch((error) => {
this.setState({ isLoading: false });
});
this.setState({ isLoading: true });
event.preventDefault();
}
@ -225,6 +239,13 @@ class EditProfile extends ImmutablePureComponent {
checked={this.state.bot}
onChange={this.handleCheckboxChange}
/>
<Checkbox
label={<FormattedMessage id='edit_profile.fields.stranger_notifications_label' defaultMessage='Block notifications from strangers' />}
hint={<FormattedMessage id='edit_profile.hints.stranger_notifications' defaultMessage='Only show notifications from people you follow' />}
name='stranger_notifications'
checked={this.state.stranger_notifications}
onChange={this.handleCheckboxChange}
/>
</FieldsGroup>
<FieldsGroup>
<div className='fields-row__column fields-group'>

Wyświetl plik

@ -5,17 +5,20 @@ import { Map as ImmutableMap, fromJS } from 'immutable';
const initialState = ImmutableMap();
const importAccount = (state, account) => {
return state.withMutations(state => {
if (account.has('pleroma')) {
const pleroPrefs = account.get('pleroma').delete('settings_store');
state.mergeIn(['pleroma'], pleroPrefs);
}
});
};
export default function meta(state = initialState, action) {
switch(action.type) {
case ME_FETCH_SUCCESS:
case ME_PATCH_SUCCESS:
const me = fromJS(action.me);
return state.withMutations(state => {
if (me.has('pleroma')) {
const pleroPrefs = me.get('pleroma').delete('settings_store');
state.mergeIn(['pleroma'], pleroPrefs);
}
});
return importAccount(state, fromJS(action.me));
default:
return state;
}