feat: character threshold for creating notes
This commit is contained in:
parent
c3d18e4494
commit
3c93e0aae7
|
@ -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<String> {
|
||||
if str.is_empty() { None } else { Some(str.to_string()) }
|
||||
}
|
||||
|
@ -33,7 +35,7 @@ pub fn parse_date(str: &str) -> Option<DateTime<Utc>> {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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('>') => {
|
||||
|
|
11
src/tasks.rs
11
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
|
||||
|
|
Loading…
Reference in New Issue