2018-04-15 01:47:55 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { blockAccount, unblockAccount } from '../_api/block'
|
|
|
|
import { toast } from '../_utils/toast'
|
2018-08-26 19:14:08 +00:00
|
|
|
import { updateLocalRelationship } from './accounts'
|
2018-04-28 21:19:39 +00:00
|
|
|
import { emit } from '../_utils/eventBus'
|
2018-04-15 01:47:55 +00:00
|
|
|
|
|
|
|
export async function setAccountBlocked (accountId, block, toastOnSuccess) {
|
2018-04-19 16:37:05 +00:00
|
|
|
let { currentInstance, accessToken } = store.get()
|
2018-04-15 01:47:55 +00:00
|
|
|
try {
|
2018-08-26 19:14:08 +00:00
|
|
|
let relationship
|
2018-04-15 01:47:55 +00:00
|
|
|
if (block) {
|
2018-08-26 19:14:08 +00:00
|
|
|
relationship = await blockAccount(currentInstance, accessToken, accountId)
|
2018-04-15 01:47:55 +00:00
|
|
|
} else {
|
2018-08-26 19:14:08 +00:00
|
|
|
relationship = await unblockAccount(currentInstance, accessToken, accountId)
|
2018-04-15 01:47:55 +00:00
|
|
|
}
|
2018-08-26 19:14:08 +00:00
|
|
|
await updateLocalRelationship(currentInstance, accountId, relationship)
|
2018-04-15 01:47:55 +00:00
|
|
|
if (toastOnSuccess) {
|
|
|
|
if (block) {
|
|
|
|
toast.say('Blocked account')
|
|
|
|
} else {
|
|
|
|
toast.say('Unblocked account')
|
|
|
|
}
|
|
|
|
}
|
2018-04-28 21:19:39 +00:00
|
|
|
emit('refreshAccountsList')
|
2018-04-15 01:47:55 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
toast.say(`Unable to ${block ? 'block' : 'unblock'} account: ` + (e.message || ''))
|
|
|
|
}
|
|
|
|
}
|