web: revamp mainly done, couple bugs left
This commit is contained in:
parent
f417732942
commit
03d7d7b0cc
12 changed files with 337 additions and 351 deletions
|
@ -3,7 +3,8 @@ let DAMUS
|
|||
const STANDARD_KINDS = [1, 42, 5, 6, 7];
|
||||
|
||||
const BOOTSTRAP_RELAYS = [
|
||||
"wss://relay.damus.io",
|
||||
"wss://nostr.rdfriedl.com",
|
||||
//"wss://relay.damus.io",
|
||||
//"wss://nostr-relay.wlvs.space",
|
||||
//"wss://nostr-pub.wellorder.net"
|
||||
]
|
||||
|
@ -57,10 +58,11 @@ async function damus_web_init_ready() {
|
|||
model.view_el = document.querySelector("#view")
|
||||
//load_cache(model)
|
||||
|
||||
switch_view('home')
|
||||
view_timeline_apply_mode(model, VM_FRIENDS);
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
update_title(model)
|
||||
})
|
||||
});
|
||||
update_timestamps();
|
||||
pool.on("open", on_pool_open);
|
||||
pool.on("event", on_pool_event);
|
||||
pool.on("notice", on_pool_notice);
|
||||
|
@ -69,8 +71,15 @@ async function damus_web_init_ready() {
|
|||
return pool
|
||||
}
|
||||
|
||||
function update_timestamps() {
|
||||
setTimeout(() => {
|
||||
update_timestamps();
|
||||
view_timeline_update_timestamps();
|
||||
}, 60 * 1000);
|
||||
}
|
||||
|
||||
function on_pool_open(relay) {
|
||||
console.info("opened relay", relay);
|
||||
log_info("opened relay", relay);
|
||||
const model = DAMUS;
|
||||
// We check the cache if we have init anything, if not we do our inital
|
||||
// otherwise we do a get since last
|
||||
|
@ -84,32 +93,30 @@ function on_pool_open(relay) {
|
|||
}
|
||||
|
||||
function on_pool_notice(relay, notice) {
|
||||
console.info("notice", relay.url, notice);
|
||||
log_info("notice", relay.url, notice);
|
||||
// DO NOTHING
|
||||
}
|
||||
|
||||
// on_pool_eose occurs when all storage from a relay has been sent to the
|
||||
// client.
|
||||
async function on_pool_eose(relay, sub_id) {
|
||||
console.info("eose", relay.url, sub_id);
|
||||
//console.info("eose", relay.url, sub_id);
|
||||
const model = DAMUS;
|
||||
const { ids, pool } = model;
|
||||
switch (sub_id) {
|
||||
case ids.home:
|
||||
//const events = model.views.home.events
|
||||
//handle_comments_loaded(ids, model, events, relay)
|
||||
const events = model_events_arr(model);
|
||||
// TODO filter out events to friends of friends
|
||||
on_eose_comments(ids, model, events, relay)
|
||||
pool.unsubscribe(ids.home, relay);
|
||||
break;
|
||||
case ids.profiles:
|
||||
//const view = get_current_view()
|
||||
//handle_profiles_loaded(ids, model, view, relay)
|
||||
pool.unsubscribe(ids.profiles, relay);
|
||||
model.pool.unsubscribe(ids.profiles, relay);
|
||||
on_eose_profiles(ids, model, relay)
|
||||
break;
|
||||
case ids.unknown:
|
||||
// TODO document why we unsub from unknowns
|
||||
pool.unsubscribe(ids.unknowns, relay);
|
||||
break;
|
||||
case ids.account:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,13 +127,15 @@ function on_pool_ok(relay) {
|
|||
function on_pool_event(relay, sub_id, ev) {
|
||||
const model = DAMUS;
|
||||
const { ids, pool } = model;
|
||||
|
||||
|
||||
// Process event and apply side effects
|
||||
if (!model.all_events[ev.id]) {
|
||||
model.all_events[ev.id] = ev;
|
||||
model_process_event(model, ev);
|
||||
// schedule_save_events(model);
|
||||
}
|
||||
|
||||
// Update subscriptions
|
||||
switch (sub_id) {
|
||||
case ids.account:
|
||||
model.done_init[relay] = true;
|
||||
|
@ -134,22 +143,44 @@ function on_pool_event(relay, sub_id, ev) {
|
|||
model_subscribe_defaults(model, relay);
|
||||
break;
|
||||
}
|
||||
|
||||
// Refresh view
|
||||
state.invalidated.push(ev.id);
|
||||
clearTimeout(state.timer);
|
||||
state.timer = setTimeout(() => {
|
||||
view_timeline_update(model, state);
|
||||
}, 1000);
|
||||
|
||||
// If it was metadata let's refresh the usernames and pics
|
||||
if (ev.kind == 0) {
|
||||
view_timeline_update_profiles(model, state, ev);
|
||||
}
|
||||
}
|
||||
|
||||
const state = {
|
||||
invalidated: [],
|
||||
timer: -1,
|
||||
};
|
||||
function on_eose_profiles(ids, model, relay) {
|
||||
const prefix = difficulty_to_prefix(model.pow);
|
||||
const fofs = Array.from(model.contacts.friend_of_friends);
|
||||
const standard_kinds = [1,42,5,6,7];
|
||||
let pow_filter = {kinds: standard_kinds, limit: 50};
|
||||
if (model.pow > 0)
|
||||
pow_filter.ids = [ prefix ];
|
||||
let explore_filters = [ pow_filter ];
|
||||
if (fofs.length > 0)
|
||||
explore_filters.push({kinds: standard_kinds, authors: fofs, limit: 50});
|
||||
model.pool.subscribe(ids.explore, explore_filters, relay);
|
||||
}
|
||||
|
||||
function on_eose_comments(ids, model, events, relay) {
|
||||
const pubkeys = events.reduce((s, ev) => {
|
||||
s.add(ev.pubkey);
|
||||
for (const tag of ev.tags) {
|
||||
if (tag.length >= 2 && tag[0] === "p") {
|
||||
if (!model.profile_events[tag[1]])
|
||||
s.add(tag[1]);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}, new Set());
|
||||
const authors = Array.from(pubkeys)
|
||||
// load profiles and noticed chatrooms
|
||||
const profile_filter = {kinds: [0,3], authors: authors};
|
||||
let filters = [];
|
||||
if (authors.length > 0)
|
||||
filters.push(profile_filter);
|
||||
if (filters.length === 0) {
|
||||
//log_debug("No profiles filters to request...")
|
||||
return
|
||||
}
|
||||
//console.log("subscribe", profiles_id, filter, relay)
|
||||
//log_debug("subscribing to profiles on %s", relay.url)
|
||||
model.pool.subscribe(ids.profiles, filters, relay)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue