pinafore/src/routes/_actions/followRequests.js
Nolan Lawson 16e66346d7
fix!: remove esm package, use native Node ES modules (#2064)
BREAKING CHANGE: Node v12.20+, v14.14+, or v16.0+ is required

* fix!: remove esm package, use native Node ES modules

* fix: fix some CJS imports
2021-07-04 20:19:04 -07:00

27 lines
985 B
JavaScript

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'
export async function updateFollowRequestCountIfLockedAccount (instanceName) {
const { verifyCredentials, loggedInInstances } = store.get()
if (!get(verifyCredentials, [instanceName, 'locked'])) {
return
}
const accessToken = loggedInInstances[instanceName].access_token
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 })
}
)
}