process: handle ContactLists if ours, respect new merge setting

This commit is contained in:
Mike Dilger 2023-01-08 08:02:01 +13:00
parent 91ffab957d
commit 367df9373e

View File

@ -4,7 +4,8 @@ use crate::db::{
use crate::error::Error;
use crate::globals::{Globals, GLOBALS};
use crate::relationship::Relationship;
use nostr_types::{Event, EventKind, Metadata, Tag, Unixtime, Url};
use nostr_types::{Event, EventKind, Metadata, PublicKeyHex, Tag, Unixtime, Url};
use std::sync::atomic::Ordering;
// This processes a new event, saving the results into the database
// and also populating the GLOBALS maps.
@ -217,11 +218,36 @@ pub async fn process_new_event(
.await?;
}
if event.kind == EventKind::ContactList {
// We only handle the user's own contact list currently
if let Some(pubkey) = GLOBALS.signer.read().await.public_key() {
if event.pubkey == pubkey {
let merge: bool = GLOBALS.pull_following_merge.load(Ordering::Relaxed);
let mut pubkeys: Vec<PublicKeyHex> = Vec::new();
// 'p' tags represent the author's contacts
for tag in &event.tags {
if let Tag::Pubkey { pubkey, .. } = tag {
pubkeys.push((*pubkey).into());
// FIXME do something with recommended_relay_url and petname
}
}
// Follow all those pubkeys, and unfollow everbody else if merge=false
// (and the date is used to ignore if the data is outdated)
GLOBALS
.people
.write()
.await
.follow_all(&pubkeys, merge, event.created_at)
.await?;
}
}
}
// FIXME: Handle EventKind::RecommendedRelay
// FIXME: Handle EventKind::ContactList
// Save in event_is_new
// Save in event_is_new (to highlight it in the feed, if feed related)
GLOBALS.event_is_new.write().await.push(event.id);
Ok(())