add ability to follow/unfollow an account
This commit is contained in:
parent
a0e6672d84
commit
92176df3ab
|
@ -0,0 +1,22 @@
|
|||
import { store } from '../_store/store'
|
||||
import { followAccount, unfollowAccount } from '../_api/follow'
|
||||
import { database } from '../_database/database'
|
||||
import { toast } from '../_utils/toast'
|
||||
|
||||
export async function setAccountFollowed (accountId, follow) {
|
||||
let instanceName = store.get('currentInstance')
|
||||
let accessToken = store.get('accessToken')
|
||||
try {
|
||||
if (follow) {
|
||||
await followAccount(instanceName, accessToken, accountId)
|
||||
} else {
|
||||
await unfollowAccount(instanceName, accessToken, accountId)
|
||||
}
|
||||
let relationship = await database.getRelationship(instanceName, accountId)
|
||||
relationship.following = follow
|
||||
await database.setRelationship(instanceName, relationship)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
toast.say(`Unable to ${follow ? 'follow' : 'unfollow'} account: ` + (e.message || ''))
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@
|
|||
pressable="true"
|
||||
pressed="{{following}}"
|
||||
big="true"
|
||||
on:click="onFollowButtonClick()"
|
||||
/>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
@ -186,6 +187,8 @@
|
|||
import ExternalLink from './ExternalLink.html'
|
||||
import Avatar from './Avatar.html'
|
||||
import { store } from '../_store/store'
|
||||
import { setAccountFollowed } from '../_actions/follow'
|
||||
import { database } from '../_database/database'
|
||||
|
||||
export default {
|
||||
computed: {
|
||||
|
@ -200,6 +203,15 @@
|
|||
},
|
||||
following: (relationship) => relationship && relationship.following
|
||||
},
|
||||
methods: {
|
||||
async onFollowButtonClick() {
|
||||
let accountId = this.get('profile').id
|
||||
let instanceName = this.store.get('currentInstance')
|
||||
let following = this.get('following')
|
||||
await setAccountFollowed(accountId, !following)
|
||||
this.set({relationship: await database.getRelationship(instanceName, accountId)})
|
||||
}
|
||||
},
|
||||
store: () => store,
|
||||
components: {
|
||||
IconButton,
|
||||
|
|
Loading…
Reference in New Issue