Bug fixes:
- Don't request history of explore - Added method to update contacts on relay - Replace timeline view upon history loaded for various views - Don't re-apply view if already on it - Change how much history to request on explore page if viewed it recently
This commit is contained in:
parent
587c2c3b32
commit
9fa6974914
4 changed files with 71 additions and 20 deletions
|
@ -15,12 +15,6 @@ function contacts_process_event(contacts, our_pubkey, ev) {
|
|||
}
|
||||
}
|
||||
|
||||
/* contacts_push_relay sends your contact list to the desired relay.
|
||||
*/
|
||||
function contacts_push_relay(contacts, relay) {
|
||||
log_warn("contacts_push_relay not implemented");
|
||||
}
|
||||
|
||||
/* contacts_save commits the contacts data to storage.
|
||||
*/
|
||||
async function contacts_save(contacts) {
|
||||
|
|
19
js/core.js
19
js/core.js
|
@ -75,6 +75,25 @@ async function update_profile(profile={}) {
|
|||
return ev;
|
||||
}
|
||||
|
||||
async function update_contacts() {
|
||||
const model = DAMUS;
|
||||
const contacts = Array.from(model.contacts.friends);
|
||||
const tags = contacts.map((pubkey) => {
|
||||
return ["p", pubkey]
|
||||
});
|
||||
let ev = {
|
||||
kind: KIND_CONTACT,
|
||||
created_at: new_creation_time(),
|
||||
pubkey: model.pubkey,
|
||||
content: "",
|
||||
tags: tags,
|
||||
}
|
||||
ev.id = await nostrjs.calculate_id(ev);
|
||||
ev = await sign_event(ev);
|
||||
broadcast_event(ev);
|
||||
return ev;
|
||||
}
|
||||
|
||||
async function sign_event(ev) {
|
||||
if (window.nostr && window.nostr.signEvent) {
|
||||
const signed = await window.nostr.signEvent(ev)
|
||||
|
|
23
js/main.js
23
js/main.js
|
@ -17,6 +17,7 @@ const SID_NOTIFICATIONS = "notifications";
|
|||
const SID_EXPLORE = "explore";
|
||||
const SID_PROFILES = "profiles";
|
||||
const SID_THREAD = "thread";
|
||||
const SID_FRIENDS = "friends";
|
||||
|
||||
// This is our main entry.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
|
||||
|
@ -160,13 +161,18 @@ function on_pool_open(relay) {
|
|||
limit: 5000,
|
||||
}]);
|
||||
|
||||
// Get the latest history as a prefetch
|
||||
/*// Get the latest history as a prefetch
|
||||
relay.subscribe(SID_HISTORY, [{
|
||||
kinds: STANDARD_KINDS,
|
||||
limit: 500,
|
||||
}]);
|
||||
}]);*/
|
||||
|
||||
// TODO perhaps get our following list's history too
|
||||
// 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,
|
||||
}]);
|
||||
}
|
||||
|
||||
function on_pool_notice(relay, notice) {
|
||||
|
@ -183,10 +189,15 @@ 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);
|
||||
switch (sid) {
|
||||
case SID_THREAD:
|
||||
case SID_PROFILES:
|
||||
case SID_META:
|
||||
case SID_HISTORY:
|
||||
case SID_THREAD:
|
||||
view_timeline_refresh(model);
|
||||
pool.unsubscribe(sub_id, relay);
|
||||
break
|
||||
case SID_FRIENDS:
|
||||
view_timeline_refresh(model);
|
||||
case SID_META:
|
||||
case SID_PROFILES:
|
||||
pool.unsubscribe(sub_id, relay);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -12,16 +12,35 @@ function view_timeline_apply_mode(model, mode, opts={}) {
|
|||
let xs;
|
||||
const { pubkey, thread_id } = opts;
|
||||
const el = view_get_timeline_el();
|
||||
const now = new Date().getTime();
|
||||
|
||||
// Don't do anything if we are already here
|
||||
if (el.dataset.mode == mode && (el.dataset.pubkey == opts.pubkey ||
|
||||
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) {
|
||||
subscribe_explore(100);
|
||||
// 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();
|
||||
}
|
||||
if (mode == VM_THREAD) {
|
||||
if (mode == VM_THREAD || mode == VM_USER) {
|
||||
fetch_thread_history(thread_id, model.pool);
|
||||
view_show_spinner(true);
|
||||
}
|
||||
|
||||
// Request the background info for this user
|
||||
if (pubkey)
|
||||
fetch_profile(pubkey, model.pool);
|
||||
|
||||
el.dataset.mode = mode;
|
||||
switch(mode) {
|
||||
case VM_THREAD:
|
||||
|
@ -49,6 +68,20 @@ function view_timeline_apply_mode(model, mode, opts={}) {
|
|||
find_node("#newpost").classList.toggle("hide", mode != VM_FRIENDS);
|
||||
find_node("#timeline").classList.toggle("reverse", mode == VM_THREAD);
|
||||
|
||||
view_timeline_refresh(model, mode, opts);
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
/* view_timeline_refresh is a hack for redrawing the events in order
|
||||
*/
|
||||
function view_timeline_refresh(model, mode, opts={}) {
|
||||
const el = view_get_timeline_el();
|
||||
if (!mode) {
|
||||
mode = el.dataset.mode;
|
||||
opts.thread_id = el.dataset.threadId;
|
||||
opts.pubkey = el.dataset.pubkey;
|
||||
}
|
||||
// Remove all
|
||||
// This is faster than removing one by one
|
||||
el.innerHTML = "";
|
||||
|
@ -72,12 +105,6 @@ function view_timeline_apply_mode(model, mode, opts={}) {
|
|||
view_timeline_update_timestamps();
|
||||
view_show_spinner(false);
|
||||
}
|
||||
|
||||
// Request the background info for this user
|
||||
if (pubkey)
|
||||
fetch_profile(pubkey, model.pool);
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
function view_show_spinner(show=true) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue