From 44feea98943c85de3d3f6015f64919f0ad9c1171 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 12 Nov 2024 20:33:23 +0100 Subject: [PATCH] enhance(kinds): improve tag formatting --- src/kinds.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/kinds.rs b/src/kinds.rs index 48d2dce..8804980 100644 --- a/src/kinds.rs +++ b/src/kinds.rs @@ -1,8 +1,6 @@ use crate::task::MARKER_PARENT; use crate::tasks::HIGH_PRIO; use itertools::Itertools; -use log::info; -use nostr_sdk::TagStandard::Hashtag; use nostr_sdk::{Alphabet, EventBuilder, EventId, Kind, Tag, TagKind, TagStandard}; use std::borrow::Cow; @@ -106,14 +104,17 @@ pub(crate) fn extract_tags(input: &str) -> (String, Vec) { }).collect_vec(); let mut split = result.split(|e| { e == &"#" }); let main = split.next().unwrap().join(" "); - let tags = extract_hashtags(&main) + let mut tags = extract_hashtags(&main) .chain(split.flatten().map(|s| to_hashtag(&s))) - .chain(prio.map(|p| to_prio_tag(p))).collect(); + .chain(prio.map(|p| to_prio_tag(p))) + .collect_vec(); + tags.sort(); + tags.dedup(); (main, tags) } fn to_hashtag(tag: &str) -> Tag { - Hashtag(tag.to_string()).into() + TagStandard::Hashtag(tag.to_string()).into() } fn format_tag(tag: &Tag) -> String { @@ -130,10 +131,7 @@ fn format_tag(tag: &Tag) -> String { }) => format!("Key{}: {:.8}", public_key, alias.as_ref().map(|s| format!(" {s}")).unwrap_or_default()), Some(TagStandard::Hashtag(content)) => format!("#{content}"), - _ => tag.content().map_or_else( - || format!("Kind {}", tag.kind()), - |content| content.to_string(), - ) + _ => tag.as_vec().join(" ") } }