only show one status if the thread is not cached

This commit is contained in:
Nolan Lawson 2018-03-11 10:48:16 -07:00
parent 25dfb99bb4
commit 217aca3d31
1 changed files with 13 additions and 6 deletions

View File

@ -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])
})
}
}
})
}