pinafore/routes/_actions/block.js
Nolan Lawson 732d1fded4
Block and unblock an account (#125)
One of the many features listed in #6
2018-04-14 18:47:55 -07:00

28 lines
875 B
JavaScript

import { store } from '../_store/store'
import { blockAccount, unblockAccount } from '../_api/block'
import { toast } from '../_utils/toast'
import { updateProfileAndRelationship } from './accounts'
export async function setAccountBlocked (accountId, block, toastOnSuccess) {
let instanceName = store.get('currentInstance')
let accessToken = store.get('accessToken')
try {
if (block) {
await blockAccount(instanceName, accessToken, accountId)
} else {
await unblockAccount(instanceName, accessToken, accountId)
}
await updateProfileAndRelationship(accountId)
if (toastOnSuccess) {
if (block) {
toast.say('Blocked account')
} else {
toast.say('Unblocked account')
}
}
} catch (e) {
console.error(e)
toast.say(`Unable to ${block ? 'block' : 'unblock'} account: ` + (e.message || ''))
}
}