feat(tasks): set new task owner from context

This commit is contained in:
xeruf 2025-01-25 07:50:48 +01:00
parent cbeba49bb3
commit fe6ac592be
2 changed files with 20 additions and 2 deletions

View file

@ -1119,11 +1119,19 @@ impl TasksRelay {
Some(id)
}
/// Create the task only incorporating context
fn make_task_unchecked(
&mut self,
input: &str,
tags: Vec<Tag>,
) -> EventId {
let assignee =
if tags.iter().any(|t| t.kind() == TagKind::p()) {
None
} else {
self.pubkey
.map(|p| Tag::public_key(p))
};
let prio =
if tags.iter().any(|t| t.kind().to_string() == PRIO) {
None
@ -1134,7 +1142,8 @@ impl TasksRelay {
EventBuilder::new(TASK_KIND, input)
.tags(self.context_hashtags())
.tags(tags)
.tags(prio),
.tags(prio)
.tags(assignee),
)
}

View file

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