From 217aca3d31db59a763e67389a916ad5e9160e138 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 11 Mar 2018 10:48:16 -0700 Subject: [PATCH] only show one status if the thread is not cached --- routes/_database/timelines.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/routes/_database/timelines.js b/routes/_database/timelines.js index 83b77697..ae2a5e66 100644 --- a/routes/_database/timelines.js +++ b/routes/_database/timelines.js @@ -86,13 +86,20 @@ async function getStatusThread (instanceName, statusId) { let keyRange = createThreadKeyRange(statusId) threadsStore.getAll(keyRange).onsuccess = e => { let thread = e.target.result - let res = new Array(thread.length) - thread.forEach((otherStatusId, i) => { - fetchStatus(statusesStore, accountsStore, otherStatusId, status => { - res[i] = status + if (thread.length) { + let res = new Array(thread.length) + callback(res) + thread.forEach((otherStatusId, i) => { + fetchStatus(statusesStore, accountsStore, otherStatusId, status => { + res[i] = status + }) }) - }) - callback(res) + } else { + // thread not cached; just make a "fake" thread with only one status in it + fetchStatus(statusesStore, accountsStore, statusId, status => { + callback([status]) + }) + } } }) }