feat: implement more explicit assignee logic

This commit is contained in:
xeruf 2025-01-25 08:04:27 +01:00
parent fe6ac592be
commit bd15a90182
5 changed files with 26 additions and 9 deletions

2
Cargo.lock generated
View file

@ -1561,7 +1561,7 @@ dependencies = [
[[package]] [[package]]
name = "mostr" name = "mostr"
version = "0.9.1" version = "0.9.2"
dependencies = [ dependencies = [
"chrono", "chrono",
"colog", "colog",

View file

@ -5,7 +5,7 @@ repository = "https://forge.ftt.gmbh/janek/mostr"
readme = "README.md" readme = "README.md"
license = "GPL 3.0" license = "GPL 3.0"
authors = ["melonion"] authors = ["melonion"]
version = "0.9.1" version = "0.9.2"
rust-version = "1.82" rust-version = "1.82"
edition = "2021" edition = "2021"
default-run = "mostr" default-run = "mostr"
@ -13,7 +13,7 @@ default-run = "mostr"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
nostr-sdk = { version = "0.38", features = ["ndb", "nip49"] } nostr-sdk = { version = "0.38", features = ["nip49"] }
# Basics # Basics
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
regex = "1.11" regex = "1.11"

View file

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

View file

@ -700,6 +700,7 @@ impl TasksRelay {
"progress" => prog_string.clone(), "progress" => prog_string.clone(),
"owner" => format!("{:.6}", self.users.get_username(&task.get_owner())), "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 "author" | "creator" => format!("{:.6}", self.users.get_username(&task.event.pubkey)), // FIXME temporary until proper column alignment
"prio" => self "prio" => self
.traverse_up_from(Some(task.get_id())) .traverse_up_from(Some(task.get_id()))
@ -1119,7 +1120,7 @@ impl TasksRelay {
Some(id) Some(id)
} }
/// Create the task only incorporating context /// Create the task, only adding context tags
fn make_task_unchecked( fn make_task_unchecked(
&mut self, &mut self,
input: &str, input: &str,
@ -1129,8 +1130,7 @@ impl TasksRelay {
if tags.iter().any(|t| t.kind() == TagKind::p()) { if tags.iter().any(|t| t.kind() == TagKind::p()) {
None None
} else { } else {
self.pubkey self.pubkey.map(|p| Tag::public_key(p))
.map(|p| Tag::public_key(p))
}; };
let prio = let prio =
if tags.iter().any(|t| t.kind().to_string() == PRIO) { if tags.iter().any(|t| t.kind().to_string() == PRIO) {

View file

@ -149,16 +149,29 @@ fn test_context() {
// s2-4 are newest while s2,s3,hp are highest prio // s2-4 are newest while s2,s3,hp are highest prio
assert_tasks_visible!(tasks, [s4, s2, s3, anid, id_hp]); 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(); 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 pubkey = Keys::generate().public_key;
let test1id = tasks.make_task(&("test1 @".to_string() + &pubkey.to_string())).unwrap(); let test1id = tasks.make_task(&("test1 @".to_string() + &pubkey.to_string())).unwrap();
let test1 = tasks.get_by_id(&test1id).unwrap(); let test1 = tasks.get_by_id(&test1id).unwrap();
assert_eq!(test1.get_owner(), pubkey); assert_eq!(test1.get_owner(), pubkey);
tasks.pubkey = Some(pubkey); tasks.pubkey = Some(pubkey);
let test2id = tasks.make_task("test2").unwrap(); let test2id = tasks.make_task("test2").unwrap();
let test2 = tasks.get_by_id(&test2id).unwrap(); let test2 = tasks.get_by_id(&test2id).unwrap();
assert_eq!(test2.get_owner(), pubkey); 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] #[test]