feat: also match user filter to hashtag and position better in prompt

This commit is contained in:
xeruf 2024-11-25 14:23:05 +01:00
parent 591adafd6e
commit d159004340
3 changed files with 22 additions and 13 deletions

View File

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

View File

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

View File

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