UI screen to wait for data migration

This commit is contained in:
Mike Dilger 2023-12-03 08:40:27 +13:00
parent cd36343f97
commit ea8eb06070
4 changed files with 65 additions and 34 deletions

View File

@ -187,9 +187,7 @@ impl Page {
match self {
Page::DmChatList => cat_name(self),
Page::Feed(_) => name_cat(self),
Page::PeopleFollowNew
| Page::PeopleLists
| Page::PeopleList(_) => cat_name(self),
Page::PeopleFollowNew | Page::PeopleLists | Page::PeopleList(_) => cat_name(self),
Page::Person(_) => name_cat(self),
Page::YourKeys | Page::YourMetadata | Page::YourDelegation => cat_name(self),
Page::Wizard(_) => name_cat(self),
@ -728,9 +726,7 @@ impl GossipUi {
GLOBALS.feed.set_feed_to_person(pubkey.to_owned());
self.close_all_menus(ctx);
}
Page::PeopleFollowNew
| Page::PeopleLists
| Page::Person(_) => {
Page::PeopleFollowNew | Page::PeopleLists | Page::Person(_) => {
self.open_menu(ctx, SubMenu::People);
}
Page::YourKeys | Page::YourMetadata | Page::YourDelegation => {
@ -1183,6 +1179,11 @@ impl eframe::App for GossipUi {
return force_login(self, ctx);
}
// If data migration, show that screen
if GLOBALS.wait_for_data_migration.load(Ordering::Relaxed) {
return wait_for_data_migration(self, ctx);
}
// Wizard does its own panels
if let Page::Wizard(wp) = self.page {
return wizard::update(self, ctx, frame, wp);
@ -1893,3 +1894,19 @@ fn force_login(app: &mut GossipUi, ctx: &Context) {
you::offer_delete(app, ui);
});
}
fn wait_for_data_migration(app: &mut GossipUi, ctx: &Context) {
egui::CentralPanel::default()
.frame({
let frame = egui::Frame::central_panel(&app.theme.get_style());
frame.inner_margin(egui::Margin {
left: 20.0,
right: 10.0,
top: 10.0,
bottom: 0.0,
})
})
.show(ctx, |ui| {
ui.label("Please wait for the data migration to complete...");
});
}

View File

@ -13,10 +13,7 @@ pub(super) fn update(
list: PersonList,
) {
let people = {
let members = GLOBALS
.storage
.get_people_in_list(list)
.unwrap_or_default();
let members = GLOBALS.storage.get_people_in_list(list).unwrap_or_default();
let mut people: Vec<(Person, bool)> = Vec::new();
@ -29,7 +26,7 @@ pub(super) fn update(
people.push((person, *public));
}
}
people.sort_by(|a,b| a.0.cmp(&b.0));
people.sort_by(|a, b| a.0.cmp(&b.0));
people
};
@ -200,7 +197,12 @@ pub(super) fn update(
ui.horizontal(|ui| {
if crate::ui::components::switch_simple(ui, *public).clicked() {
let _ = GLOBALS.storage.add_person_to_list(&person.pubkey, list, !*public, None);
let _ = GLOBALS.storage.add_person_to_list(
&person.pubkey,
list,
!*public,
None,
);
}
ui.label(if *public { "public" } else { "private" });
});
@ -208,7 +210,9 @@ pub(super) fn update(
});
if ui.button("Remove").clicked() {
let _ = GLOBALS.storage.remove_person_from_list(&person.pubkey, list, None);
let _ = GLOBALS
.storage
.remove_person_from_list(&person.pubkey, list, None);
}
ui.add_space(4.0);

View File

@ -130,6 +130,9 @@ pub struct Globals {
// Wait for login
pub wait_for_login: AtomicBool,
pub wait_for_login_notify: Notify,
// Wait for data migration
pub wait_for_data_migration: AtomicBool,
}
lazy_static! {
@ -187,6 +190,7 @@ lazy_static! {
filter,
wait_for_login: AtomicBool::new(false),
wait_for_login_notify: Notify::new(),
wait_for_data_migration: AtomicBool::new(false),
}
};
}

View File

@ -167,7 +167,13 @@ impl Overlord {
// If we need to rebuild relationships, do so now
if GLOBALS.storage.get_flag_rebuild_relationships_needed() {
GLOBALS
.wait_for_data_migration
.store(true, Ordering::Relaxed);
GLOBALS.storage.rebuild_relationships(None)?;
GLOBALS
.wait_for_data_migration
.store(false, Ordering::Relaxed);
}
// Start the fetcher
@ -859,9 +865,7 @@ impl Overlord {
}
/// Delete a person list
pub async fn delete_person_list(&mut self, list: PersonList)
-> Result<(), Error>
{
pub async fn delete_person_list(&mut self, list: PersonList) -> Result<(), Error> {
let public_key = match GLOBALS.signer.public_key() {
Some(pk) => pk,
None => {
@ -886,31 +890,35 @@ impl Overlord {
&[public_key],
None,
|event| event.parameter() == Some(name.clone()),
false
false,
)?;
tracing::error!("DEBUG: deleting {} local events for list={}",
bad_events.len(), name);
tracing::error!(
"DEBUG: deleting {} local events for list={}",
bad_events.len(),
name
);
// Delete those events locally
for bad_event in &bad_events {
GLOBALS.storage.delete_event(bad_event.id, None)?;
tracing::error!("DEBUG: deleting event={} from local events for list={}",
bad_event.id.as_hex_string(), name);
tracing::error!(
"DEBUG: deleting event={} from local events for list={}",
bad_event.id.as_hex_string(),
name
);
}
// Generate a deletion event for those events
let event = {
// Include an "a" tag for the entire group
let mut tags: Vec<Tag> = vec![
Tag::Address {
kind: EventKind::FollowSets,
pubkey: public_key.into(),
d: name.clone(),
relay_url: None,
marker: None,
trailing: Vec::new(),
}
];
let mut tags: Vec<Tag> = vec![Tag::Address {
kind: EventKind::FollowSets,
pubkey: public_key.into(),
d: name.clone(),
relay_url: None,
marker: None,
trailing: Vec::new(),
}];
// Include "e" tags for each event
for bad_event in &bad_events {
@ -926,9 +934,7 @@ impl Overlord {
pubkey: public_key,
created_at: Unixtime::now().unwrap(),
kind: EventKind::EventDeletion,
tags: vec![
],
tags: vec![],
content: "".to_owned(), // FIXME, option to supply a delete reason
};