2018-02-11 19:35:25 +01:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { cacheFirstUpdateAfter } from '../_utils/sync'
|
2018-08-30 04:03:12 +02:00
|
|
|
import { database } from '../_database/database'
|
2018-04-17 05:56:21 +02:00
|
|
|
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) {
|
2018-04-19 18:37:05 +02:00
|
|
|
let { currentInstance, accessToken } = store.get()
|
2018-02-11 19:35:25 +01:00
|
|
|
|
|
|
|
await cacheFirstUpdateAfter(
|
2018-04-19 18:37:05 +02:00
|
|
|
() => getPinnedStatuses(currentInstance, accessToken, accountId),
|
2018-08-30 04:03:12 +02:00
|
|
|
() => database.getPinnedStatuses(currentInstance, accountId),
|
|
|
|
statuses => database.insertPinnedStatuses(currentInstance, accountId, statuses),
|
2018-02-11 19:35:25 +01:00
|
|
|
statuses => {
|
2018-04-19 18:37:05 +02:00
|
|
|
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
|
|
|
}
|