pinafore/routes/_actions/pinnedStatuses.js

23 lines
840 B
JavaScript
Raw Normal View History

2018-02-11 19:35:25 +01:00
import { store } from '../_store/store'
import { cacheFirstUpdateAfter } from '../_utils/sync'
import { database } from '../_database/database'
import {
getPinnedStatuses
} from '../_api/pinnedStatuses'
2018-02-11 19:35:25 +01:00
2018-02-11 23:11:03 +01:00
export async function updatePinnedStatusesForAccount (accountId) {
let { currentInstance, accessToken } = store.get()
2018-02-11 19:35:25 +01:00
await cacheFirstUpdateAfter(
() => getPinnedStatuses(currentInstance, accessToken, accountId),
() => database.getPinnedStatuses(currentInstance, accountId),
statuses => database.insertPinnedStatuses(currentInstance, accountId, statuses),
2018-02-11 19:35:25 +01:00
statuses => {
let { pinnedStatuses } = store.get()
pinnedStatuses[currentInstance] = pinnedStatuses[currentInstance] || {}
pinnedStatuses[currentInstance][accountId] = statuses
store.set({pinnedStatuses: pinnedStatuses})
2018-02-11 19:35:25 +01:00
}
)
2018-02-11 23:11:03 +01:00
}