From 3edf243bbecc4cc64e57dd6ced8e115c0936b430 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 30 Jun 2021 03:02:52 -0500 Subject: [PATCH] Admin: optimistic user deletions --- app/soapbox/actions/moderation.js | 2 ++ app/soapbox/reducers/accounts.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/soapbox/actions/moderation.js b/app/soapbox/actions/moderation.js index cc05bd905..cce860de8 100644 --- a/app/soapbox/actions/moderation.js +++ b/app/soapbox/actions/moderation.js @@ -2,6 +2,7 @@ import React from 'react'; import { defineMessages } from 'react-intl'; import { openModal } from 'soapbox/actions/modal'; import { deactivateUsers, deleteUsers, deleteStatus, toggleStatusSensitivity } from 'soapbox/actions/admin'; +import { fetchAccountByUsername } from 'soapbox/actions/accounts'; import snackbar from 'soapbox/actions/snackbar'; import AccountContainer from 'soapbox/containers/account_container'; import { isLocal } from 'soapbox/utils/accounts'; @@ -75,6 +76,7 @@ export function deleteUserModal(intl, accountId, afterConfirm = () => {}) { onConfirm: () => { dispatch(deleteUsers([acct])).then(() => { const message = intl.formatMessage(messages.userDeleted, { acct }); + dispatch(fetchAccountByUsername(acct)); dispatch(snackbar.success(message)); afterConfirm(); }).catch(() => {}); diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index 889ed0d38..dfaff67d5 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -18,6 +18,7 @@ import { ADMIN_USERS_UNTAG_REQUEST, ADMIN_USERS_UNTAG_FAIL, } from 'soapbox/actions/admin'; +import { ADMIN_USERS_DELETE_REQUEST } from 'soapbox/actions/admin'; const initialState = ImmutableMap(); @@ -74,6 +75,21 @@ const removeTags = (state, accountIds, tags) => { }); }; +const nicknamesToIds = (state, nicknames) => { + return nicknames.map(nickname => { + return state.find(account => account.get('acct') === nickname, null, ImmutableMap()).get('id'); + }); +}; + +const setDeactivated = (state, nicknames) => { + const ids = nicknamesToIds(state, nicknames); + return state.withMutations(state => { + ids.forEach(id => { + state.setIn([id, 'pleroma', 'is_active'], false); + }); + }); +}; + export default function accounts(state = initialState, action) { switch(action.type) { case ACCOUNT_IMPORT: @@ -95,6 +111,8 @@ export default function accounts(state = initialState, action) { case ADMIN_USERS_UNTAG_REQUEST: case ADMIN_USERS_TAG_FAIL: return removeTags(state, action.accountIds, action.tags); + case ADMIN_USERS_DELETE_REQUEST: + return setDeactivated(state, action.nicknames); default: return state; }