2021-07-05 05:19:04 +02:00
|
|
|
import { store } from '../_store/store.js'
|
|
|
|
import { muteAccount, unmuteAccount } from '../_api/mute.js'
|
|
|
|
import { toast } from '../_components/toast/toast.js'
|
|
|
|
import { updateLocalRelationship } from './accounts.js'
|
|
|
|
import { emit } from '../_utils/eventBus.js'
|
|
|
|
import { formatIntl } from '../_utils/formatIntl.js'
|
2018-04-15 07:18:48 +02:00
|
|
|
|
2019-02-19 00:43:41 +01:00
|
|
|
export async function setAccountMuted (accountId, mute, notifications, toastOnSuccess) {
|
2019-08-03 22:49:37 +02:00
|
|
|
const { currentInstance, accessToken } = store.get()
|
2018-04-15 07:18:48 +02:00
|
|
|
try {
|
2018-08-26 21:14:08 +02:00
|
|
|
let relationship
|
2018-04-15 07:18:48 +02:00
|
|
|
if (mute) {
|
2019-02-19 00:43:41 +01:00
|
|
|
relationship = await muteAccount(currentInstance, accessToken, accountId, notifications)
|
2018-04-15 07:18:48 +02:00
|
|
|
} else {
|
2018-08-26 21:14:08 +02:00
|
|
|
relationship = await unmuteAccount(currentInstance, accessToken, accountId)
|
2018-04-15 07:18:48 +02:00
|
|
|
}
|
2018-08-26 21:14:08 +02:00
|
|
|
await updateLocalRelationship(currentInstance, accountId, relationship)
|
2018-04-15 07:18:48 +02:00
|
|
|
if (toastOnSuccess) {
|
2020-11-29 23:13:27 +01:00
|
|
|
/* no await */ toast.say(mute ? 'intl.mutedAccount' : 'intl.unmutedAccount')
|
2018-04-15 07:18:48 +02:00
|
|
|
}
|
2018-04-28 23:19:39 +02:00
|
|
|
emit('refreshAccountsList')
|
2018-04-15 07:18:48 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
2020-11-29 23:13:27 +01:00
|
|
|
/* no await */ toast.say(mute
|
|
|
|
? formatIntl('intl.unableToMute', { error: (e.message || '') })
|
|
|
|
: formatIntl('intl.unableToUnmute', { error: (e.message || '') })
|
|
|
|
)
|
2018-04-15 07:18:48 +02:00
|
|
|
}
|
|
|
|
}
|