diff --git a/src/main.rs b/src/main.rs index 14a54f5..1fc218c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -463,14 +463,13 @@ async fn main() -> Result<()> { } Some(arg) => { if arg == "@" { - info!("Showing everybody's tasks"); - tasks.set_filter_author(None) + tasks.reset_key_filter() } else if let Ok(key) = PublicKey::from_str(arg) { info!("Showing {}'s tasks", tasks.get_username(&key)); - tasks.set_filter_author(Some(key)) + tasks.set_key_filter(key) } else if let Some((key, meta)) = tasks.find_user(arg) { info!("Showing {}'s tasks", meta.display_name.as_ref().unwrap_or(meta.name.as_ref().unwrap_or(&key.to_string()))); - tasks.set_filter_author(Some(key.clone())) + tasks.set_key_filter(key.clone()) } else { if parse_hour(arg, 1) .or_else(|| parse_date(arg).map(|utc| utc.with_timezone(&Local))) diff --git a/src/tasks.rs b/src/tasks.rs index 272226b..a59334e 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -658,8 +658,19 @@ impl TasksRelay { Ok(added) } - pub(crate) fn set_filter_author(&mut self, key: Option) { - self.pubkey = key + pub(crate) fn reset_key_filter(&mut self) { + let own = self.sender.pubkey(); + if self.pubkey.is_some_and(|k| k == own) { + info!("Showing everybody's tasks"); + self.pubkey = None + } else { + info!("Showing own tasks"); + self.pubkey = Some(own) + } + } + + pub(crate) fn set_key_filter(&mut self, key: PublicKey) { + self.pubkey = Some(key) } pub(crate) fn set_filter_from(&mut self, time: Timestamp) -> bool { @@ -703,10 +714,11 @@ impl TasksRelay { pub(crate) fn clear_filters(&mut self) { self.state = StateFilter::Default; + self.pubkey = Some(self.sender.pubkey()); self.view.clear(); self.tags.clear(); self.tags_excluded.clear(); - info!("Removed all filters"); + info!("Reset all filters"); } pub(crate) fn has_tag_filter(&self) -> bool {