Update Metadata

This commit is contained in:
Mike Dilger 2023-01-02 23:19:51 +13:00
parent f991e4e801
commit 8d7f062a1a
6 changed files with 75 additions and 33 deletions

View File

@ -27,6 +27,10 @@ impl Minion {
ws_sink.send(WsMessage::Text(wire)).await?;
info!("Posted event to {}", &self.url);
}
"temp_subscribe_metadata" => {
let pubkeyhex: PublicKeyHex = serde_json::from_str(&bus_message.json_payload)?;
self.temp_subscribe_metadata(pubkeyhex).await?;
}
_ => {
warn!(
"{} Unrecognized bus message kind received by minion: {}",

View File

@ -386,6 +386,18 @@ impl Minion {
Ok(())
}
async fn temp_subscribe_metadata(&mut self, pubkeyhex: PublicKeyHex) -> Result<(), Error> {
let handle = format!("temp_subscribe_metadata_{}", &pubkeyhex.0);
let filter = Filter {
authors: vec![pubkeyhex],
kinds: vec![EventKind::Metadata, EventKind::ContactList],
// FIXME: we could probably get a since-last-fetched-their-metadata here.
// but relays should just return the lastest of these.
..Default::default()
};
self.subscribe(vec![filter], &handle).await
}
#[allow(dead_code)]
async fn subscribe(&mut self, filters: Vec<Filter>, handle: &str) -> Result<(), Error> {
let req_message = if self.subscriptions.has(handle) {

View File

@ -523,6 +523,24 @@ impl Overlord {
DbRelay::insert(dbrelay).await?;
}
}
"update_metadata" => {
let pubkey: PublicKeyHex = serde_json::from_str(&bus_message.json_payload)?;
let person_relays = DbPersonRelay::fetch_for_pubkeys(&[pubkey.clone()]).await?;
for person_relay in person_relays.iter() {
// Start a minion for this relay if there is none
if !self.urls_watching.contains(&Url::new(&person_relay.relay)) {
self.start_minion(person_relay.relay.clone()).await?;
}
// Subscribe to metadata and contact lists for this person
let _ = self.to_minions.send(BusMessage {
target: person_relay.relay.to_string(),
kind: "temp_subscribe_metadata".to_string(),
json_payload: serde_json::to_string(&pubkey).unwrap(),
});
}
}
_ => {}
},
_ => {}

View File

@ -389,6 +389,16 @@ fn render_post_actual(
if ui.button("Dismiss").clicked() {
GLOBALS.dismissed.blocking_write().push(event.id);
}
if ui.button("Update Metadata").clicked() {
let _ = GLOBALS.to_overlord.send(BusMessage {
target: "overlord".to_string(),
kind: "update_metadata".to_string(),
json_payload: serde_json::to_string(
&event.pubkey.as_hex_string(),
)
.unwrap(),
});
}
});
ui.label(
@ -472,14 +482,6 @@ fn render_content(ui: &mut Ui, content: &str) {
}
fn set_person_view(app: &mut GossipUi, pubkeyhex: &PublicKeyHex) {
if let Some(dbperson) = GLOBALS.people.blocking_write().get(pubkeyhex) {
app.person_view_name = if let Some(name) = &dbperson.name {
Some(name.to_string())
} else {
Some(GossipUi::hex_pubkey_short(pubkeyhex))
};
app.person_view_person = Some(dbperson);
app.person_view_pubkey = Some(pubkeyhex.to_owned());
app.page = Page::Person;
}
}

View File

@ -86,8 +86,6 @@ struct GossipUi {
replying_to: Option<Id>,
hides: Vec<Id>,
person_view_pubkey: Option<PublicKeyHex>,
person_view_person: Option<DbPerson>,
person_view_name: Option<String>,
avatars: HashMap<PublicKeyHex, TextureHandle>,
new_relay_url: String,
}
@ -161,8 +159,6 @@ impl GossipUi {
replying_to: None,
hides: Vec::new(),
person_view_pubkey: None,
person_view_person: None,
person_view_name: None,
avatars: HashMap::new(),
new_relay_url: "".to_owned(),
}

View File

@ -6,14 +6,20 @@ use eframe::egui;
use egui::{Context, Image, RichText, ScrollArea, Sense, TextEdit, TopBottomPanel, Ui, Vec2};
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
let maybe_person = if let Some(pubkeyhex) = &app.person_view_pubkey {
GLOBALS.people.blocking_write().get(pubkeyhex)
} else {
None
};
TopBottomPanel::top("people_menu").show(ctx, |ui| {
ui.horizontal(|ui| {
ui.selectable_value(&mut app.page, Page::PeopleList, "Followed");
ui.separator();
ui.selectable_value(&mut app.page, Page::PeopleFollow, "Follow Someone New");
ui.separator();
if let Some(name) = &app.person_view_name {
ui.selectable_value(&mut app.page, Page::Person, name);
if let Some(person) = &maybe_person {
ui.selectable_value(&mut app.page, Page::Person, get_name(person));
ui.separator();
}
});
@ -162,19 +168,15 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
}
});
} else if app.page == Page::Person {
if app.person_view_pubkey.is_none()
|| app.person_view_person.is_none()
|| app.person_view_name.is_none()
{
if maybe_person.is_none() || app.person_view_pubkey.is_none() {
ui.label("ERROR");
} else {
let pubkeyhex = app.person_view_pubkey.as_ref().unwrap().to_owned();
let person = app.person_view_person.as_ref().unwrap().to_owned();
let name = app.person_view_name.as_ref().unwrap().to_owned();
let person = maybe_person.as_ref().unwrap();
let pubkeyhex = app.person_view_pubkey.as_ref().unwrap().clone();
ui.add_space(24.0);
ui.heading(name);
ui.heading(get_name(person));
ui.horizontal(|ui| {
// Avatar first
@ -187,7 +189,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.vertical(|ui| {
ui.label(RichText::new(GossipUi::hex_pubkey_short(&pubkeyhex)).weak());
GossipUi::render_person_name_line(ui, Some(&person));
GossipUi::render_person_name_line(ui, Some(person));
});
});
@ -203,25 +205,33 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
if person.followed == 0 {
if ui.button("FOLLOW").clicked() {
GLOBALS.people.blocking_write().follow(&pubkeyhex, true);
app.person_view_person.as_mut().unwrap().followed = 1;
}
} else {
if ui.button("UNFOLLOW").clicked() {
GLOBALS.people.blocking_write().follow(&pubkeyhex, false);
app.person_view_person.as_mut().unwrap().followed = 0;
}
}
if ui.button("UPDATE METADATA").clicked() {
let _ = GLOBALS.to_overlord.send(BusMessage {
target: "overlord".to_string(),
kind: "update_metadata".to_string(),
json_payload: serde_json::to_string(&pubkeyhex).unwrap(),
});
}
}
}
}
fn get_name(person: &DbPerson) -> String {
if let Some(name) = &person.name {
name.to_owned()
} else {
GossipUi::hex_pubkey_short(&person.pubkey)
}
}
fn set_person_view(app: &mut GossipUi, person: &DbPerson) {
app.person_view_pubkey = Some(person.pubkey.clone());
app.person_view_person = Some(person.clone());
app.person_view_name = if let Some(name) = &person.name {
Some(name.to_string())
} else {
Some(GossipUi::hex_pubkey_short(&person.pubkey))
};
app.page = Page::Person;
}