forked from janek/mostr
1
0
Fork 0

refactor(main): improved debug output

This commit is contained in:
xeruf 2024-08-14 15:56:40 +03:00
parent bbfbb2d8b0
commit 8588fb9a04
2 changed files with 9 additions and 11 deletions

View File

@ -298,6 +298,8 @@ async fn main() {
let mut lines = stdin().lines(); let mut lines = stdin().lines();
loop { loop {
trace!("All Root Tasks:\n{}", relays.iter().map(|(url, tasks)|
format!("{}: [{}]", url, tasks.children_of(None).map(|id| tasks.get_task_title(id)).join("; "))).join("\n"));
println!(); println!();
let tasks = selected_relay.as_ref().and_then(|url| relays.get(url)).unwrap_or(&local_tasks); let tasks = selected_relay.as_ref().and_then(|url| relays.get(url)).unwrap_or(&local_tasks);
print!( print!(
@ -320,10 +322,13 @@ async fn main() {
.. ..
} = notification } = notification
{ {
print_event(&event); debug!(
"At {} found {} kind {} content \"{}\" tags {:?}",
event.created_at, event.id, event.kind, event.content, event.tags.iter().map(|tag| tag.as_vec()).collect_vec()
);
match relays.get_mut(&relay_url) { match relays.get_mut(&relay_url) {
Some(tasks) => tasks.add(*event), Some(tasks) => tasks.add(*event),
None => warn!("Event received from unknown relay {relay_url}: {:?}", event) None => warn!("Event received from unknown relay {relay_url}: {:?}", *event)
} }
count += 1; count += 1;
} }
@ -582,10 +587,3 @@ async fn main() {
info!("Submitting pending updates..."); info!("Submitting pending updates...");
or_print(sender.await); or_print(sender.await);
} }
fn print_event(event: &Event) {
debug!(
"At {} found {} kind {} \"{}\" {:?}",
event.created_at, event.id, event.kind, event.content, event.tags
);
}

View File

@ -336,7 +336,7 @@ impl Tasks {
self.position.and_then(|id| self.get_by_id(&id)) self.position.and_then(|id| self.get_by_id(&id))
} }
pub(crate) fn children_of(&self, id: Option<EventId>) -> impl IntoIterator<Item=&EventId> + '_ { pub(crate) fn children_of(&self, id: Option<EventId>) -> impl Iterator<Item=&EventId> + '_ {
self.tasks self.tasks
.values() .values()
.filter(move |t| t.parent_id() == id.as_ref()) .filter(move |t| t.parent_id() == id.as_ref())
@ -686,7 +686,7 @@ impl Tasks {
) )
} }
fn get_task_title(&self, id: &EventId) -> String { pub(crate) fn get_task_title(&self, id: &EventId) -> String {
self.tasks.get(id).map_or(id.to_string(), |t| t.get_title()) self.tasks.get(id).map_or(id.to_string(), |t| t.get_title())
} }