Compare commits

..

No commits in common. "d15900434099f60c647922551f539df5ee4276a2" and "ca263b50d2a0d38c33c31fd6161bd966361051b8" have entirely different histories.

4 changed files with 18 additions and 30 deletions

View file

@ -17,11 +17,8 @@ pub struct Hashtag {
}
impl Hashtag {
pub fn contains(&self, token: &str) -> bool {
self.lowercased.contains(&token.to_ascii_lowercase())
}
pub fn matches(&self, token: &str) -> bool {
token.contains(&self.lowercased)
self.lowercased.contains(&token.to_ascii_lowercase())
}
}

View file

@ -282,9 +282,8 @@ async fn main() -> Result<()> {
println!();
let tasks = relays.get(&selected_relay).unwrap();
let prompt = format!(
"{}{} {}{}{}",
"{} {}{}{}",
selected_relay.as_ref().map_or(LOCAL_RELAY_NAME.to_string(), |url| url.to_string()).dimmed(),
tasks.pubkey_str().map_or(String::new(), |s| format!(" @{s}")),
tasks.get_task_path(tasks.get_position()).bold(),
tasks.get_prompt_suffix().italic(),
" ".dimmed()
@ -729,7 +728,7 @@ async fn main() -> Result<()> {
tasks.get_filtered(pos, |t| {
transform(&t.event.content).contains(&remaining) ||
t.list_hashtags().any(
|tag| tag.contains(&remaining))
|tag| tag.matches(&remaining))
});
if filtered.len() == 1 {
tasks.move_to(filtered.into_iter().next());

View file

@ -71,18 +71,15 @@ impl Task {
&self.event.id
}
pub(crate) fn get_participants(&self) -> impl Iterator<Item=PublicKey> + '_ {
self.tags()
.filter(|t| t.kind() == TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::P)))
.filter_map(|t| t.content()
.and_then(|c| PublicKey::from_str(c).inspect_err(|e| warn!("Unparseable pubkey in {:?}", t)).ok()))
}
pub(crate) fn get_owner(&self) -> PublicKey {
self.get_participants().next()
self.tags()
.find(|t| t.kind() == TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::P)))
.and_then(|t| t.content()
.and_then(|c| PublicKey::from_str(c).inspect_err(|e| warn!("Unparseable pubkey in {:?}", t)).ok()))
.unwrap_or_else(|| self.event.pubkey)
}
pub(crate) fn find_refs<'a>(&'a self, marker: &'a str) -> impl Iterator<Item=&'a EventId> {
self.refs.iter().filter_map(move |(str, id)| Some(id).filter(|_| str == marker))
}

View file

@ -399,22 +399,18 @@ impl TasksRelay {
.and_then(|t| t.parent_id())
}
pub(crate) fn pubkey_str(&self) -> Option<String> {
match self.pubkey {
None => { Some("ALL".to_string()) }
Some(key) =>
if key != self.sender.pubkey() {
Some(self.users.get_username(&key))
} else {
None
},
}
}
// TODO test with context elements
/// Visual representation of current context
pub(crate) fn get_prompt_suffix(&self) -> String {
let mut prompt = String::with_capacity(128);
match self.pubkey {
None => { prompt.push_str(" @ALL"); }
Some(key) =>
if key != self.sender.pubkey() {
prompt.push_str(" @");
prompt.push_str(&self.users.get_username(&key))
},
}
for tag in self.tags.iter() {
prompt.push_str(&format!(" #{}", tag));
}
@ -513,8 +509,7 @@ impl TasksRelay {
fn filter(&self, task: &Task) -> bool {
self.state.matches(task) &&
(!task.is_task() || self.pubkey.is_none_or(|p| p == task.get_owner() ||
task.list_hashtags().any(|t| t.matches(&self.users.get_username(&p))))) &&
(!task.is_task() || self.pubkey.is_none_or(|p| p == task.get_owner())) &&
self.priority.is_none_or(|prio| {
task.priority().unwrap_or(DEFAULT_PRIO) >= prio
}) &&
@ -821,7 +816,7 @@ impl TasksRelay {
pub(crate) fn remove_tag(&mut self, tag: &str) {
self.view.clear();
let len = self.tags.len();
self.tags.retain(|t| !t.contains(tag));
self.tags.retain(|t| !t.matches(tag));
if self.tags.len() < len {
info!("Removed tag filters containing {tag}");
} else {