diff --git a/src/routes/_actions/pinnedStatuses.js b/src/routes/_actions/pinnedStatuses.js index 2022faa..0292385 100644 --- a/src/routes/_actions/pinnedStatuses.js +++ b/src/routes/_actions/pinnedStatuses.js @@ -10,7 +10,13 @@ export async function updatePinnedStatusesForAccount (accountId) { await cacheFirstUpdateAfter( () => getPinnedStatuses(currentInstance, accessToken, accountId), - () => database.getPinnedStatuses(currentInstance, accountId), + async () => { + let pinnedStatuses = await database.getPinnedStatuses(currentInstance, accountId) + if (!pinnedStatuses || !pinnedStatuses.every(Boolean)) { + throw new Error('missing pinned statuses in idb') + } + return pinnedStatuses + }, statuses => database.insertPinnedStatuses(currentInstance, accountId, statuses), statuses => { let { pinnedStatuses } = store.get() diff --git a/src/routes/_database/timelines/fetchStatus.js b/src/routes/_database/timelines/fetchStatus.js index 8e6b760..e5bf027 100644 --- a/src/routes/_database/timelines/fetchStatus.js +++ b/src/routes/_database/timelines/fetchStatus.js @@ -5,6 +5,9 @@ export function fetchStatus (statusesStore, accountsStore, id, callback) { statusesStore.get(id).onsuccess = e => { let status = e.target.result callback(status) + if (!status) { + return + } fetchAccount(accountsStore, status[ACCOUNT_ID], account => { status.account = account }) diff --git a/src/routes/_utils/sync.js b/src/routes/_utils/sync.js index 51344c3..8cc3b19 100644 --- a/src/routes/_utils/sync.js +++ b/src/routes/_utils/sync.js @@ -5,8 +5,12 @@ export async function cacheFirstUpdateAfter (networkFetcher, dbFetcher, dbUpdate let dbResponse try { dbResponse = await dbFetcher() - stateSetter(dbResponse) + } catch (err) { + console.error('ignored DB error', err) } finally { + if (dbResponse) { + stateSetter(dbResponse) + } let fetchAndUpdatePromise = networkPromise.then(networkResponse => { /* no await */ dbUpdater(networkResponse) stateSetter(networkResponse) @@ -16,18 +20,3 @@ export async function cacheFirstUpdateAfter (networkFetcher, dbFetcher, dbUpdate } } } - -// Make a change that we optimistically show to the user as successful, but which -// actually depends on a network operation. In the unlikely event that the network -// operation fails, revert the changes -export async function optimisticUpdate (doImmediately, networkUpdater, onSuccess, onFailure) { - let networkPromise = networkUpdater() - doImmediately() - try { - let response = await networkPromise - onSuccess(response) - } catch (e) { - console.error(e) - onFailure(e) - } -}