Remove Followed/Muted pages (use PersonList(_) page instead)

This commit is contained in:
Mike Dilger 2023-11-29 09:39:07 +13:00
parent 6d7d5e311f
commit 6ce1d8ef08
5 changed files with 4 additions and 431 deletions

View File

@ -67,7 +67,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.horizontal_wrapped(|ui| {
ui.label("On the");
if ui.link("People > Followed").clicked() {
app.set_page(ctx, Page::PeopleFollowed);
app.set_page(ctx, Page::PeopleList(PersonList::Followed));
}
ui.label("page, press [↓ Pull ↓ Overwrite] to pull down the people you follow. They won't have metadata just yet.");
});
@ -91,7 +91,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.horizontal_wrapped(|ui| {
ui.label("Back on the");
if ui.link("People > Followed").clicked() {
app.set_page(ctx, Page::PeopleFollowed);
app.set_page(ctx, Page::PeopleList(PersonList::Followed));
}
ui.label("page, once the relay picking has settled down, press [Refresh Metadata]. Then give it some time. It might not be able to find everybody just yet.");
});
@ -187,7 +187,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.horizontal_wrapped(|ui| {
ui.label("On the");
if ui.link("People > Followed").clicked() {
app.set_page(ctx, Page::PeopleFollowed);
app.set_page(ctx, Page::PeopleList(PersonList::Followed));
}
ui.label("page, once the relay picking has settled down, press [Refresh Metadata]. Then give it some time. It might not be able to find everybody just yet.");
});

View File

