mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 11:43:43 +00:00
Merge branch 'metadata'
This commit is contained in:
commit
e01f706877
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2352,7 +2352,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-types"
|
name = "nostr-types"
|
||||||
version = "0.2.0-unstable"
|
version = "0.2.0-unstable"
|
||||||
source = "git+https://github.com/mikedilger/nostr-types#204d4395f7a4cf6b3f9af54f2677863326cbdf94"
|
source = "git+https://github.com/mikedilger/nostr-types#6af60c195cff89ddf322b113e0014848b6c9ad6c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"base64 0.13.1",
|
"base64 0.13.1",
|
||||||
|
@ -86,43 +86,49 @@ impl People {
|
|||||||
|
|
||||||
// Update the map
|
// Update the map
|
||||||
let person = self.people.get_mut(pubkeyhex).unwrap();
|
let person = self.people.get_mut(pubkeyhex).unwrap();
|
||||||
|
|
||||||
|
// Determine whether to update it
|
||||||
|
let mut doit = person.metadata_at.is_none();
|
||||||
if let Some(metadata_at) = person.metadata_at {
|
if let Some(metadata_at) = person.metadata_at {
|
||||||
if asof.0 > metadata_at {
|
if asof.0 > metadata_at {
|
||||||
// Process fresh metadata
|
doit = true;
|
||||||
|
|
||||||
person.name = metadata.name;
|
|
||||||
person.about = metadata.about;
|
|
||||||
person.picture = metadata.picture;
|
|
||||||
if person.dns_id != metadata.nip05 {
|
|
||||||
person.dns_id = metadata.nip05;
|
|
||||||
person.dns_id_valid = 0; // changed, so reset to invalid
|
|
||||||
person.dns_id_last_checked = None; // we haven't checked this one yet
|
|
||||||
}
|
|
||||||
person.metadata_at = Some(asof.0);
|
|
||||||
|
|
||||||
// Update the database
|
|
||||||
let person = person.clone();
|
|
||||||
let pubkeyhex2 = pubkeyhex.to_owned();
|
|
||||||
task::spawn_blocking(move || {
|
|
||||||
let maybe_db = GLOBALS.db.blocking_lock();
|
|
||||||
let db = maybe_db.as_ref().unwrap();
|
|
||||||
|
|
||||||
let mut stmt = db.prepare(
|
|
||||||
"UPDATE person SET name=?, about=?, picture=?, dns_id=?, metadata_at=? WHERE pubkey=?"
|
|
||||||
)?;
|
|
||||||
stmt.execute((
|
|
||||||
&person.name,
|
|
||||||
&person.about,
|
|
||||||
&person.picture,
|
|
||||||
&person.dns_id,
|
|
||||||
&person.metadata_at,
|
|
||||||
&pubkeyhex2.0,
|
|
||||||
))?;
|
|
||||||
Ok::<(), Error>(())
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if doit {
|
||||||
|
// Process fresh metadata
|
||||||
|
|
||||||
|
person.name = metadata.get("name");
|
||||||
|
person.about = metadata.get("about");
|
||||||
|
person.picture = metadata.get("picture");
|
||||||
|
if person.dns_id != metadata.get("nip05") {
|
||||||
|
person.dns_id = metadata.get("nip05");
|
||||||
|
person.dns_id_valid = 0; // changed, so reset to invalid
|
||||||
|
person.dns_id_last_checked = None; // we haven't checked this one yet
|
||||||
|
}
|
||||||
|
person.metadata_at = Some(asof.0);
|
||||||
|
|
||||||
|
// Update the database
|
||||||
|
let person = person.clone();
|
||||||
|
let pubkeyhex2 = pubkeyhex.to_owned();
|
||||||
|
task::spawn_blocking(move || {
|
||||||
|
let maybe_db = GLOBALS.db.blocking_lock();
|
||||||
|
let db = maybe_db.as_ref().unwrap();
|
||||||
|
|
||||||
|
let mut stmt = db.prepare(
|
||||||
|
"UPDATE person SET name=?, about=?, picture=?, dns_id=?, metadata_at=? WHERE pubkey=?"
|
||||||
|
)?;
|
||||||
|
stmt.execute((
|
||||||
|
&person.name,
|
||||||
|
&person.about,
|
||||||
|
&person.picture,
|
||||||
|
&person.dns_id,
|
||||||
|
&person.metadata_at,
|
||||||
|
&pubkeyhex2.0,
|
||||||
|
))?;
|
||||||
|
Ok::<(), Error>(())
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove from failed avatars list so the UI will try to fetch the avatar again
|
// Remove from failed avatars list so the UI will try to fetch the avatar again
|
||||||
GLOBALS.failed_avatars.write().await.remove(pubkeyhex);
|
GLOBALS.failed_avatars.write().await.remove(pubkeyhex);
|
||||||
|
Loading…
Reference in New Issue
Block a user