From 1251f547894ede5b635844595cf02f1dfa567ac0 Mon Sep 17 00:00:00 2001
From: xeruf <27jf@pm.me>
Date: Mon, 29 Jul 2024 14:13:32 +0300
Subject: [PATCH] fix(task): omit tags referencing events in property getter
---
src/task.rs | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/task.rs b/src/task.rs
index ae62379..7209590 100644
--- a/src/task.rs
+++ b/src/task.rs
@@ -2,7 +2,7 @@ use std::collections::{BTreeSet, HashSet};
use std::fmt;
use std::ops::Div;
-use nostr_sdk::{Event, EventBuilder, EventId, Kind, Tag, Timestamp};
+use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, Kind, Tag, Timestamp};
use crate::EventSender;
@@ -127,6 +127,17 @@ impl Task {
}
total
}
+
+ fn filter_tags
(&self, predicate: P) -> Option
+ where P: FnMut(&&Tag) -> bool{
+ self.tags.as_ref().map(|tags| {
+ tags.into_iter()
+ .filter(predicate)
+ .map(|t| format!("{}", t.content().unwrap()))
+ .collect::>()
+ .join(" ")
+ })
+ }
pub(crate) fn get(&self, property: &str) -> Option {
match property {
@@ -135,12 +146,8 @@ impl Task {
"state" => self.state().map(|s| s.to_string()),
"name" => Some(self.event.content.clone()),
"time" => Some(format!("{}m", self.time_tracked().div(60))),
- "tags" => self.tags.as_ref().map(|tags| {
- tags.iter()
- .map(|t| format!("{}", t.content().unwrap()))
- .collect::>()
- .join(" ")
- }),
+ "hashtags" => self.filter_tags(|tag| tag.single_letter_tag().is_some_and(|sltag| sltag.character == Alphabet::T)),
+ "tags" => self.filter_tags(|tag| !tag.single_letter_tag().is_some_and(|sltag| sltag.character == Alphabet::E)),
"props" => Some(format!(
"{:?}",
self.props
@@ -148,14 +155,10 @@ impl Task {
.map(|e| format!("{} kind {} '{}'", e.created_at, e.kind, e.content))
.collect::>()
)),
- "desc" | "description" => self.descriptions().fold(None, |total, s| {
- Some(match total {
- None => s.clone(),
- Some(i) => i + " " + s,
- })
- }),
+ "descriptions" => Some(format!("{:?}", self.descriptions().collect::>())),
+ "desc" | "description" => self.descriptions().last().cloned(),
_ => {
- eprintln!("Unknown column {}", property);
+ eprintln!("Unknown task property {}", property);
None
}
}