@ -107,8 +107,6 @@ enum Page {
PeopleFollowNew, // deprecated, will separately be part of the list page
PeopleLists,
PeopleList(PersonList),
PeopleFollowed, // deprecated, will use PeopleList(PersonList)
PeopleMuted, // deprecated, will use PeopleList(PersonList)
Person(PublicKey),
YourKeys,
YourMetadata,
@ -145,8 +143,6 @@ impl Page {
Page::PeopleFollowNew => (SubMenu::People.as_str(), "Follow new".into()),
Page::PeopleLists => (SubMenu::People.as_str(), "Lists".into()),
Page::PeopleList(list) => ("People", list.name()),
Page::PeopleFollowed => (SubMenu::People.as_str(), "Followed".into()),
Page::PeopleMuted => (SubMenu::People.as_str(), "Muted".into()),
Page::Person(pk) => {
let name = gossip_lib::names::best_name_from_pubkey_lookup(pk);
("Profile", name)
@ -193,9 +189,7 @@ impl Page {
Page::Feed(_) => name_cat(self),
Page::PeopleFollowNew
| Page::PeopleLists
| Page::PeopleList(_)
| Page::PeopleFollowed
| Page::PeopleMuted => cat_name(self),
| Page::PeopleList(_) => cat_name(self),
Page::Person(_) => name_cat(self),
Page::YourKeys | Page::YourMetadata | Page::YourDelegation => cat_name(self),
Page::Wizard(_) => name_cat(self),
@ -416,8 +410,6 @@ struct GossipUi {
// User entry: general
follow_someone: String,
add_relay: String, // dep
follow_clear_needs_confirm: bool,
mute_clear_needs_confirm: bool,
clear_list_needs_confirm: bool,
password: String,
password2: String,
@ -658,8 +650,6 @@ impl GossipUi {
delegatee_tag_str: "".to_owned(),
follow_someone: "".to_owned(),
add_relay: "".to_owned(),
follow_clear_needs_confirm: false,
mute_clear_needs_confirm: false,
clear_list_needs_confirm: false,
password: "".to_owned(),
password2: "".to_owned(),
@ -740,8 +730,6 @@ impl GossipUi {
}
Page::PeopleFollowNew
| Page::PeopleLists
| Page::PeopleFollowed
| Page::PeopleMuted
| Page::Person(_) => {
self.open_menu(ctx, SubMenu::People);
}
@ -907,8 +895,6 @@ impl GossipUi {
cstate.show_body_indented(&header_response, ui, |ui| {
self.add_menu_item_page(ui, Page::PeopleFollowNew);
self.add_menu_item_page(ui, Page::PeopleLists);
self.add_menu_item_page(ui, Page::PeopleFollowed);
self.add_menu_item_page(ui, Page::PeopleMuted);
});
self.after_openable_menu(ui, &cstate);
}
@ -1282,8 +1268,6 @@ impl eframe::App for GossipUi {
Page::PeopleFollowNew
| Page::PeopleLists
| Page::PeopleList(_)
| Page::PeopleFollowed
| Page::PeopleMuted
| Page::Person(_) => {
if self.theme.dark_mode {
ctx.style().visuals.panel_fill
@ -1303,8 +1287,6 @@ impl eframe::App for GossipUi {
Page::PeopleFollowNew
| Page::PeopleLists
| Page::PeopleList(_)
| Page::PeopleFollowed
| Page::PeopleMuted
| Page::Person(_) => people::update(self, ctx, frame, ui),
Page::YourKeys | Page::YourMetadata | Page::YourDelegation => {
you::update(self, ctx, frame, ui)

View File

@ -1,210 +0,0 @@
use super::{GossipUi, Page};
use crate::ui::widgets;
use eframe::egui;
use egui::{Context, RichText, Ui};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::{Person, PersonList, GLOBALS};
use nostr_types::PublicKey;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
let followed_pubkeys: Vec<PublicKey> = GLOBALS
.storage
.get_people_in_list(PersonList::Followed)
.unwrap_or_default()
.drain(..)
.map(|(pk, _)| pk)
.collect();
let mut people: Vec<Person> = Vec::new();
for pk in &followed_pubkeys {
if let Ok(Some(person)) = GLOBALS.storage.read_person(pk) {
people.push(person);
} else {
let person = Person::new(pk.to_owned());
let _ = GLOBALS.storage.write_person(&person, None);
people.push(person);
}
}
people.sort();
ui.add_space(12.0);
let latest_event_data = GLOBALS
.people
.latest_person_list_event_data
.get(&PersonList::Followed)
.map(|v| v.value().clone())
.unwrap_or_default();
let mut asof = "unknown".to_owned();
if let Ok(stamp) = time::OffsetDateTime::from_unix_timestamp(latest_event_data.when.0) {
if let Ok(formatted) = stamp.format(time::macros::format_description!(
"[year]-[month repr:short]-[day] ([weekday repr:short]) [hour]:[minute]"
)) {
asof = formatted;
}
}
ui.label(
RichText::new(format!(
"REMOTE: {} (len={})",
asof, latest_event_data.public_len
))
.size(15.0),
)
.on_hover_text("This is the data in the latest ContactList event fetched from relays");
ui.add_space(10.0);
ui.horizontal(|ui| {
ui.add_space(30.0);
if ui
.button("↓ Overwrite ↓")
.on_hover_text(
"This pulls down your Contact List, erasing anything that is already here",
)
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UpdatePersonList {
person_list: PersonList::Followed,
merge: false,
});
}
if ui
.button("↓ Merge ↓")
.on_hover_text(
"This pulls down your Contact List, merging it into what is already here",
)
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UpdatePersonList {
person_list: PersonList::Followed,
merge: true,
});
}
if GLOBALS.signer.is_ready() {
if ui
.button("↑ Publish ↑")
.on_hover_text("This publishes your Contact List")
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::PushPersonList(PersonList::Followed));
}
}
if GLOBALS.signer.is_ready() {
if app.follow_clear_needs_confirm {
if ui.button("CANCEL").clicked() {
app.follow_clear_needs_confirm = false;
}
if ui.button("YES, CLEAR ALL").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::ClearPersonList(PersonList::Followed));
app.follow_clear_needs_confirm = false;
}
} else {
if ui.button("Clear All").clicked() {
app.follow_clear_needs_confirm = true;
}
}
}
if ui
.button("Refresh Metadata")
.on_hover_text(
"This will seek out metadata (name, avatar, etc) on each person in the list below",
)
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::RefreshSubscribedMetadata);
}
});
ui.add_space(10.0);
let last_contact_list_edit = match GLOBALS
.storage
.get_person_list_last_edit_time(PersonList::Followed)
{
Ok(Some(date)) => date,
Ok(None) => 0,
Err(e) => {
tracing::error!("{}", e);
0
}
};
let mut ledit = "unknown".to_owned();
if let Ok(stamp) = time::OffsetDateTime::from_unix_timestamp(last_contact_list_edit) {
if let Ok(formatted) = stamp.format(time::macros::format_description!(
"[year]-[month repr:short]-[day] ([weekday repr:short]) [hour]:[minute]"
)) {
ledit = formatted;
}
}
ui.label(RichText::new(format!("LOCAL: {} (size={})", ledit, people.len())).size(15.0))
.on_hover_text("This is the local (and effective) following list");
if !GLOBALS.signer.is_ready() {
ui.add_space(10.0);
ui.horizontal_wrapped(|ui| {
ui.label("You need to ");
if ui.link("setup your identity").clicked() {
app.set_page(ctx, Page::YourKeys);
}
ui.label(" to push.");
});
}
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
ui.heading(format!("People Followed ({})", people.len()));
ui.add_space(18.0);
app.vert_scroll_area().show(ui, |ui| {
for person in people.iter() {
ui.horizontal(|ui| {
// Avatar first
let avatar = if let Some(avatar) = app.try_get_avatar(ctx, &person.pubkey) {
avatar
} else {
app.placeholder_avatar.clone()
};
if widgets::paint_avatar(ui, person, &avatar, widgets::AvatarSize::Feed).clicked() {
app.set_page(ctx, Page::Person(person.pubkey));
};
ui.vertical(|ui| {
ui.label(RichText::new(gossip_lib::names::pubkey_short(&person.pubkey)).weak());
GossipUi::render_person_name_line(app, ui, person, false);
if !GLOBALS
.storage
.have_persons_relays(person.pubkey)
.unwrap_or(false)
{
ui.label(
RichText::new("Relay list not found")
.color(app.theme.warning_marker_text_color()),
);
}
});
});
ui.add_space(4.0);
ui.separator();
}
});
}

