fix(task): omit tags referencing events in property getter

This commit is contained in:
xeruf 2024-07-29 14:13:32 +03:00
parent eb7e571f1e
commit 1251f54789
1 changed files with 17 additions and 14 deletions

View File

@ -2,7 +2,7 @@ use std::collections::{BTreeSet, HashSet};
use std::fmt; use std::fmt;
use std::ops::Div; use std::ops::Div;
use nostr_sdk::{Event, EventBuilder, EventId, Kind, Tag, Timestamp}; use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, Kind, Tag, Timestamp};
use crate::EventSender; use crate::EventSender;
@ -127,6 +127,17 @@ impl Task {
} }
total total
} }
fn filter_tags<P>(&self, predicate: P) -> Option<String>
where P: FnMut(&&Tag) -> bool{
self.tags.as_ref().map(|tags| {
tags.into_iter()
.filter(predicate)
.map(|t| format!("{}", t.content().unwrap()))
.collect::<Vec<String>>()
.join(" ")
})
}
pub(crate) fn get(&self, property: &str) -> Option<String> { pub(crate) fn get(&self, property: &str) -> Option<String> {
match property { match property {
@ -135,12 +146,8 @@ impl Task {
"state" => self.state().map(|s| s.to_string()), "state" => self.state().map(|s| s.to_string()),
"name" => Some(self.event.content.clone()), "name" => Some(self.event.content.clone()),
"time" => Some(format!("{}m", self.time_tracked().div(60))), "time" => Some(format!("{}m", self.time_tracked().div(60))),
"tags" => self.tags.as_ref().map(|tags| { "hashtags" => self.filter_tags(|tag| tag.single_letter_tag().is_some_and(|sltag| sltag.character == Alphabet::T)),
tags.iter() "tags" => self.filter_tags(|tag| !tag.single_letter_tag().is_some_and(|sltag| sltag.character == Alphabet::E)),
.map(|t| format!("{}", t.content().unwrap()))
.collect::<Vec<String>>()
.join(" ")
}),
"props" => Some(format!( "props" => Some(format!(
"{:?}", "{:?}",
self.props self.props
@ -148,14 +155,10 @@ impl Task {
.map(|e| format!("{} kind {} '{}'", e.created_at, e.kind, e.content)) .map(|e| format!("{} kind {} '{}'", e.created_at, e.kind, e.content))
.collect::<Vec<String>>() .collect::<Vec<String>>()
)), )),
"desc" | "description" => self.descriptions().fold(None, |total, s| { "descriptions" => Some(format!("{:?}", self.descriptions().collect::<Vec<&String>>())),
Some(match total { "desc" | "description" => self.descriptions().last().cloned(),
None => s.clone(),
Some(i) => i + " " + s,
})
}),
_ => { _ => {
eprintln!("Unknown column {}", property); eprintln!("Unknown task property {}", property);
None None
} }
} }