forked from janek/mostr
fix(tasks): do not show bookmarks on childrenless tasks
This commit is contained in:
parent
945e29b5ed
commit
3942105764
25
src/tasks.rs
25
src/tasks.rs
|
@ -379,10 +379,15 @@ impl Tasks {
|
|||
|
||||
pub(crate) fn filtered_tasks<'a>(&'a self, position: Option<&'a EventId>) -> impl Iterator<Item=&Task> + 'a {
|
||||
let current: HashMap<&EventId, &Task> = self.resolve_tasks(self.children_of(position)).map(|t| (t.get_id(), t)).collect();
|
||||
let bookmarks = self.bookmarks.iter()
|
||||
.filter(|id| !position.is_some_and(|p| &p == id) && !current.contains_key(id))
|
||||
.filter_map(|id| self.get_by_id(id))
|
||||
.collect_vec();
|
||||
let bookmarks =
|
||||
if current.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
self.bookmarks.iter()
|
||||
.filter(|id| !position.is_some_and(|p| &p == id) && !current.contains_key(id))
|
||||
.filter_map(|id| self.get_by_id(id))
|
||||
.collect_vec()
|
||||
};
|
||||
// TODO use ChildIterator
|
||||
current.into_values().chain(
|
||||
bookmarks
|
||||
|
@ -528,7 +533,7 @@ impl Tasks {
|
|||
pub(crate) fn toggle_bookmark(&mut self, id: EventId) -> nostr_sdk::Result<Event> {
|
||||
match self.bookmarks.iter().position(|b| b == &id) {
|
||||
None => self.bookmarks.push(id),
|
||||
Some(pos) => { self.bookmarks.remove(pos); },
|
||||
Some(pos) => { self.bookmarks.remove(pos); }
|
||||
}
|
||||
self.sender.submit(
|
||||
EventBuilder::new(Kind::Bookmarks, "mostr pins",
|
||||
|
@ -1253,10 +1258,14 @@ mod tasks_test {
|
|||
|
||||
assert_eq!(tasks.filtered_tasks(None).count(), 2);
|
||||
assert_eq!(tasks.filtered_tasks(Some(&zero)).count(), 0);
|
||||
assert_eq!(tasks.visible_tasks().len(), 1);
|
||||
assert_eq!(tasks.filtered_tasks(Some(&pin)).count(), 0);
|
||||
assert_eq!(tasks.filtered_tasks(Some(&zero)).count(), 0);
|
||||
|
||||
tasks.submit(EventBuilder::new(Kind::Bookmarks, "", [Tag::event(pin), Tag::event(zero)]));
|
||||
assert_eq!(tasks.filtered_tasks(Some(&zero)).collect_vec(), vec![tasks.get_by_id(&pin).unwrap()]);
|
||||
tasks.move_to(Some(pin));
|
||||
assert!(tasks.visible_tasks().is_empty());
|
||||
assert_eq!(tasks.visible_tasks().len(), 1);
|
||||
assert_eq!(tasks.filtered_tasks(Some(&pin)).count(), 0);
|
||||
assert_eq!(tasks.filtered_tasks(Some(&zero)).count(), 0);
|
||||
|
||||
tasks.move_to(None);
|
||||
assert_eq!(tasks.visible_tasks().len(), 3);
|
||||
|
|
Loading…
Reference in New Issue