2018-08-26 21:16:00 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { blockDomain, unblockDomain } from '../_api/blockDomain'
|
2018-12-22 23:37:51 +00:00
|
|
|
import { toast } from '../_components/toast/toast'
|
2018-08-26 21:16:00 +00:00
|
|
|
import { updateRelationship } from './accounts'
|
2020-11-29 22:13:27 +00:00
|
|
|
import { formatIntl } from '../_utils/formatIntl'
|
2018-08-26 21:16:00 +00:00
|
|
|
|
|
|
|
export async function setDomainBlocked (accountId, domain, block, toastOnSuccess) {
|
2019-08-03 20:49:37 +00:00
|
|
|
const { currentInstance, accessToken } = store.get()
|
2018-08-26 21:16:00 +00:00
|
|
|
try {
|
|
|
|
if (block) {
|
|
|
|
await blockDomain(currentInstance, accessToken, domain)
|
|
|
|
} else {
|
|
|
|
await unblockDomain(currentInstance, accessToken, domain)
|
|
|
|
}
|
|
|
|
await updateRelationship(accountId)
|
|
|
|
if (toastOnSuccess) {
|
2020-11-29 22:13:27 +00:00
|
|
|
/* no await */ toast.say(block ? 'intl.hidDomain' : 'intl.unhidDomain')
|
2018-08-26 21:16:00 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
2020-11-29 22:13:27 +00:00
|
|
|
/* no await */ toast.say(block
|
|
|
|
? formatIntl('intl.unableToHideDomain', { error: (e.message || '') })
|
|
|
|
: formatIntl('intl.unableToUnhideDomain', { error: (e.message || '') })
|
|
|
|
)
|
2018-08-26 21:16:00 +00:00
|
|
|
}
|
|
|
|
}
|