2018-02-11 18:35:25 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { cacheFirstUpdateAfter } from '../_utils/sync'
|
2018-04-17 03:56:21 +00:00
|
|
|
import {
|
|
|
|
getPinnedStatuses as getPinnedStatusesFromDatabase,
|
|
|
|
insertPinnedStatuses as insertPinnedStatusesInDatabase
|
|
|
|
} from '../_database/timelines/pinnedStatuses'
|
|
|
|
import {
|
|
|
|
getPinnedStatuses
|
|
|
|
} from '../_api/pinnedStatuses'
|
2018-02-11 18:35:25 +00:00
|
|
|
|
2018-02-11 22:11:03 +00:00
|
|
|
export async function updatePinnedStatusesForAccount (accountId) {
|
2018-02-11 18:35:25 +00:00
|
|
|
let instanceName = store.get('currentInstance')
|
|
|
|
let accessToken = store.get('accessToken')
|
|
|
|
|
|
|
|
await cacheFirstUpdateAfter(
|
|
|
|
() => getPinnedStatuses(instanceName, accessToken, accountId),
|
2018-04-17 03:56:21 +00:00
|
|
|
() => getPinnedStatusesFromDatabase(instanceName, accountId),
|
|
|
|
statuses => insertPinnedStatusesInDatabase(instanceName, accountId, statuses),
|
2018-02-11 18:35:25 +00:00
|
|
|
statuses => {
|
|
|
|
let $pinnedStatuses = store.get('pinnedStatuses')
|
|
|
|
$pinnedStatuses[instanceName] = $pinnedStatuses[instanceName] || {}
|
|
|
|
$pinnedStatuses[instanceName][accountId] = statuses
|
|
|
|
store.set({pinnedStatuses: $pinnedStatuses})
|
|
|
|
}
|
|
|
|
)
|
2018-02-11 22:11:03 +00:00
|
|
|
}
|