web: bunch of fixes

Following works, but saving to storage does not. I need to
implement indexddb API to save event data.
This commit is contained in:
Thomas Mathews 2022-12-18 21:26:34 -08:00
parent d02992c7e6
commit 4db7250ccc
11 changed files with 115 additions and 227 deletions

View file

@ -1,44 +1,12 @@
function contacts_friend_list(contacts) {
return Array.from(contacts.friends)
}
function contacts_friendosphere(contacts) {
let s = new Set()
let fs = []
for (const friend of contacts.friends.keys()) {
fs.push(friend)
s.add(friend)
}
for (const friend of contacts.friend_of_friends.keys()) {
if (!s.has(friend))
fs.push(friend)
}
return fs
}
function add_contact_if_friend(contacts, ev) {
if (!contact_is_friend(contacts, ev.pubkey))
return
add_friend_contact(contacts, ev)
}
// TODO track friend sphere another way by using graph nodes
function contact_is_friend(contacts, pk) {
return contacts.friends.has(pk)
}
function add_friend_contact(contacts, contact) {
contacts.friends.add(contact.pubkey)
for (const tag of contact.tags) {
if (tag.length >= 2 && tag[0] == "p") {
if (!contact_is_friend(contacts, tag[1]))
contacts.friend_of_friends.add(tag[1])
}
}
}
function load_our_contacts(contacts, our_pubkey, ev) {
function contacts_process_event(contacts, our_pubkey, ev) {
if (ev.pubkey !== our_pubkey)
return
return;
contacts.event = ev
for (const tag of ev.tags) {
if (tag.length > 1 && tag[0] === "p") {
@ -46,4 +14,15 @@ function load_our_contacts(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.
*/
function contacts_save(contacts) {
log_warn("contacts_save not implemented");
}