pinafore/routes/_actions/requests.js
Nolan Lawson ffb00fcc5c
approve/reject follow requests, unblock, unmute (#230)
* approve/reject follow requests, unblock, unmute

* make tests less flaky
2018-04-28 14:19:39 -07:00

30 lines
888 B
JavaScript

import { store } from '../_store/store'
import { approveFollowRequest, rejectFollowRequest } from '../_api/requests'
import { emit } from '../_utils/eventBus'
import { toast } from '../_utils/toast'
export async function setFollowRequestApprovedOrRejected (accountId, approved, toastOnSuccess) {
let {
currentInstance,
accessToken
} = store.get()
try {
if (approved) {
await approveFollowRequest(currentInstance, accessToken, accountId)
} else {
await rejectFollowRequest(currentInstance, accessToken, accountId)
}
if (toastOnSuccess) {
if (approved) {
toast.say('Approved follow request')
} else {
toast.say('Rejected follow request')
}
}
emit('refreshAccountsList')
} catch (e) {
console.error(e)
toast.say(`Unable to ${approved ? 'approve' : 'reject'} account: ` + (e.message || ''))
}
}