View File

@ -3,10 +3,8 @@ use eframe::egui;
use egui::{Context, Ui};
mod follow;
mod followed;
mod list;
mod lists;
mod muted;
mod person;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
@ -16,10 +14,6 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
lists::update(app, ctx, _frame, ui);
} else if let Page::PeopleList(plist) = app.page {
list::update(app, ctx, _frame, ui, plist);
} else if app.page == Page::PeopleFollowed {
followed::update(app, ctx, _frame, ui);
} else if app.page == Page::PeopleMuted {
muted::update(app, ctx, _frame, ui);
} else if matches!(app.page, Page::Person(_)) {
person::update(app, ctx, _frame, ui);
}

View File

@ -1,193 +0,0 @@
use super::{GossipUi, Page};
use crate::ui::widgets;
use eframe::egui;
use egui::{Context, RichText, Ui};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::{Person, PersonList, GLOBALS};
use nostr_types::PublicKey;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
let muted_pubkeys: Vec<PublicKey> = GLOBALS
.storage
.get_people_in_list(PersonList::Muted)
.unwrap_or_default()
.drain(..)
.map(|(pk, _)| pk)
.collect();
let mut people: Vec<Person> = Vec::new();
for pk in &muted_pubkeys {
if let Ok(Some(person)) = GLOBALS.storage.read_person(pk) {
people.push(person);
} else {
let person = Person::new(pk.to_owned());
let _ = GLOBALS.storage.write_person(&person, None);
people.push(person);
}
}
people.sort();
ui.add_space(12.0);
let latest_event_data = GLOBALS
.people
.latest_person_list_event_data
.get(&PersonList::Muted)
.map(|v| v.value().clone())
.unwrap_or_default();
let mut asof = "unknown".to_owned();
if let Ok(stamp) = time::OffsetDateTime::from_unix_timestamp(latest_event_data.when.0) {
if let Ok(formatted) = stamp.format(time::macros::format_description!(
"[year]-[month repr:short]-[day] ([weekday repr:short]) [hour]:[minute]"
)) {
asof = formatted;
}
}
let txt = if let Some(private_len) = latest_event_data.private_len {
format!(
"REMOTE: {} (public_len={} private_len={})",
asof, latest_event_data.public_len, private_len
)
} else {
format!(
"REMOTE: {} (public_len={})",
asof, latest_event_data.public_len
)
};
ui.label(RichText::new(txt).size(15.0))
.on_hover_text("This is the data in the latest MuteList event fetched from relays");
ui.add_space(10.0);
ui.horizontal(|ui| {
ui.add_space(30.0);
if ui
.button("↓ Overwrite ↓")
.on_hover_text("This pulls down your Mute List, erasing anything that is already here")
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UpdatePersonList {
person_list: PersonList::Muted,
merge: false,
});
}
if ui
.button("↓ Merge ↓")
.on_hover_text("This pulls down your Mute List, merging it into what is already here")
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UpdatePersonList {
person_list: PersonList::Muted,
merge: true,
});
}
if GLOBALS.signer.is_ready() {
if ui
.button("↑ Publish ↑")
.on_hover_text("This publishes your Mute List")
.clicked()
{
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::PushPersonList(PersonList::Muted));
}
}
if GLOBALS.signer.is_ready() {
if app.mute_clear_needs_confirm {
if ui.button("CANCEL").clicked() {
app.mute_clear_needs_confirm = false;
}
if ui.button("YES, CLEAR ALL").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::ClearPersonList(PersonList::Muted));
app.mute_clear_needs_confirm = false;
}
} else {
if ui.button("Clear All").clicked() {
app.mute_clear_needs_confirm = true;
}
}
}
});
ui.add_space(10.0);
let last_mute_list_edit = match GLOBALS
.storage
.get_person_list_last_edit_time(PersonList::Muted)
{
Ok(Some(date)) => date,
Ok(None) => 0,
Err(e) => {
tracing::error!("{}", e);
0
}
};
let mut ledit = "unknown".to_owned();
if let Ok(stamp) = time::OffsetDateTime::from_unix_timestamp(last_mute_list_edit) {
if let Ok(formatted) = stamp.format(time::macros::format_description!(
"[year]-[month repr:short]-[day] ([weekday repr:short]) [hour]:[minute]"
)) {
ledit = formatted;
}
}
ui.label(RichText::new(format!("LOCAL: {} (size={})", ledit, people.len())).size(15.0))
.on_hover_text("This is the local (and effective) mute list");
if !GLOBALS.signer.is_ready() {
ui.add_space(10.0);
ui.horizontal_wrapped(|ui| {
ui.label("You need to ");
if ui.link("setup your identity").clicked() {
app.set_page(ctx, Page::YourKeys);
}
ui.label(" to push.");
});
}
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
ui.heading(format!("People who are Muted ({})", people.len()));
ui.add_space(10.0);
app.vert_scroll_area().show(ui, |ui| {
for person in people.iter() {
ui.horizontal(|ui| {
// Avatar first
let avatar = if let Some(avatar) = app.try_get_avatar(ctx, &person.pubkey) {
avatar
} else {
app.placeholder_avatar.clone()
};
if widgets::paint_avatar(ui, person, &avatar, widgets::AvatarSize::Feed).clicked() {
app.set_page(ctx, Page::Person(person.pubkey));
};
ui.vertical(|ui| {
ui.label(RichText::new(gossip_lib::names::pubkey_short(&person.pubkey)).weak());
GossipUi::render_person_name_line(app, ui, person, false);
if ui.button("UNMUTE").clicked() {
let _ = GLOBALS.people.mute(&person.pubkey, false, true);
}
});
});
ui.add_space(4.0);
ui.separator();
}
});
}