feat: display task owner

This commit is contained in:
xeruf 2024-11-25 02:29:23 +01:00
parent 6ef5c47e98
commit 3a4588b45d
2 changed files with 20 additions and 8 deletions

View File

@ -4,13 +4,14 @@ use std::collections::BTreeSet;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::iter::once;
use std::str::FromStr;
use std::string::ToString;
use colored::{ColoredString, Colorize};
use itertools::Either::{Left, Right};
use itertools::Itertools;
use log::{debug, error, info, trace, warn};
use nostr_sdk::{Alphabet, Event, EventId, Kind, Tag, Timestamp};
use nostr_sdk::{Alphabet, Event, EventId, Kind, PublicKey, SingleLetterTag, Tag, TagKind, Timestamp};
use crate::hashtag::{is_hashtag, Hashtag};
use crate::helpers::{format_timestamp_local, some_non_empty};
use crate::kinds::{match_event_tag, Prio, PRIO, PROCEDURE_KIND, PROCEDURE_KIND_ID, TASK_KIND};
@ -70,6 +71,15 @@ impl Task {
&self.event.id
}
pub(crate) fn get_owner(&self) -> PublicKey {
self.tags()
.find(|t| t.kind() == TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::P)))
.and_then(|t| t.content()
.and_then(|c| PublicKey::from_str(c).inspect_err(|e| warn!("Unparseable pubkey in {:?}", t)).ok()))
.unwrap_or_else(|| self.event.pubkey)
}
pub(crate) fn find_refs<'a>(&'a self, marker: &'a str) -> impl Iterator<Item=&'a EventId> {
self.refs.iter().filter_map(move |(str, id)| Some(id).filter(|_| str == marker))
}
@ -184,11 +194,12 @@ impl Task {
self.tags().filter_map(|t| Hashtag::try_from(t).ok())
}
/// Tags of this task that are not event references, newest to oldest
fn tags(&self) -> impl Iterator<Item=&Tag> {
self.tags.iter().flatten().chain(
self.props.iter().flat_map(|e| e.tags.iter()
self.props.iter()
.flat_map(|e| e.tags.iter()
.filter(|t| t.single_letter_tag().is_none_or(|s| s.character != Alphabet::E)))
)
.chain(self.tags.iter().flatten())
}
fn join_tags<P>(&self, predicate: P) -> String

View File

@ -159,7 +159,7 @@ impl TasksRelay {
bookmarks: Default::default(),
properties: [
"author",
"owner",
"prio",
"state",
"rtime",
@ -170,7 +170,7 @@ impl TasksRelay {
sorting: [
"priority",
"status",
"author",
"owner",
"hashtags",
"rtime",
"name",
@ -661,6 +661,7 @@ impl TasksRelay {
}
"progress" => prog_string.clone(),
"owner" => format!("{:.6}", self.users.get_username(&task.get_owner())),
"author" | "creator" => format!("{:.6}", self.users.get_username(&task.event.pubkey)), // FIXME temporary until proper column alignment
"prio" => self
.traverse_up_from(Some(task.event.id))
@ -1823,7 +1824,7 @@ mod tasks_test {
tasks.custom_time = Some(Timestamp::now());
tasks.update_state("Finished #YeaH # oi", State::Done);
assert_eq!(tasks.get_by_id(&parent).unwrap().list_hashtags().collect_vec(), ["tag1", "YeaH", "oi", "tag3", "yeah"].map(Hashtag::from));
assert_eq!(tasks.get_by_id(&parent).unwrap().list_hashtags().collect_vec(), ["YeaH", "oi", "tag3", "yeah", "tag1"].map(Hashtag::from));
assert_eq!(tasks.all_hashtags(), all_tags);
tasks.custom_time = Some(now());