mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
When processing ContactLists, update PersonRelay infromation for p-tags with recommend_relay_url set
This commit is contained in:
parent
cee5feb6fc
commit
9db4ed32e8
@ -189,6 +189,34 @@ impl DbPersonRelay {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub async fn upsert_last_suggested_kind3(
|
||||||
|
person: PublicKeyHex,
|
||||||
|
relay: String,
|
||||||
|
last_suggested_kind3: u64,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let sql = "INSERT INTO person_relay (person, relay, last_suggested_kind3) \
|
||||||
|
VALUES (?, ?, ?) \
|
||||||
|
ON CONFLICT(person, relay) DO UPDATE SET last_suggested_kind3=?";
|
||||||
|
|
||||||
|
spawn_blocking(move || {
|
||||||
|
let maybe_db = GLOBALS.db.blocking_lock();
|
||||||
|
let db = maybe_db.as_ref().unwrap();
|
||||||
|
|
||||||
|
let mut stmt = db.prepare(sql)?;
|
||||||
|
stmt.execute((
|
||||||
|
&person.0,
|
||||||
|
&relay,
|
||||||
|
&last_suggested_kind3,
|
||||||
|
&last_suggested_kind3,
|
||||||
|
))?;
|
||||||
|
Ok::<(), Error>(())
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn upsert_last_suggested_bytag(
|
pub async fn upsert_last_suggested_bytag(
|
||||||
person: String,
|
person: String,
|
||||||
relay: String,
|
relay: String,
|
||||||
|
@ -208,11 +208,30 @@ pub async fn process_new_event(
|
|||||||
let merge: bool = GLOBALS.pull_following_merge.load(Ordering::Relaxed);
|
let merge: bool = GLOBALS.pull_following_merge.load(Ordering::Relaxed);
|
||||||
let mut pubkeys: Vec<PublicKeyHex> = Vec::new();
|
let mut pubkeys: Vec<PublicKeyHex> = Vec::new();
|
||||||
|
|
||||||
|
let now = Unixtime::now().unwrap();
|
||||||
|
|
||||||
// 'p' tags represent the author's contacts
|
// 'p' tags represent the author's contacts
|
||||||
for tag in &event.tags {
|
for tag in &event.tags {
|
||||||
if let Tag::Pubkey { pubkey, .. } = tag {
|
if let Tag::Pubkey {
|
||||||
|
pubkey,
|
||||||
|
recommended_relay_url,
|
||||||
|
petname: _,
|
||||||
|
} = tag
|
||||||
|
{
|
||||||
|
// Save the pubkey for actual following them (outside of the loop in a batch)
|
||||||
pubkeys.push(pubkey.to_owned());
|
pubkeys.push(pubkey.to_owned());
|
||||||
// FIXME do something with recommended_relay_url and petname
|
|
||||||
|
// If there is a URL, create or update person_relay last_suggested_kind3
|
||||||
|
if let Some(url) = recommended_relay_url {
|
||||||
|
DbPersonRelay::upsert_last_suggested_bytag(
|
||||||
|
pubkey.0.to_owned(),
|
||||||
|
url.inner().to_owned(),
|
||||||
|
now.0 as u64,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TBD: do something with the petname
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user