2018-05-13 07:49:01 +02:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { muteConversation, unmuteConversation } from '../_api/muteConversation'
|
2018-12-23 00:37:51 +01:00
|
|
|
import { toast } from '../_components/toast/toast'
|
2018-08-30 04:03:12 +02:00
|
|
|
import { database } from '../_database/database'
|
2020-11-29 23:13:27 +01:00
|
|
|
import { formatIntl } from '../_utils/formatIntl'
|
2018-05-13 07:49:01 +02:00
|
|
|
|
|
|
|
export async function setConversationMuted (statusId, mute, toastOnSuccess) {
|
2019-08-03 22:49:37 +02:00
|
|
|
const { currentInstance, accessToken } = store.get()
|
2018-05-13 07:49:01 +02:00
|
|
|
try {
|
|
|
|
if (mute) {
|
|
|
|
await muteConversation(currentInstance, accessToken, statusId)
|
|
|
|
} else {
|
|
|
|
await unmuteConversation(currentInstance, accessToken, statusId)
|
|
|
|
}
|
2018-08-30 04:03:12 +02:00
|
|
|
await database.setStatusMuted(currentInstance, statusId, mute)
|
2018-05-13 07:49:01 +02:00
|
|
|
if (toastOnSuccess) {
|
2020-11-29 23:13:27 +01:00
|
|
|
/* no await */ toast.say(mute ? 'intl.mutedConversation' : 'intl.unmutedConversation')
|
2018-05-13 07:49:01 +02:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
2020-11-29 23:13:27 +01:00
|
|
|
/* no await */ toast.say(mute
|
|
|
|
? formatIntl('intl.unableToMuteConversation', { error: (e.message || '') })
|
|
|
|
: formatIntl('intl.unableToUnmuteConversation', { error: (e.message || '') })
|
|
|
|
)
|
2018-05-13 07:49:01 +02:00
|
|
|
}
|
|
|
|
}
|