2021-01-18 12:59:02 -08:00
import { defineMessages } from 'react-intl' ;
import { openModal } from 'soapbox/actions/modal' ;
2021-01-18 18:59:07 -08:00
import { deactivateUsers , deleteUsers , deleteStatus , toggleStatusSensitivity } from 'soapbox/actions/admin' ;
2021-01-18 12:59:02 -08:00
import snackbar from 'soapbox/actions/snackbar' ;
const messages = defineMessages ( {
2021-01-18 16:25:36 -08:00
deactivateUserPrompt : { id : 'confirmations.admin.deactivate_user.message' , defaultMessage : 'You are about to deactivate @{acct}. Deactivating a user is a reversible action.' } ,
deactivateUserConfirm : { id : 'confirmations.admin.deactivate_user.confirm' , defaultMessage : 'Deactivate @{name}' } ,
userDeactivated : { id : 'admin.users.user_deactivated_message' , defaultMessage : '@{acct} was deactivated' } ,
deleteUserPrompt : { id : 'confirmations.admin.delete_user.message' , defaultMessage : 'You are about to delete @{acct}. THIS IS A DESTRUCTIVE ACTION THAT CANNOT BE UNDONE.' } ,
deleteUserConfirm : { id : 'confirmations.admin.delete_user.confirm' , defaultMessage : 'Delete @{name}' } ,
userDeleted : { id : 'admin.users.user_deleted_message' , defaultMessage : '@{acct} was deleted' } ,
deleteStatusPrompt : { id : 'confirmations.admin.delete_status.message' , defaultMessage : 'You are about to delete a post by @{acct}. This action cannot be undone.' } ,
2021-01-18 13:57:20 -08:00
deleteStatusConfirm : { id : 'confirmations.admin.delete_status.confirm' , defaultMessage : 'Delete post' } ,
2021-01-18 16:25:36 -08:00
statusDeleted : { id : 'admin.statuses.status_deleted_message' , defaultMessage : 'Post by @{acct} was deleted' } ,
2021-01-18 19:09:35 -08:00
markStatusSensitivePrompt : { id : 'confirmations.admin.mark_status_sensitive.message' , defaultMessage : 'You are about to mark a post by @{acct} sensitive.' } ,
markStatusNotSensitivePrompt : { id : 'confirmations.admin.mark_status_not_sensitive.message' , defaultMessage : 'You are about to mark a post by @{acct} not sensitive.' } ,
2021-01-18 18:59:07 -08:00
markStatusSensitiveConfirm : { id : 'confirmations.admin.mark_status_sensitive.confirm' , defaultMessage : 'Mark post sensitive' } ,
markStatusNotSensitiveConfirm : { id : 'confirmations.admin.mark_status_not_sensitive.confirm' , defaultMessage : 'Mark post not sensitive' } ,
2021-01-18 19:09:35 -08:00
statusMarkedSensitive : { id : 'admin.statuses.status_marked_message_sensitive' , defaultMessage : 'Post by @{acct} was marked sensitive' } ,
statusMarkedNotSensitive : { id : 'admin.statuses.status_marked_message_not_sensitive' , defaultMessage : 'Post by @{acct} was marked not sensitive' } ,
2021-01-18 12:59:02 -08:00
} ) ;
export function deactivateUserModal ( intl , accountId , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
2021-01-18 16:25:36 -08:00
const name = state . getIn ( [ 'accounts' , accountId , 'username' ] ) ;
2021-01-18 12:59:02 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2021-01-18 16:25:36 -08:00
message : intl . formatMessage ( messages . deactivateUserPrompt , { acct } ) ,
confirm : intl . formatMessage ( messages . deactivateUserConfirm , { name } ) ,
2021-01-18 12:59:02 -08:00
onConfirm : ( ) => {
dispatch ( deactivateUsers ( [ acct ] ) ) . then ( ( ) => {
2021-01-18 16:25:36 -08:00
const message = intl . formatMessage ( messages . userDeactivated , { acct } ) ;
2021-01-18 12:59:02 -08:00
dispatch ( snackbar . success ( message ) ) ;
afterConfirm ( ) ;
} ) . catch ( ( ) => { } ) ;
} ,
} ) ) ;
} ;
}
export function deleteUserModal ( intl , accountId , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
2021-01-18 16:25:36 -08:00
const name = state . getIn ( [ 'accounts' , accountId , 'username' ] ) ;
2021-01-18 12:59:02 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2021-01-18 16:25:36 -08:00
message : intl . formatMessage ( messages . deleteUserPrompt , { acct } ) ,
confirm : intl . formatMessage ( messages . deleteUserConfirm , { name } ) ,
2021-01-18 12:59:02 -08:00
onConfirm : ( ) => {
dispatch ( deleteUsers ( [ acct ] ) ) . then ( ( ) => {
2021-01-18 16:25:36 -08:00
const message = intl . formatMessage ( messages . userDeleted , { acct } ) ;
2021-01-18 12:59:02 -08:00
dispatch ( snackbar . success ( message ) ) ;
afterConfirm ( ) ;
} ) . catch ( ( ) => { } ) ;
} ,
} ) ) ;
} ;
}
2021-01-18 13:57:20 -08:00
2021-01-18 18:59:07 -08:00
export function toggleStatusSensitivityModal ( intl , statusId , sensitive , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const accountId = state . getIn ( [ 'statuses' , statusId , 'account' ] ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( sensitive === false ? messages . markStatusSensitivePrompt : messages . markStatusNotSensitivePrompt , { acct : ` @ ${ acct } ` } ) ,
confirm : intl . formatMessage ( sensitive === false ? messages . markStatusSensitiveConfirm : messages . markStatusNotSensitiveConfirm ) ,
onConfirm : ( ) => {
dispatch ( toggleStatusSensitivity ( statusId , sensitive ) ) . then ( ( ) => {
const message = intl . formatMessage ( sensitive === false ? messages . statusMarkedSensitive : messages . statusMarkedNotSensitive , { acct : ` @ ${ acct } ` } ) ;
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
afterConfirm ( ) ;
} ,
} ) ) ;
} ;
}
2021-01-18 13:57:20 -08:00
export function deleteStatusModal ( intl , statusId , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const accountId = state . getIn ( [ 'statuses' , statusId , 'account' ] ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
dispatch ( openModal ( 'CONFIRM' , {
2021-01-18 16:25:36 -08:00
message : intl . formatMessage ( messages . deleteStatusPrompt , { acct } ) ,
2021-01-18 13:57:20 -08:00
confirm : intl . formatMessage ( messages . deleteStatusConfirm ) ,
onConfirm : ( ) => {
dispatch ( deleteStatus ( statusId ) ) . then ( ( ) => {
2021-01-18 16:25:36 -08:00
const message = intl . formatMessage ( messages . statusDeleted , { acct } ) ;
2021-01-18 13:57:20 -08:00
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
afterConfirm ( ) ;
} ,
} ) ) ;
} ;
}