2019-09-16 22:36:24 -07:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { cacheFirstUpdateAfter } from '../_utils/sync'
|
|
|
|
import { database } from '../_database/database'
|
|
|
|
import { getFollowRequests } from '../_api/followRequests'
|
2019-09-21 13:43:45 -07:00
|
|
|
import { get } from '../_utils/lodash-lite'
|
2018-03-14 22:14:06 -07:00
|
|
|
|
2019-09-16 22:36:24 -07:00
|
|
|
export async function updateFollowRequestCountIfLockedAccount (instanceName) {
|
|
|
|
const { verifyCredentials, loggedInInstances } = store.get()
|
2018-03-14 22:14:06 -07:00
|
|
|
|
2019-09-21 13:43:45 -07:00
|
|
|
if (!get(verifyCredentials, [instanceName, 'locked'])) {
|
2019-09-16 22:36:24 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const accessToken = loggedInInstances[instanceName].access_token
|
2018-03-14 22:14:06 -07:00
|
|
|
|
2019-09-16 22:36:24 -07:00
|
|
|
await cacheFirstUpdateAfter(
|
|
|
|
async () => (await getFollowRequests(instanceName, accessToken)).length,
|
|
|
|
() => database.getFollowRequestCount(instanceName),
|
|
|
|
followReqsCount => database.setFollowRequestCount(instanceName, followReqsCount),
|
|
|
|
followReqsCount => {
|
|
|
|
const { followRequestCounts } = store.get()
|
|
|
|
followRequestCounts[instanceName] = followReqsCount
|
|
|
|
store.set({ followRequestCounts })
|
|
|
|
}
|
|
|
|
)
|
2018-03-14 22:14:06 -07:00
|
|
|
}
|