style: clean up code formatting and add notes

This commit is contained in:
xeruf 2024-11-22 11:22:28 +01:00
parent 29476e60ad
commit 58117b901a
4 changed files with 16 additions and 16 deletions

View File

@ -36,6 +36,7 @@ impl<T: TimeZone> ToTimestamp for DateTime<T> {
/// Parses the hour from a plain number in the String, /// Parses the hour from a plain number in the String,
/// with max of max_future hours into the future. /// with max of max_future hours into the future.
/// TODO parse HHMM as well
pub fn parse_hour(str: &str, max_future: i64) -> Option<DateTime<Local>> { pub fn parse_hour(str: &str, max_future: i64) -> Option<DateTime<Local>> {
str.parse::<u32>().ok().and_then(|hour| { str.parse::<u32>().ok().and_then(|hour| {
let now = Local::now(); let now = Local::now();

View File

@ -1,7 +1,7 @@
use crate::task::MARKER_PARENT; use crate::task::MARKER_PARENT;
use crate::tasks::HIGH_PRIO; use crate::tasks::HIGH_PRIO;
use itertools::Itertools; use itertools::Itertools;
use nostr_sdk::{Alphabet, EventBuilder, EventId, Kind, Tag, TagKind, TagStandard}; use nostr_sdk::{EventBuilder, EventId, Kind, Tag, TagKind, TagStandard};
use std::borrow::Cow; use std::borrow::Cow;
pub const TASK_KIND: Kind = Kind::GitIssue; pub const TASK_KIND: Kind = Kind::GitIssue;

View File

@ -175,7 +175,7 @@ impl Task {
} }
} }
pub(crate) fn list_hashtags(&self) -> impl Iterator<Item=Hashtag> + use<'_> { pub(crate) fn list_hashtags(&self) -> impl Iterator<Item=Hashtag> + '_ {
self.tags().filter_map(|t| Hashtag::try_from(t).ok()) self.tags().filter_map(|t| Hashtag::try_from(t).ok())
} }
@ -362,13 +362,13 @@ mod tasks_test {
assert_eq!(task.pure_state(), State::Done); assert_eq!(task.pure_state(), State::Done);
task.props.insert( task.props.insert(
EventBuilder::new(State::Open.into(), "").tags([Tag::hashtag("tag2")]) EventBuilder::new(State::Open.into(), "").tags([Tag::hashtag("tag2")])
.custom_created_at(Timestamp::from(Timestamp::now() - 2)) .custom_created_at(Timestamp::now() - 2)
.sign_with_keys(&keys).unwrap()); .sign_with_keys(&keys).unwrap());
assert_eq!(task.pure_state(), State::Done); assert_eq!(task.pure_state(), State::Done);
assert_eq!(task.list_hashtags().count(), 2); assert_eq!(task.list_hashtags().count(), 2);
task.props.insert( task.props.insert(
EventBuilder::new(State::Closed.into(), "") EventBuilder::new(State::Closed.into(), "")
.custom_created_at(Timestamp::from(Timestamp::now() + 1)) .custom_created_at(Timestamp::now() + 1)
.sign_with_keys(&keys).unwrap()); .sign_with_keys(&keys).unwrap());
assert_eq!(task.pure_state(), State::Closed); assert_eq!(task.pure_state(), State::Closed);
} }

View File

@ -13,7 +13,7 @@ use crate::task::{State, Task, TaskState, MARKER_DEPENDS, MARKER_PARENT, MARKER_
use colored::Colorize; use colored::Colorize;
use itertools::Itertools; use itertools::Itertools;
use log::{debug, error, info, trace, warn}; use log::{debug, error, info, trace, warn};
use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, JsonUtil, Keys, Kind, Metadata, PublicKey, SingleLetterTag, Tag, TagKind, TagStandard, Timestamp, Url}; use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, JsonUtil, Keys, Kind, Metadata, PublicKey, SingleLetterTag, Tag, TagKind, Timestamp, Url};
use regex::bytes::Regex; use regex::bytes::Regex;
use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::Sender;
@ -403,7 +403,7 @@ impl TasksRelay {
prompt.push_str(&format!(" -#{}", tag)); prompt.push_str(&format!(" -#{}", tag));
} }
prompt.push_str(&self.state.indicator()); prompt.push_str(&self.state.indicator());
self.priority.map(|p| self.priority.map(|p|
prompt.push_str(&format!(" *{:02}", p))); prompt.push_str(&format!(" *{:02}", p)));
prompt prompt
} }
@ -505,7 +505,7 @@ impl TasksRelay {
}) })
} }
// TODO sparse is deprecated // TODO sparse is deprecated and only left for tests
pub(crate) fn filtered_tasks( pub(crate) fn filtered_tasks(
&self, &self,
position: Option<EventId>, position: Option<EventId>,
@ -977,7 +977,7 @@ impl TasksRelay {
} }
self.submit( self.submit(
build_tracking(target) build_tracking(target)
.custom_created_at(Timestamp::from(now.as_u64() + offset)), .custom_created_at(now + offset),
); );
} }
@ -1025,7 +1025,7 @@ impl TasksRelay {
}) })
} }
fn context_hashtags(&self) -> impl Iterator<Item=Tag> + use<'_> { fn context_hashtags(&self) -> impl Iterator<Item=Tag> + '_ {
self.tags.iter().map(Tag::from) self.tags.iter().map(Tag::from)
} }
@ -1431,8 +1431,7 @@ impl Display for TasksRelay {
for task in visible { for task in visible {
writeln!( writeln!(
lock, lock,
"{}", "{}", self.properties.iter()
self.properties.iter()
.map(|p| self.get_property(task, p.as_str())) .map(|p| self.get_property(task, p.as_str()))
.join(" \t") .join(" \t")
)?; )?;
@ -1523,9 +1522,8 @@ pub(crate) fn join_tasks<'a>(
}) })
} }
fn referenced_events(event: &Event) -> impl Iterator<Item=EventId> + use < '_ > { fn referenced_events(event: &Event) -> impl Iterator<Item=EventId> + '_ {
event.tags.iter() event.tags.iter().filter_map(|tag| match_event_tag(tag).map(|t| t.id))
.filter_map(| tag | match_event_tag(tag).map(| t | t.id))
} }
fn referenced_event(event: &Event) -> Option<EventId> { fn referenced_event(event: &Event) -> Option<EventId> {
@ -1907,9 +1905,10 @@ mod tasks_test {
EventBuilder::new(TASK_KIND, "sub") EventBuilder::new(TASK_KIND, "sub")
.tags([tasks.make_event_tag_from_id(parent, MARKER_PARENT)]) .tags([tasks.make_event_tag_from_id(parent, MARKER_PARENT)])
); );
assert_eq!(tasks.viewed_tasks().len(), 1); assert_tasks_view!(tasks, [parent]);
tasks.track_at(Timestamp::now(), Some(sub)); tasks.track_at(Timestamp::now(), Some(sub));
assert_eq!(tasks.get_own_events_history().count(), 1); assert_eq!(tasks.get_own_events_history().count(), 1);
assert_tasks_view!(tasks, []);
tasks.make_dependent_sibling("sibling"); tasks.make_dependent_sibling("sibling");
assert_eq!(tasks.len(), 3); assert_eq!(tasks.len(), 3);
@ -2065,7 +2064,7 @@ mod tasks_test {
let mut tasks = stub_tasks(); let mut tasks = stub_tasks();
let zero = EventId::all_zeros(); let zero = EventId::all_zeros();
tasks.track_at(Timestamp::from(Timestamp::now().as_u64() + 100), Some(zero)); tasks.track_at(Timestamp::now() + 100, Some(zero));
assert_eq!( assert_eq!(
timestamps(tasks.get_own_events_history(), &[zero]) timestamps(tasks.get_own_events_history(), &[zero])
.collect_vec() .collect_vec()