2021-07-05 03:19:04 +00:00
|
|
|
import { store } from '../_store/store.js'
|
|
|
|
import { cacheFirstUpdateAfter } from '../_utils/sync.js'
|
|
|
|
import { database } from '../_database/database.js'
|
|
|
|
import { getFollowRequests } from '../_api/followRequests.js'
|
|
|
|
import { get } from '../_utils/lodash-lite.js'
|
2018-03-15 05:14:06 +00:00
|
|
|
|
2019-09-17 05:36:24 +00:00
|
|
|
export async function updateFollowRequestCountIfLockedAccount (instanceName) {
|
|
|
|
const { verifyCredentials, loggedInInstances } = store.get()
|
2018-03-15 05:14:06 +00:00
|
|
|
|
2019-09-21 20:43:45 +00:00
|
|
|
if (!get(verifyCredentials, [instanceName, 'locked'])) {
|
2019-09-17 05:36:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const accessToken = loggedInInstances[instanceName].access_token
|
2018-03-15 05:14:06 +00:00
|
|
|
|
2019-09-17 05:36:24 +00: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-15 05:14:06 +00:00
|
|
|
}
|