feat(tasks): set new task owner from context
This commit is contained in:
parent
cbeba49bb3
commit
fe6ac592be
2 changed files with 20 additions and 2 deletions
11
src/tasks.rs
11
src/tasks.rs
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue