From 8f9a0d2fa923f4d02e0ffb30b6fa958193ddbf51 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sat, 25 Jan 2025 08:04:27 +0100 Subject: [PATCH] feat: implement more explicit assignee logic --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/task.rs | 8 ++++++-- src/tasks.rs | 6 +++--- src/tasks/tests.rs | 15 ++++++++++++++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c6bfa2..76bd554 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1561,7 +1561,7 @@ dependencies = [ [[package]] name = "mostr" -version = "0.9.1" +version = "0.9.2" dependencies = [ "chrono", "colog", diff --git a/Cargo.toml b/Cargo.toml index 84f70c9..203ba87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ repository = "https://forge.ftt.gmbh/janek/mostr" readme = "README.md" license = "GPL 3.0" authors = ["melonion"] -version = "0.9.1" +version = "0.9.2" rust-version = "1.82" edition = "2021" default-run = "mostr" diff --git a/src/task.rs b/src/task.rs index a751ba4..2ae706f 100644 --- a/src/task.rs +++ b/src/task.rs @@ -87,13 +87,17 @@ impl Task { pub(crate) fn get_participants(&self) -> impl Iterator + '_ { 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 { self.get_participants().next() + } + + pub(crate) fn get_owner(&self) -> PublicKey { + self.get_assignee() .unwrap_or_else(|| self.event.pubkey) } diff --git a/src/tasks.rs b/src/tasks.rs index 79df7de..d6e5494 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -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())) @@ -1119,7 +1120,7 @@ impl TasksRelay { Some(id) } - /// Create the task only incorporating context + /// Create the task, only adding context tags fn make_task_unchecked( &mut self, input: &str, @@ -1129,8 +1130,7 @@ impl TasksRelay { if tags.iter().any(|t| t.kind() == TagKind::p()) { None } else { - self.pubkey - .map(|p| Tag::public_key(p)) + self.pubkey.map(|p| Tag::public_key(p)) }; let prio = if tags.iter().any(|t| t.kind().to_string() == PRIO) { diff --git a/src/tasks/tests.rs b/src/tasks/tests.rs index cf60989..dea7688 100644 --- a/src/tasks/tests.rs +++ b/src/tasks/tests.rs @@ -149,16 +149,29 @@ fn test_context() { // s2-4 are newest while s2,s3,hp are highest prio assert_tasks_visible!(tasks, [s4, s2, s3, anid, id_hp]); + // 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()); + 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]