forked from janek/mostr
refactor(main): improved debug output
This commit is contained in:
parent
bbfbb2d8b0
commit
8588fb9a04
16
src/main.rs
16
src/main.rs
|
@ -298,6 +298,8 @@ async fn main() {
|
|||
|
||||
let mut lines = stdin().lines();
|
||||
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!();
|
||||
let tasks = selected_relay.as_ref().and_then(|url| relays.get(url)).unwrap_or(&local_tasks);
|
||||
print!(
|
||||
|
@ -320,10 +322,13 @@ async fn main() {
|
|||
..
|
||||
} = 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) {
|
||||
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;
|
||||
}
|
||||
|
@ -582,10 +587,3 @@ async fn main() {
|
|||
info!("Submitting pending updates...");
|
||||
or_print(sender.await);
|
||||
}
|
||||
|
||||
fn print_event(event: &Event) {
|
||||
debug!(
|
||||
"At {} found {} kind {} \"{}\" {:?}",
|
||||
event.created_at, event.id, event.kind, event.content, event.tags
|
||||
);
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ impl Tasks {
|
|||
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
|
||||
.values()
|
||||
.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())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue