simplify model for updating account relationships (#494)
This commit is contained in:
parent
8959cdaeb1
commit
17b80e5a79
|
@ -46,6 +46,15 @@ async function updateRelationship (accountId, instanceName, accessToken) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function updateLocalRelationship (instanceName, accountId, relationship) {
|
||||
await setRelationshipInDatabase(instanceName, relationship)
|
||||
try {
|
||||
store.set({currentAccountRelationship: relationship})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearProfileAndRelationship () {
|
||||
store.set({
|
||||
currentAccountProfile: null,
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
import { store } from '../_store/store'
|
||||
import { blockAccount, unblockAccount } from '../_api/block'
|
||||
import { toast } from '../_utils/toast'
|
||||
import { updateProfileAndRelationship } from './accounts'
|
||||
import { updateLocalRelationship } from './accounts'
|
||||
import { emit } from '../_utils/eventBus'
|
||||
|
||||
export async function setAccountBlocked (accountId, block, toastOnSuccess) {
|
||||
let { currentInstance, accessToken } = store.get()
|
||||
try {
|
||||
let relationship
|
||||
if (block) {
|
||||
await blockAccount(currentInstance, accessToken, accountId)
|
||||
relationship = await blockAccount(currentInstance, accessToken, accountId)
|
||||
} else {
|
||||
await unblockAccount(currentInstance, accessToken, accountId)
|
||||
relationship = await unblockAccount(currentInstance, accessToken, accountId)
|
||||
}
|
||||
await updateProfileAndRelationship(accountId)
|
||||
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||
if (toastOnSuccess) {
|
||||
if (block) {
|
||||
toast.say('Blocked account')
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
import { store } from '../_store/store'
|
||||
import { followAccount, unfollowAccount } from '../_api/follow'
|
||||
import { toast } from '../_utils/toast'
|
||||
import { updateProfileAndRelationship } from './accounts'
|
||||
import { updateLocalRelationship } from './accounts'
|
||||
|
||||
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
|
||||
let { currentInstance, accessToken } = store.get()
|
||||
try {
|
||||
let relationship
|
||||
if (follow) {
|
||||
await followAccount(currentInstance, accessToken, accountId)
|
||||
relationship = await followAccount(currentInstance, accessToken, accountId)
|
||||
} else {
|
||||
await unfollowAccount(currentInstance, accessToken, accountId)
|
||||
relationship = await unfollowAccount(currentInstance, accessToken, accountId)
|
||||
}
|
||||
await updateProfileAndRelationship(accountId)
|
||||
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||
if (toastOnSuccess) {
|
||||
if (follow) {
|
||||
toast.say('Followed account')
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
import { store } from '../_store/store'
|
||||
import { muteAccount, unmuteAccount } from '../_api/mute'
|
||||
import { toast } from '../_utils/toast'
|
||||
import { updateProfileAndRelationship } from './accounts'
|
||||
import { updateLocalRelationship } from './accounts'
|
||||
import { emit } from '../_utils/eventBus'
|
||||
|
||||
export async function setAccountMuted (accountId, mute, toastOnSuccess) {
|
||||
let { currentInstance, accessToken } = store.get()
|
||||
try {
|
||||
let relationship
|
||||
if (mute) {
|
||||
await muteAccount(currentInstance, accessToken, accountId)
|
||||
relationship = await muteAccount(currentInstance, accessToken, accountId)
|
||||
} else {
|
||||
await unmuteAccount(currentInstance, accessToken, accountId)
|
||||
relationship = await unmuteAccount(currentInstance, accessToken, accountId)
|
||||
}
|
||||
await updateProfileAndRelationship(accountId)
|
||||
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||
if (toastOnSuccess) {
|
||||
if (mute) {
|
||||
toast.say('Muted account')
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { store } from '../_store/store'
|
||||
import { setShowReblogs as setShowReblogsApi } from '../_api/showReblogs'
|
||||
import { toast } from '../_utils/toast'
|
||||
import { updateProfileAndRelationship } from './accounts'
|
||||
import { updateLocalRelationship } from './accounts'
|
||||
|
||||
export async function setShowReblogs (accountId, showReblogs, toastOnSuccess) {
|
||||
let { currentInstance, accessToken } = store.get()
|
||||
try {
|
||||
await setShowReblogsApi(currentInstance, accessToken, accountId, showReblogs)
|
||||
await updateProfileAndRelationship(accountId)
|
||||
let relationship = await setShowReblogsApi(currentInstance, accessToken, accountId, showReblogs)
|
||||
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||
if (toastOnSuccess) {
|
||||
if (showReblogs) {
|
||||
toast.say('Showing boosts')
|
||||
|
|
Loading…
Reference in a new issue