diff --git a/src/helpers.rs b/src/helpers.rs index 6e5b997..394f9e2 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -5,6 +5,8 @@ use chrono::LocalResult::Single; use log::{debug, error, info, trace, warn}; use nostr_sdk::Timestamp; +pub const CHARACTER_THRESHOLD: usize = 3; + pub fn some_non_empty(str: &str) -> Option { if str.is_empty() { None } else { Some(str.to_string()) } } @@ -33,7 +35,7 @@ pub fn parse_date(str: &str) -> Option> { match parse_datetime::parse_datetime_at_date(Local::now(), str) { Ok(date) => Some(date.to_utc()), Err(_) => { - warn!("Could not parse date from {str}: {e}"); + warn!("Could not parse date from \"{str}\": {e}"); None } } diff --git a/src/main.rs b/src/main.rs index 282de66..bbf720d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -415,7 +415,13 @@ async fn main() -> Result<()> { ); continue; } - Some(arg) => tasks.make_note(arg), + Some(arg) => { + if arg.len() < CHARACTER_THRESHOLD { + warn!("Note needs at least {CHARACTER_THRESHOLD} characters!"); + continue + } + tasks.make_note(arg) + }, } Some('>') => { diff --git a/src/tasks.rs b/src/tasks.rs index 05e9b51..9583c14 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -14,7 +14,7 @@ use nostr_sdk::prelude::Marker; use TagStandard::Hashtag; use crate::{EventSender, MostrMessage}; -use crate::helpers::{format_timestamp_local, format_timestamp_relative, format_timestamp_relative_to, parse_tracking_stamp, some_non_empty}; +use crate::helpers::{CHARACTER_THRESHOLD, format_timestamp_local, format_timestamp_relative, format_timestamp_relative_to, parse_tracking_stamp, some_non_empty}; use crate::kinds::*; use crate::task::{MARKER_DEPENDS, MARKER_PARENT, State, Task, TaskState}; @@ -594,12 +594,11 @@ impl Tasks { 0 => { // No match, new task self.view.clear(); - if arg.len() > 2 { - Some(self.make_task_with(arg, self.position_tags_for(position), true)) - } else { - warn!("Name of a task needs to have at least 3 characters"); - None + if arg.len() < CHARACTER_THRESHOLD { + warn!("New task name needs at least {CHARACTER_THRESHOLD} characters"); + return None } + Some(self.make_task_with(arg, self.position_tags_for(position), true)) } 1 => { // One match, activate