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