Compare commits

..

2 Commits

Author SHA1 Message Date
xeruf fd970b3709 fix(tasks): match task names at word boundary with regex 2024-10-01 23:20:08 +02:00
xeruf c6de8daee9 fix(main): increase notification channel size
apparently it needs to be double of the expected events,
so even this is only a temporary remedy
2024-10-01 23:19:01 +02:00
2 changed files with 36 additions and 7 deletions

View File

@ -203,7 +203,9 @@ async fn main() -> Result<()> {
};
let client = ClientBuilder::new()
.opts(Options::new().automatic_authentication(true))
.opts(Options::new()
.automatic_authentication(true)
.pool(RelayPoolOptions::new().notification_channel_size(8192)))
.signer(&keys)
.build();
info!("My public key: {}", keys.public_key());
@ -246,6 +248,22 @@ async fn main() -> Result<()> {
let sub2 = client.subscribe(vec![Filter::new().kinds(PROP_KINDS)], None).await;
info!("Subscribed to updates with {:?}", sub2);
if args.peek().is_some_and(|arg| arg == "--watch-events") {
loop {
match notifications.recv().await {
Ok(notification) => {
if let RelayPoolNotification::Event { event, .. } = notification {
println!("At {} found {} kind {} content \"{}\"", event.created_at, event.id, event.kind, event.content);
}
}
Err(e) => {
println!("Aborting due to {:?}", e);
return Ok(());
}
}
}
}
let metadata = var("USER").ok().map(
|user| Metadata::new().name(user));
let moved_metadata = metadata.clone();
@ -679,6 +697,7 @@ async fn main() -> Result<()> {
info!("Moving up {} tasks", dots - 1)
}
} else {
// TODO regex match
let mut transform: Box<dyn Fn(&str) -> String> = Box::new(|s: &str| s.to_string());
if !remaining.chars().any(|c| c.is_ascii_uppercase()) {
// Smart-case - case-sensitive if any uppercase char is entered

View File

@ -15,6 +15,7 @@ use itertools::{Either, Itertools};
use log::{debug, error, info, trace, warn};
use nostr_sdk::prelude::Marker;
use nostr_sdk::{Event, EventBuilder, EventId, JsonUtil, Keys, Kind, Metadata, PublicKey, Tag, TagStandard, Timestamp, UncheckedUrl, Url};
use regex::bytes::Regex;
use tokio::sync::mpsc::Sender;
use TagStandard::Hashtag;
@ -715,7 +716,8 @@ impl TasksRelay {
return vec![id];
}
let lowercase_arg = arg.to_ascii_lowercase();
let has_space = lowercase_arg.split_ascii_whitespace().count() > 1;
// TODO apply regex to all matching
let regex = Regex::new(&format!(r"\b{}", lowercase_arg)).unwrap();
let mut filtered: Vec<EventId> = Vec::with_capacity(32);
let mut filtered_fuzzy: Vec<EventId> = Vec::with_capacity(32);
@ -726,7 +728,7 @@ impl TasksRelay {
return vec![task.event.id];
} else if content.starts_with(arg) {
filtered.push(task.event.id)
} else if if has_space { lowercase.starts_with(&lowercase_arg) } else { lowercase.split_ascii_whitespace().any(|word| word.trim_start_matches('#').starts_with(&lowercase_arg)) } {
} else if regex.is_match(lowercase.as_bytes()) {
filtered_fuzzy.push(task.event.id)
}
}
@ -1547,17 +1549,25 @@ mod tasks_test {
assert_eq!(tasks.visible_tasks().len(), 2);
assert_eq!(tasks.get_by_id(&sub).unwrap().parent_id(), zero);
let id2 = tasks.filter_or_create(None, "new");
// Do not substring match invisible subtask
let id2 = tasks.filter_or_create(None, "#new-is gold wrapped").unwrap();
assert_eq!(tasks.len(), 3);
assert_eq!(tasks.visible_tasks().len(), 2);
let new2 = tasks.get_by_id(&id2.unwrap()).unwrap();
let new2 = tasks.get_by_id(&id2).unwrap();
assert_eq!(new2.props, Default::default());
assert_eq!(tasks.get_own_events_history().count(), 1);
tasks.move_up();
assert_eq!(tasks.get_matching(tasks.get_position_ref(), "wrapped").len(), 1);
assert_eq!(tasks.get_matching(tasks.get_position_ref(), "new-i").len(), 1);
tasks.filter_or_create(None, "is gold");
assert_position!(tasks, id2);
assert_eq!(tasks.get_own_events_history().count(), 3);
// Global match
let idagain = tasks.filter_or_create(None, "newer");
assert_eq!(idagain, None);
assert_position!(tasks, id1.unwrap());
assert_eq!(tasks.get_own_events_history().count(), 2);
assert_eq!(tasks.get_own_events_history().count(), 4);
assert_eq!(tasks.len(), 3);
}