2021-07-05 04:19:04 +01:00
|
|
|
import { store } from '../_store/store.js'
|
|
|
|
import { approveFollowRequest, rejectFollowRequest } from '../_api/requests.js'
|
|
|
|
import { emit } from '../_utils/eventBus.js'
|
|
|
|
import { toast } from '../_components/toast/toast.js'
|
|
|
|
import { formatIntl } from '../_utils/formatIntl.js'
|
2018-04-28 22:19:39 +01:00
|
|
|
|
|
|
|
export async function setFollowRequestApprovedOrRejected (accountId, approved, toastOnSuccess) {
|
2019-08-03 21:49:37 +01:00
|
|
|
const {
|
2018-04-28 22:19:39 +01:00
|
|
|
currentInstance,
|
|
|
|
accessToken
|
|
|
|
} = store.get()
|
|
|
|
try {
|
|
|
|
if (approved) {
|
|
|
|
await approveFollowRequest(currentInstance, accessToken, accountId)
|
|
|
|
} else {
|
|
|
|
await rejectFollowRequest(currentInstance, accessToken, accountId)
|
|
|
|
}
|
|
|
|
if (toastOnSuccess) {
|
2020-11-29 22:13:27 +00:00
|
|
|
/* no await */ toast.say(approved ? 'intl.approvedFollowRequest' : 'intl.rejectedFollowRequest')
|
2018-04-28 22:19:39 +01:00
|
|
|
}
|
|
|
|
emit('refreshAccountsList')
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
2020-11-29 22:13:27 +00:00
|
|
|
/* no await */ toast.say(approved
|
|
|
|
? formatIntl('intl.unableToApproveFollowRequest', { error: (e.message || '') })
|
|
|
|
: formatIntl('intl.unableToRejectFollowRequest', { error: (e.message || '') })
|
|
|
|
)
|
2018-04-28 22:19:39 +01:00
|
|
|
}
|
|
|
|
}
|