2018-08-26 23:16:00 +02:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { blockDomain, unblockDomain } from '../_api/blockDomain'
|
2018-12-23 00:37:51 +01:00
|
|
|
import { toast } from '../_components/toast/toast'
|
2018-08-26 23:16:00 +02:00
|
|
|
import { updateRelationship } from './accounts'
|
|
|
|
|
|
|
|
export async function setDomainBlocked (accountId, domain, block, toastOnSuccess) {
|
2019-08-03 22:49:37 +02:00
|
|
|
const { currentInstance, accessToken } = store.get()
|
2018-08-26 23:16:00 +02:00
|
|
|
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 || ''))
|
|
|
|
}
|
|
|
|
}
|