2018-01-28 20:51:48 +00:00
|
|
|
import { getAccount, getRelationship } from '../../_utils/mastodon/user'
|
2018-01-28 04:23:52 +00:00
|
|
|
import { database } from '../../_utils/database/database'
|
2018-01-28 21:09:39 +00:00
|
|
|
import { store } from '../../_store/store'
|
2018-01-28 04:23:52 +00:00
|
|
|
|
2018-01-28 20:51:48 +00:00
|
|
|
async function updateAccount(accountId, instanceName, accessToken) {
|
2018-01-28 04:23:52 +00:00
|
|
|
let localPromise = database.getAccount(instanceName, accountId)
|
|
|
|
let remotePromise = getAccount(instanceName, accessToken, accountId).then(account => {
|
|
|
|
database.setAccount(instanceName, account)
|
|
|
|
return account
|
|
|
|
})
|
|
|
|
|
|
|
|
try {
|
2018-01-28 20:51:48 +00:00
|
|
|
store.set({currentAccountProfile: (await localPromise)})
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
store.set({currentAccountProfile: (await remotePromise)})
|
2018-01-28 04:23:52 +00:00
|
|
|
} catch (e) {
|
2018-01-28 20:51:48 +00:00
|
|
|
console.error(e)
|
2018-01-28 04:23:52 +00:00
|
|
|
}
|
2018-01-28 20:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function updateRelationship(accountId, instanceName, accessToken) {
|
|
|
|
let localPromise = database.getRelationship(instanceName, accountId)
|
|
|
|
let remotePromise = getRelationship(instanceName, accessToken, accountId).then(relationship => {
|
|
|
|
database.setRelationship(instanceName, relationship)
|
|
|
|
return relationship
|
|
|
|
})
|
|
|
|
try {
|
|
|
|
store.set({currentAccountRelationship: (await localPromise)})
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
store.set({currentAccountRelationship: (await remotePromise)})
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function updateProfileAndRelationship(accountId) {
|
|
|
|
store.set({
|
|
|
|
currentAccountProfile: null,
|
|
|
|
currentAccountRelationship: null
|
|
|
|
})
|
|
|
|
let instanceName = store.get('currentInstance')
|
|
|
|
let accessToken = store.get('accessToken')
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
updateAccount(accountId, instanceName, accessToken),
|
|
|
|
updateRelationship(accountId, instanceName, accessToken)
|
|
|
|
])
|
2018-01-28 04:23:52 +00:00
|
|
|
}
|