pinafore/src/routes/_actions/mute.js

30 wiersze
979 B
JavaScript
Czysty Zwykły widok Historia

2018-04-15 05:18:48 +00:00
import { store } from '../_store/store'
import { muteAccount, unmuteAccount } from '../_api/mute'
2018-12-22 23:37:51 +00:00
import { toast } from '../_components/toast/toast'
import { updateLocalRelationship } from './accounts'
import { emit } from '../_utils/eventBus'
2018-04-15 05:18:48 +00:00
export async function setAccountMuted (accountId, mute, toastOnSuccess) {
let { currentInstance, accessToken } = store.get()
2018-04-15 05:18:48 +00:00
try {
let relationship
2018-04-15 05:18:48 +00:00
if (mute) {
relationship = await muteAccount(currentInstance, accessToken, accountId)
2018-04-15 05:18:48 +00:00
} else {
relationship = await unmuteAccount(currentInstance, accessToken, accountId)
2018-04-15 05:18:48 +00:00
}
await updateLocalRelationship(currentInstance, accountId, relationship)
2018-04-15 05:18:48 +00:00
if (toastOnSuccess) {
if (mute) {
toast.say('Muted account')
} else {
toast.say('Unmuted account')
}
}
emit('refreshAccountsList')
2018-04-15 05:18:48 +00:00
} catch (e) {
console.error(e)
toast.say(`Unable to ${mute ? 'mute' : 'unmute'} account: ` + (e.message || ''))
}
}