pinafore/src/routes/_actions/follow.js

28 wiersze
938 B
JavaScript
Czysty Zwykły widok Historia

import { store } from '../_store/store'
import { followAccount, unfollowAccount } from '../_api/follow'
2018-12-22 23:37:51 +00:00
import { toast } from '../_components/toast/toast'
import { updateLocalRelationship } from './accounts'
2018-03-12 02:40:32 +00:00
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
2019-08-03 20:49:37 +00:00
const { currentInstance, accessToken } = store.get()
try {
let relationship
if (follow) {
relationship = await followAccount(currentInstance, accessToken, accountId)
} else {
relationship = await unfollowAccount(currentInstance, accessToken, accountId)
}
await updateLocalRelationship(currentInstance, accountId, relationship)
2018-03-12 02:40:32 +00:00
if (toastOnSuccess) {
2018-03-15 05:14:06 +00:00
if (follow) {
toast.say('Followed account')
2018-03-15 05:14:06 +00:00
} else {
toast.say('Unfollowed account')
}
2018-03-12 02:40:32 +00:00
}
} catch (e) {
console.error(e)
toast.say(`Unable to ${follow ? 'follow' : 'unfollow'} account: ` + (e.message || ''))
}
}