feat: implement more explicit assignee logic

This commit is contained in:
xeruf 2025-01-29 22:58:18 +01:00
parent fe6ac592be
commit fd7819e979
3 changed files with 28 additions and 3 deletions

View file

@ -87,13 +87,17 @@ impl Task {
pub(crate) fn get_participants(&self) -> impl Iterator<Item=PublicKey> + '_ {
self.tags()
.filter(|t| t.kind() == TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::P)))
.filter(|t| t.kind() == TagKind::p())
.filter_map(|t| t.content()
.and_then(|c| PublicKey::from_str(c).inspect_err(|e| warn!("Unparseable pubkey in {:?}", t)).ok()))
}
pub(crate) fn get_owner(&self) -> PublicKey {
pub(crate) fn get_assignee(&self) -> Option<PublicKey> {
self.get_participants().next()
}
pub(crate) fn get_owner(&self) -> PublicKey {
self.get_assignee()
.unwrap_or_else(|| self.event.pubkey)
}

View file

@ -700,6 +700,7 @@ impl TasksRelay {
"progress" => prog_string.clone(),
"owner" => format!("{:.6}", self.users.get_username(&task.get_owner())),
"assignee" => format!("{:.6}", task.get_assignee().map(|u| self.users.get_username(&u)).unwrap_or_default()),
"author" | "creator" => format!("{:.6}", self.users.get_username(&task.event.pubkey)), // FIXME temporary until proper column alignment
"prio" => self
.traverse_up_from(Some(task.get_id()))

View file

@ -149,16 +149,36 @@ fn test_context() {
// s2-4 are newest while s2,s3,hp are highest prio
assert_tasks_visible!(tasks, [s4, s2, s3, anid, id_hp]);
//let keys = Keys::generate();
//let builder = EventBuilder::new(Kind::from(1234), "test").tags([Tag::public_key(k//eys.public_key)]);
//println!("{:?}", builder);
//println!("{:?}", builder.sign_with_keys(&keys));
//env_logger::init();
// ASSIGNEE
assert_eq!(tasks.pubkey, Some(tasks.sender.pubkey()));
let hoi = tasks.make_task("hoi").unwrap();
assert_eq!(tasks.get_by_id(&hoi).unwrap().get_owner(), tasks.sender.pubkey());
let hoi = tasks.get_by_id(&hoi).unwrap();
assert_eq!(hoi.get_owner(), tasks.sender.pubkey());
// https://github.com/rust-nostr/nostr/issues/736
//assert_eq!(hoi.get_participants().collect_vec(), vec![tasks.sender.pubkey()]);
//assert_eq!(hoi.get_assignee(), Some(tasks.sender.pubkey()));
let pubkey = Keys::generate().public_key;
let test1id = tasks.make_task(&("test1 @".to_string() + &pubkey.to_string())).unwrap();
let test1 = tasks.get_by_id(&test1id).unwrap();
assert_eq!(test1.get_owner(), pubkey);
tasks.pubkey = Some(pubkey);
let test2id = tasks.make_task("test2").unwrap();
let test2 = tasks.get_by_id(&test2id).unwrap();
assert_eq!(test2.get_owner(), pubkey);
tasks.pubkey = None;
let all = tasks.make_task("all").unwrap();
let all = tasks.get_by_id(&all).unwrap();
assert_eq!(all.get_assignee(), None);
assert_eq!(all.get_owner(), tasks.sender.pubkey());
}
#[test]