diff --git a/js/main.js b/js/main.js index 53fbb34..fbdb75e 100644 --- a/js/main.js +++ b/js/main.js @@ -161,18 +161,18 @@ function on_pool_open(relay) { limit: 5000, }]); - /*// Get the latest history as a prefetch - relay.subscribe(SID_HISTORY, [{ + // Subscribe to the world as it will serve our friends, notifications, and + // explore views + relay.subscribe(SID_EXPLORE, [{ kinds: STANDARD_KINDS, limit: 500, - }]);*/ - - // Grab our friends history so our default timeline looks loaded - relay.subscribe(SID_FRIENDS, [{ - kinds: STANDARD_KINDS, - authors: Array.from(model.contacts.friends), - limit: 500, }]); + + // Grab our friends history so our default timeline looks loaded + if (model.contacts.friends.size > 0) { + model_get_relay_que(model, relay).contacts_init = true; + fetch_friends_history(Array.from(model.contacts.friends), model.pool, relay); + } } function on_pool_notice(relay, notice) { @@ -188,15 +188,24 @@ async function on_pool_eose(relay, sub_id) { const index = sub_id.indexOf(":"); const sid = sub_id.slice(0, index >= 0 ? index : sub_id.length); + const identifier = sub_id.slice(index+1); switch (sid) { case SID_HISTORY: case SID_THREAD: + case SID_FRIENDS: view_timeline_refresh(model); pool.unsubscribe(sub_id, relay); break - case SID_FRIENDS: - view_timeline_refresh(model); case SID_META: + // if sid is ours and we did not init properly (must be login) then + // we will fetch our friends history now + if (model.pubkey == identifier && + !model_get_relay_que(model, relay).contacts_init) { + fetch_friends_history(Array.from(model.contacts.friends), + pool, relay); + log_debug("Got our friends after no init & fetching our friends"); + } + case SID_NOTIFICATIONS: case SID_PROFILES: pool.unsubscribe(sub_id, relay); break; @@ -255,13 +264,11 @@ function fetch_thread_history(evid, pool) { log_debug(`fetching thread ${sid}`); } -function subscribe_explore(limit) { - DAMUS.pool.subscribe(SID_EXPLORE, [{ +function fetch_friends_history(friends, pool, relay) { + pool.subscribe(SID_FRIENDS, [{ kinds: STANDARD_KINDS, - limit: limit, - }]); + authors: friends, + limit: 500, + }], relay); } -function unsubscribe_explore() { - DAMUS.pool.unsubscribe(SID_EXPLORE); -} diff --git a/js/model.js b/js/model.js index 82bb34c..da0ffe5 100644 --- a/js/model.js +++ b/js/model.js @@ -51,6 +51,7 @@ function model_get_relay_que(model, relay) { return map_get(model.relay_que, relay, { profiles: [], timestamp: 0, + contacts_init: false, }); } diff --git a/js/ui/state.js b/js/ui/state.js index e5f0d97..7ccabfc 100644 --- a/js/ui/state.js +++ b/js/ui/state.js @@ -19,27 +19,15 @@ function view_timeline_apply_mode(model, mode, opts={}) { el.dataset.threadId == thread_id)) return; - // Set the last time we were actively viewing explore to correctly fetch - // the history in the future - if (el.dataset.mode == VM_EXPLORE && mode != VM_EXPLORE) { - model.seen_explore = now; - } - - if (mode == VM_EXPLORE) { - // If the time between the last explore and now is less than a minute - // simply only fetch a few - subscribe_explore((now - model.seen_explore) / 1000 < 60 ? 100 : 500); - } else { - unsubscribe_explore(); - } + // Fetch history for certain views if (mode == VM_THREAD || mode == VM_USER) { - fetch_thread_history(thread_id, model.pool); view_show_spinner(true); + fetch_thread_history(thread_id, model.pool); } - - // Request the background info for this user - if (pubkey) + if (pubkey) { + view_show_spinner(true); fetch_profile(pubkey, model.pool); + } el.dataset.mode = mode; switch(mode) {