pinafore/routes/_actions/setDomainBlocked.js
Nolan Lawson 95665f6d74
add domain blocking (#496)
* add domain blocking

fixes another thing from #6

* show "domain blocking" on profile page
2018-08-26 14:16:00 -07:00

27 lines
821 B
JavaScript

import { store } from '../_store/store'
import { blockDomain, unblockDomain } from '../_api/blockDomain'
import { toast } from '../_utils/toast'
import { updateRelationship } from './accounts'
export async function setDomainBlocked (accountId, domain, block, toastOnSuccess) {
let { currentInstance, accessToken } = store.get()
try {
if (block) {
await blockDomain(currentInstance, accessToken, domain)
} else {
await unblockDomain(currentInstance, accessToken, domain)
}
await updateRelationship(accountId)
if (toastOnSuccess) {
if (block) {
toast.say(`Hiding ${domain}`)
} else {
toast.say(`Unhiding ${domain}`)
}
}
} catch (e) {
console.error(e)
toast.say(`Unable to ${block ? 'hide' : 'unhide'} domain: ` + (e.message || ''))
}
}