forked from cybrespace/pinafore
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 () {
|
export async function clearProfileAndRelationship () {
|
||||||
store.set({
|
store.set({
|
||||||
currentAccountProfile: null,
|
currentAccountProfile: null,
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
import { store } from '../_store/store'
|
import { store } from '../_store/store'
|
||||||
import { blockAccount, unblockAccount } from '../_api/block'
|
import { blockAccount, unblockAccount } from '../_api/block'
|
||||||
import { toast } from '../_utils/toast'
|
import { toast } from '../_utils/toast'
|
||||||
import { updateProfileAndRelationship } from './accounts'
|
import { updateLocalRelationship } from './accounts'
|
||||||
import { emit } from '../_utils/eventBus'
|
import { emit } from '../_utils/eventBus'
|
||||||
|
|
||||||
export async function setAccountBlocked (accountId, block, toastOnSuccess) {
|
export async function setAccountBlocked (accountId, block, toastOnSuccess) {
|
||||||
let { currentInstance, accessToken } = store.get()
|
let { currentInstance, accessToken } = store.get()
|
||||||
try {
|
try {
|
||||||
|
let relationship
|
||||||
if (block) {
|
if (block) {
|
||||||
await blockAccount(currentInstance, accessToken, accountId)
|
relationship = await blockAccount(currentInstance, accessToken, accountId)
|
||||||
} else {
|
} else {
|
||||||
await unblockAccount(currentInstance, accessToken, accountId)
|
relationship = await unblockAccount(currentInstance, accessToken, accountId)
|
||||||
}
|
}
|
||||||
await updateProfileAndRelationship(accountId)
|
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||||
if (toastOnSuccess) {
|
if (toastOnSuccess) {
|
||||||
if (block) {
|
if (block) {
|
||||||
toast.say('Blocked account')
|
toast.say('Blocked account')
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import { store } from '../_store/store'
|
import { store } from '../_store/store'
|
||||||
import { followAccount, unfollowAccount } from '../_api/follow'
|
import { followAccount, unfollowAccount } from '../_api/follow'
|
||||||
import { toast } from '../_utils/toast'
|
import { toast } from '../_utils/toast'
|
||||||
import { updateProfileAndRelationship } from './accounts'
|
import { updateLocalRelationship } from './accounts'
|
||||||
|
|
||||||
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
|
export async function setAccountFollowed (accountId, follow, toastOnSuccess) {
|
||||||
let { currentInstance, accessToken } = store.get()
|
let { currentInstance, accessToken } = store.get()
|
||||||
try {
|
try {
|
||||||
|
let relationship
|
||||||
if (follow) {
|
if (follow) {
|
||||||
await followAccount(currentInstance, accessToken, accountId)
|
relationship = await followAccount(currentInstance, accessToken, accountId)
|
||||||
} else {
|
} else {
|
||||||
await unfollowAccount(currentInstance, accessToken, accountId)
|
relationship = await unfollowAccount(currentInstance, accessToken, accountId)
|
||||||
}
|
}
|
||||||
await updateProfileAndRelationship(accountId)
|
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||||
if (toastOnSuccess) {
|
if (toastOnSuccess) {
|
||||||
if (follow) {
|
if (follow) {
|
||||||
toast.say('Followed account')
|
toast.say('Followed account')
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
import { store } from '../_store/store'
|
import { store } from '../_store/store'
|
||||||
import { muteAccount, unmuteAccount } from '../_api/mute'
|
import { muteAccount, unmuteAccount } from '../_api/mute'
|
||||||
import { toast } from '../_utils/toast'
|
import { toast } from '../_utils/toast'
|
||||||
import { updateProfileAndRelationship } from './accounts'
|
import { updateLocalRelationship } from './accounts'
|
||||||
import { emit } from '../_utils/eventBus'
|
import { emit } from '../_utils/eventBus'
|
||||||
|
|
||||||
export async function setAccountMuted (accountId, mute, toastOnSuccess) {
|
export async function setAccountMuted (accountId, mute, toastOnSuccess) {
|
||||||
let { currentInstance, accessToken } = store.get()
|
let { currentInstance, accessToken } = store.get()
|
||||||
try {
|
try {
|
||||||
|
let relationship
|
||||||
if (mute) {
|
if (mute) {
|
||||||
await muteAccount(currentInstance, accessToken, accountId)
|
relationship = await muteAccount(currentInstance, accessToken, accountId)
|
||||||
} else {
|
} else {
|
||||||
await unmuteAccount(currentInstance, accessToken, accountId)
|
relationship = await unmuteAccount(currentInstance, accessToken, accountId)
|
||||||
}
|
}
|
||||||
await updateProfileAndRelationship(accountId)
|
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||||
if (toastOnSuccess) {
|
if (toastOnSuccess) {
|
||||||
if (mute) {
|
if (mute) {
|
||||||
toast.say('Muted account')
|
toast.say('Muted account')
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { store } from '../_store/store'
|
import { store } from '../_store/store'
|
||||||
import { setShowReblogs as setShowReblogsApi } from '../_api/showReblogs'
|
import { setShowReblogs as setShowReblogsApi } from '../_api/showReblogs'
|
||||||
import { toast } from '../_utils/toast'
|
import { toast } from '../_utils/toast'
|
||||||
import { updateProfileAndRelationship } from './accounts'
|
import { updateLocalRelationship } from './accounts'
|
||||||
|
|
||||||
export async function setShowReblogs (accountId, showReblogs, toastOnSuccess) {
|
export async function setShowReblogs (accountId, showReblogs, toastOnSuccess) {
|
||||||
let { currentInstance, accessToken } = store.get()
|
let { currentInstance, accessToken } = store.get()
|
||||||
try {
|
try {
|
||||||
await setShowReblogsApi(currentInstance, accessToken, accountId, showReblogs)
|
let relationship = await setShowReblogsApi(currentInstance, accessToken, accountId, showReblogs)
|
||||||
await updateProfileAndRelationship(accountId)
|
await updateLocalRelationship(currentInstance, accountId, relationship)
|
||||||
if (toastOnSuccess) {
|
if (toastOnSuccess) {
|
||||||
if (showReblogs) {
|
if (showReblogs) {
|
||||||
toast.say('Showing boosts')
|
toast.say('Showing boosts')
|
||||||
|
|
Loading…
Reference in New Issue