forked from janek/mostr
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 log::{debug, error, info, trace, warn};
|
||||||
use nostr_sdk::Timestamp;
|
use nostr_sdk::Timestamp;
|
||||||
|
|
||||||
|
pub const CHARACTER_THRESHOLD: usize = 3;
|
||||||
|
|
||||||
pub fn some_non_empty(str: &str) -> Option<String> {
|
pub fn some_non_empty(str: &str) -> Option<String> {
|
||||||
if str.is_empty() { None } else { Some(str.to_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) {
|
match parse_datetime::parse_datetime_at_date(Local::now(), str) {
|
||||||
Ok(date) => Some(date.to_utc()),
|
Ok(date) => Some(date.to_utc()),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
warn!("Could not parse date from {str}: {e}");
|
warn!("Could not parse date from \"{str}\": {e}");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,7 +415,13 @@ async fn main() -> Result<()> {
|
||||||
);
|
);
|
||||||
continue;
|
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('>') => {
|
Some('>') => {
|
||||||
|
|
11
src/tasks.rs
11
src/tasks.rs
|
@ -14,7 +14,7 @@ use nostr_sdk::prelude::Marker;
|
||||||
use TagStandard::Hashtag;
|
use TagStandard::Hashtag;
|
||||||
|
|
||||||
use crate::{EventSender, MostrMessage};
|
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::kinds::*;
|
||||||
use crate::task::{MARKER_DEPENDS, MARKER_PARENT, State, Task, TaskState};
|
use crate::task::{MARKER_DEPENDS, MARKER_PARENT, State, Task, TaskState};
|
||||||
|
|
||||||
|
@ -594,12 +594,11 @@ impl Tasks {
|
||||||
0 => {
|
0 => {
|
||||||
// No match, new task
|
// No match, new task
|
||||||
self.view.clear();
|
self.view.clear();
|
||||||
if arg.len() > 2 {
|
if arg.len() < CHARACTER_THRESHOLD {
|
||||||
Some(self.make_task_with(arg, self.position_tags_for(position), true))
|
warn!("New task name needs at least {CHARACTER_THRESHOLD} characters");
|
||||||
} else {
|
return None
|
||||||
warn!("Name of a task needs to have at least 3 characters");
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
Some(self.make_task_with(arg, self.position_tags_for(position), true))
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
// One match, activate
|
// One match, activate
|
||||||
|
|
Loading…
Reference in New Issue