pinafore/routes/_actions/follow.js

27 lines
853 B
JavaScript
Raw Normal View History

import { store } from '../_store/store'
import { followAccount, unfollowAccount } from '../_api/follow'
import { toast } from '../_utils/toast'
2018-03-15 06:14:06 +01:00
import { updateProfileAndRelationship } from './accounts'
2018-03-12 03:40:32 +01:00
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
let { currentInstance, accessToken } = store.get()
try {
if (follow) {
await followAccount(currentInstance, accessToken, accountId)
} else {
await unfollowAccount(currentInstance, accessToken, accountId)
}
2018-03-15 06:14:06 +01:00
await updateProfileAndRelationship(accountId)
2018-03-12 03:40:32 +01:00
if (toastOnSuccess) {
2018-03-15 06:14:06 +01:00
if (follow) {
toast.say('Followed account')
2018-03-15 06:14:06 +01:00
} else {
toast.say('Unfollowed account')
}
2018-03-12 03:40:32 +01:00
}
} catch (e) {
console.error(e)
toast.say(`Unable to ${follow ? 'follow' : 'unfollow'} account: ` + (e.message || ''))
}
}