diff --git a/routes/_actions/accounts.js b/routes/_actions/accounts.js index 6d3410f..5fdcd7e 100644 --- a/routes/_actions/accounts.js +++ b/routes/_actions/accounts.js @@ -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, diff --git a/routes/_actions/block.js b/routes/_actions/block.js index b6fb30f..ccef11a 100644 --- a/routes/_actions/block.js +++ b/routes/_actions/block.js @@ -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') diff --git a/routes/_actions/follow.js b/routes/_actions/follow.js index e2f2c8b..0bdd3ca 100644 --- a/routes/_actions/follow.js +++ b/routes/_actions/follow.js @@ -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') diff --git a/routes/_actions/mute.js b/routes/_actions/mute.js index 7b28541..e28ffed 100644 --- a/routes/_actions/mute.js +++ b/routes/_actions/mute.js @@ -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') diff --git a/routes/_actions/setShowReblogs.js b/routes/_actions/setShowReblogs.js index 9ea1286..516e6ad 100644 --- a/routes/_actions/setShowReblogs.js +++ b/routes/_actions/setShowReblogs.js @@ -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')