mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Update Metadata
This commit is contained in:
parent
f991e4e801
commit
8d7f062a1a
@ -27,6 +27,10 @@ impl Minion {
|
|||||||
ws_sink.send(WsMessage::Text(wire)).await?;
|
ws_sink.send(WsMessage::Text(wire)).await?;
|
||||||
info!("Posted event to {}", &self.url);
|
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!(
|
warn!(
|
||||||
"{} Unrecognized bus message kind received by minion: {}",
|
"{} Unrecognized bus message kind received by minion: {}",
|
||||||
|
@ -386,6 +386,18 @@ impl Minion {
|
|||||||
Ok(())
|
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)]
|
#[allow(dead_code)]
|
||||||
async fn subscribe(&mut self, filters: Vec<Filter>, handle: &str) -> Result<(), Error> {
|
async fn subscribe(&mut self, filters: Vec<Filter>, handle: &str) -> Result<(), Error> {
|
||||||
let req_message = if self.subscriptions.has(handle) {
|
let req_message = if self.subscriptions.has(handle) {
|
||||||
|
@ -523,6 +523,24 @@ impl Overlord {
|
|||||||
DbRelay::insert(dbrelay).await?;
|
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(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -389,6 +389,16 @@ fn render_post_actual(
|
|||||||
if ui.button("Dismiss").clicked() {
|
if ui.button("Dismiss").clicked() {
|
||||||
GLOBALS.dismissed.blocking_write().push(event.id);
|
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(
|
ui.label(
|
||||||
@ -472,14 +482,6 @@ fn render_content(ui: &mut Ui, content: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_person_view(app: &mut GossipUi, pubkeyhex: &PublicKeyHex) {
|
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.person_view_pubkey = Some(pubkeyhex.to_owned());
|
||||||
app.page = Page::Person;
|
app.page = Page::Person;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,6 @@ struct GossipUi {
|
|||||||
replying_to: Option<Id>,
|
replying_to: Option<Id>,
|
||||||
hides: Vec<Id>,
|
hides: Vec<Id>,
|
||||||
person_view_pubkey: Option<PublicKeyHex>,
|
person_view_pubkey: Option<PublicKeyHex>,
|
||||||
person_view_person: Option<DbPerson>,
|
|
||||||
person_view_name: Option<String>,
|
|
||||||
avatars: HashMap<PublicKeyHex, TextureHandle>,
|
avatars: HashMap<PublicKeyHex, TextureHandle>,
|
||||||
new_relay_url: String,
|
new_relay_url: String,
|
||||||
}
|
}
|
||||||
@ -161,8 +159,6 @@ impl GossipUi {
|
|||||||
replying_to: None,
|
replying_to: None,
|
||||||
hides: Vec::new(),
|
hides: Vec::new(),
|
||||||
person_view_pubkey: None,
|
person_view_pubkey: None,
|
||||||
person_view_person: None,
|
|
||||||
person_view_name: None,
|
|
||||||
avatars: HashMap::new(),
|
avatars: HashMap::new(),
|
||||||
new_relay_url: "".to_owned(),
|
new_relay_url: "".to_owned(),
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,20 @@ use eframe::egui;
|
|||||||
use egui::{Context, Image, RichText, ScrollArea, Sense, TextEdit, TopBottomPanel, Ui, Vec2};
|
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) {
|
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| {
|
TopBottomPanel::top("people_menu").show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.selectable_value(&mut app.page, Page::PeopleList, "Followed");
|
ui.selectable_value(&mut app.page, Page::PeopleList, "Followed");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.selectable_value(&mut app.page, Page::PeopleFollow, "Follow Someone New");
|
ui.selectable_value(&mut app.page, Page::PeopleFollow, "Follow Someone New");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if let Some(name) = &app.person_view_name {
|
if let Some(person) = &maybe_person {
|
||||||
ui.selectable_value(&mut app.page, Page::Person, name);
|
ui.selectable_value(&mut app.page, Page::Person, get_name(person));
|
||||||
ui.separator();
|
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 {
|
} else if app.page == Page::Person {
|
||||||
if app.person_view_pubkey.is_none()
|
if maybe_person.is_none() || app.person_view_pubkey.is_none() {
|
||||||
|| app.person_view_person.is_none()
|
|
||||||
|| app.person_view_name.is_none()
|
|
||||||
{
|
|
||||||
ui.label("ERROR");
|
ui.label("ERROR");
|
||||||
} else {
|
} else {
|
||||||
let pubkeyhex = app.person_view_pubkey.as_ref().unwrap().to_owned();
|
let person = maybe_person.as_ref().unwrap();
|
||||||
let person = app.person_view_person.as_ref().unwrap().to_owned();
|
let pubkeyhex = app.person_view_pubkey.as_ref().unwrap().clone();
|
||||||
let name = app.person_view_name.as_ref().unwrap().to_owned();
|
|
||||||
|
|
||||||
ui.add_space(24.0);
|
ui.add_space(24.0);
|
||||||
|
|
||||||
ui.heading(name);
|
ui.heading(get_name(person));
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
// Avatar first
|
// Avatar first
|
||||||
@ -187,7 +189,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.label(RichText::new(GossipUi::hex_pubkey_short(&pubkeyhex)).weak());
|
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 person.followed == 0 {
|
||||||
if ui.button("FOLLOW").clicked() {
|
if ui.button("FOLLOW").clicked() {
|
||||||
GLOBALS.people.blocking_write().follow(&pubkeyhex, true);
|
GLOBALS.people.blocking_write().follow(&pubkeyhex, true);
|
||||||
app.person_view_person.as_mut().unwrap().followed = 1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ui.button("UNFOLLOW").clicked() {
|
if ui.button("UNFOLLOW").clicked() {
|
||||||
GLOBALS.people.blocking_write().follow(&pubkeyhex, false);
|
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) {
|
fn set_person_view(app: &mut GossipUi, person: &DbPerson) {
|
||||||
app.person_view_pubkey = Some(person.pubkey.clone());
|
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;
|
app.page = Page::Person;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user